Vowpal Wabbit - fast online machine learning - for Ruby
🔥 Uses the C API for blazing performance
First, install the Vowpal Wabbit C++ library. For Homebrew, use:
brew install vowpal-wabbit
Add this line to your application’s Gemfile:
gem 'vowpalwabbit'
Prep your data
x = [[1, 2], [3, 4], [5, 6], [7, 8]]
y = [1, 2, 3, 4]
Train a model
model = VowpalWabbit::Regressor.new(learning_rate: 100)
model.fit(x, y)
Use VowpalWabbit::Classifier
for classification and VowpalWabbit::Model
for other models
Make predictions
model.predict(x)
Save the model to a file
model.save_model("model.bin")
Load the model from a file
model.load_model("model.bin")
Export the model to string
require 'base64'
binary_string = model.export_model_to_binary_string
safe_encoded_string = Base64.encode64(binary_string) #BETTER, BUT OPTIONAL
Import the model from string
require 'base64'
binary_string = Base64.decode64(safe_encoded_string) #BETTER, BUT OPTIONAL
model = model.import_model_from_binary_string(binary_string)
Train online
model.partial_fit(x, y)
Get the intercept and coefficients
model.intercept
model.coefs
Score - R-squared for regression and accuracy for classification
model.score(x, y)
Specify parameters
model = VowpalWabbit::Model.new(cb: 4)
Supports the same parameters as the CLI
Data can be an array of arrays
[[1, 2, 3], [4, 5, 6]]
Or a Numo NArray
Numo::DFloat.new(3, 2).seq
Or an array of strings
[
"0 | price:.23 sqft:.25 age:.05 2006",
"1 2 'second_house | price:.18 sqft:.15 age:.35 1976",
"0 1 0.5 'third_house | price:.53 sqft:.32 age:.87 1924"
]
Or a path to a file
model.fit("train.txt")
model.partial_fit("train.txt")
model.predict("train.txt")
model.score("train.txt")
Files can be compressed
model.fit("train.txt.gz")
Read more about the input format
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development and testing:
git clone https://github.com/ankane/vowpalwabbit.git
cd vowpalwabbit
bundle install
bundle exec rake test