Skip to content


Repository files navigation

Coverage Status Gem Version Build Status


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

Currently supports -

  • Decision Tree
  • Naive Bayes
  • Logistic Regression
  • Random Forest
  • Gradient Boosted Trees

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

Contact me here or at

Tutorial - Deploy Machine Learning Models from R Research to Ruby Production with PMML


Add this line to your application's Gemfile:

gem 'scoruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install scoruby


Naive Bayes

naive_bayes = Scoruby.load_model 'naive_bayes.pmml'
features = { f1: v1 , ... } 
naive_bayes.score(features, 'l1')

Logistic Regression

logistic_regression = Scoruby.load_model 'logistic_regression.pmml'
features = { f1: v1 , ... } 

Decision Tree

decision_tree = Scoruby.load_model 'decision_tree.pmml'
features = { f1 : v1, ... } 

=> #<Decision:0x007fc232384180 @score="0", @score_distribution={"0"=>"0.999615579933873", "1"=>"0.000384420066126561"}>

Random Forest

Generate PMML - R

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


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


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

Gradient Boosted model

Generate PMML - R

gbm = Scoruby.load_model 'gbm.pmml'

features =  {
        Sex: 'male',
        Parch: 0,
        Age: 30,
        Fare: 9.6875,
        Pclass: 2,
        SibSp: 0,
        Embarked: 'Q'       


=> 0.3652639329522468


After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.