<commit_before><a href="https://codeclimate.com/github/asafschers/scoruby"><img src="https://codeclimate.com/github/asafschers/scoruby/badges/gpa.svg" /></a>
[![Coverage Status](https://coveralls.io/repos/github/asafschers/scoruby/badge.svg?branch=master)](https://coveralls.io/github/asafschers/scoruby?branch=master)
[![Gem Version](https://badge.fury.io/rb/scoruby.svg)](https://badge.fury.io/rb/scoruby)
[![Build Status](https://travis-ci.org/asafschers/scoruby.svg?branch=master)](https://travis-ci.org/asafschers/scoruby)

# Scoruby

Ruby scoring API for Predictive Model Markup Language (PMML).

Currently supports Decision Tree, Random Forest Naive Bayes and Gradient Boosted Models.

Will be happy to implement new models by demand, or assist with any other issue.

Contact me here or at <EMAIL>.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'scoruby'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install scoruby

## Usage
### Random Forest

[Generate PMML - R](https://github.com/asafschers/scoruby/wiki/Random-Forest) 
#### Classify by PMML - Ruby

```ruby

random_forest = Scoruby.get_model 'titanic_rf.pmml'
features =  {
        Sex: 'male',
        Parch: 0,
        Age: 30,
        Fare: 9.6875,
        Pclass: 2,
        SibSp: 0,
        Embarked: 'Q'       
    }

random_forest.predict(features)

=> "0"

random_forest.decisions_count(features)

=> {"0"=>441, "1"=>59}

```

### Gradient Boosted model
<commit_msg>README - Random Forest usage<commit_after><a href="https://codeclimate.com/github/asafschers/scoruby"><img src="https://codeclimate.com/github/asafschers/scoruby/badges/gpa.svg" /></a>
[![Coverage Status](https://coveralls.io/repos/github/asafschers/scoruby/badge.svg?branch=master)](https://coveralls.io/github/asafschers/scoruby?branch=master)
[![Gem Version](https://badge.fury.io/rb/scoruby.svg)](https://badge.fury.io/rb/scoruby)
[![Build Status](https://travis-ci.org/asafschers/scoruby.svg?branch=master)](https://travis-ci.org/asafschers/scoruby)

# Scoruby

Ruby scoring API for Predictive Model Markup Language (PMML).

Currently supports Decision Tree, Random Forest Naive Bayes and Gradient Boosted Models.

Will be happy to implement new models by demand, or assist with any other issue.

Contact me here or at <EMAIL>.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'scoruby'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install scoruby

## Usage
### Random Forest

[Generate PMML - R](https://github.com/asafschers/scoruby/wiki/Random-Forest) 
#### Classify by PMML - Ruby

```ruby

random_forest = Scoruby.get_model 'titanic_rf.pmml'
features =  {
        Sex: 'male',
        Parch: 0,
        Age: 30,
        Fare: 9.6875,
        Pclass: 2,
        SibSp: 0,
        Embarked: 'Q'       
    }

random_forest.predict(features)

=> {:label=>"0", :score=>0.882}

random_forest.decisions_count(features)

=> {"0"=>441, "1"=>59}

```

### Gradient Boosted model

{'fraction_non_alphanumeric': 0.1505270092226614, 'fraction_numerical': 0.013175230566534914, 'mean_word_length': 3.882636655948553, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '844504', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1109, 'n_words': 230}