LIBFFM - field-aware factorization machines - for Ruby
Add this line to your application’s Gemfile:
gem "libffm"
Prep your data in LIBFFM format
0 0:0:1 1:1:1
1 0:2:1 1:3:1
Create a model
model = Libffm::Model.new
model.fit("train.txt")
Make predictions
model.predict("test.txt")
Save the model to a file
model.save_model("model.bin")
Load the model from a file
model.load_model("model.bin")
Pass a validation set
model.fit("train.txt", eval_set: "validation.txt")
Pass parameters - default values below
Libffm::Model.new(
eta: 0.2, # learning rate
lambda: 0.00002, # regularization parameter
nr_iters: 15, # number of iterations
k: 4, # number of latent factors
normalization: true, # use instance-wise normalization
auto_stop: false # stop at the iteration that achieves the best validation loss
)
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:
git clone --recursive https://github.com/ankane/libffm-ruby.git
cd libffm-ruby
bundle install
bundle exec rake compile
bundle exec rake test