/libffm-ruby

Field-aware factorization machines for Ruby

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

LIBFFM Ruby

LIBFFM - field-aware factorization machines - for Ruby

Build Status

Installation

Add this line to your application’s Gemfile:

gem "libffm"

Getting Started

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")

Parameters

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
)

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

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