IBM::ML
A Ruby gem to invoke the IBM Machine Learning service REST API.
Currently supports:
Installation
With Gem
After installing Ruby >= 2.3:
$ gem install ibm-ml
With Bundler
Add this line to your application's Gemfile:
gem 'ibm-ml'
And then execute:
$ bundle install
Usage
Setup
require 'ibm/ml'
require 'pp'
record = {
GENDER: 'M',
AGEGROUP: '45-54',
EDUCATION: 'Doctorate',
PROFESSION: 'Executive',
INCOME: 200000,
SWITCHER: 0,
LASTPURCHASE: 3,
ANNUAL_SPEND: 1200
}
Cloud
CLOUD_USERNAME =
CLOUD_PASSWORD =
CLOUD_INSTANCE_ID =
DEPLOYMENT_ID =
ml_service = IBM::ML::Cloud.new(CLOUD_USERNAME, CLOUD_PASSWORD, CLOUD_INSTANCE_ID)
pp ml_service.fetch_token
pp ml_service.models
pp ml_service.model_by_name('ML Model')
pp ml_service.deployments
pp ml_service.deployment(DEPLOYMENT_ID)
pp ml_service.deployment_by_name('Deployed ML Model')
score = ml_service.score(DEPLOYMENT_ID, record)
score = ml_service.score_by_name('Deployed ML Model', record)
Local
LOCAL_HOST =
LOCAL_USERNAME =
LOCAL_PASSWORD =
DEPLOYMENT_ID =
ml_service = IBM::ML::Local.new(LOCAL_HOST, LOCAL_USERNAME, LOCAL_PASSWORD)
pp ml_service.fetch_token
score = ml_service.score(DEPLOYMENT_ID, record)
Print Score
pp score
prediction = ml_service.query_score(score, 'prediction')
probability = ml_service.query_score(score, 'probability')[prediction]
puts
puts "Prediction = #{prediction == 1}"
puts "Probability = #{(probability * 100).round(1)}%"
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
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 rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/IBM-DSE/ibm-ml-ruby.