Popularity
1.0
Growing
Activity
8.1
Declining
29
4
0

Monthly Downloads: 212
Programming language: Ruby
License: MIT License
Latest version: v0.1.3

XGBoost alternatives and similar gems

Based on the "Machine Learning" category

Do you think we are missing an alternative of XGBoost or a related project?

Add another 'Machine Learning' Gem

README

Xgb

XGBoost - the high performance machine learning library - for Ruby

:fire: Uses the C API for blazing performance

Build Status

Installation

First, install XGBoost. For Homebrew, use:

brew install xgboost

Add this line to your application’s Gemfile:

gem 'xgb'

Getting Started

This library follows the Python API, with the get_ and set_ prefixes removed from methods. Some methods and options are missing at the moment. PRs welcome!

Learning API

Prep your data

x = [[1, 2], [3, 4], [5, 6], [7, 8]]
y = [1, 2, 3, 4]

Train a model

params = {objective: "reg:squarederror"}
dtrain = Xgb::DMatrix.new(x, label: y)
booster = Xgb.train(params, dtrain)

Predict

dtest = Xgb::DMatrix.new(x)
booster.predict(dtest)

Save the model to a file

booster.save_model("my.model")

Load the model from a file

booster = Xgb::Booster.new(model_file: "my.model")

Get the importance of features

booster.score

Early stopping

Xgb.train(params, dtrain, evals: [[dtrain, "train"], [dtest, "eval"]], early_stopping_rounds: 5)

CV

Xgb.cv(params, dtrain, nfold: 3, verbose_eval: true)

Scikit-Learn API

Prep your data

x = [[1, 2], [3, 4], [5, 6], [7, 8]]
y = [1, 2, 3, 4]

Train a model

model = Xgb::Regressor.new
model.fit(x, y)

For classification, use Xgb::Classifier

Predict

model.predict(x)

For classification, use predict_proba for probabilities

Save the model to a file

model.save_model("my.model")

Load the model from a file

model.load_model("my.model")

Get the importance of features

model.feature_importances

Early stopping

model.fit(x, y, eval_set: [[x_test, y_test]], early_stopping_rounds: 5)

Data

Data can be an array of arrays

[[1, 2, 3], [4, 5, 6]]

Or a Daru data frame

Daru::DataFrame.from_csv("houses.csv")

Or a Numo NArray

Numo::DFloat.new(3, 2).seq

XGBoost Installation

There’s an experimental branch that includes XGBoost with the gem for easiest installation.

gem 'xgb', github: 'ankane/xgb', branch: 'vendor', submodules: true

Please file an issue if it doesn’t work for you.

You can also specify the path to XGBoost in an initializer:

Xgb.ffi_lib << "/path/to/xgboost/lib/libxgboost.so"

Use libxgboost.dylib for Mac and xgboost.dll for Windows

Helpful Resources

  • LightGBM - LightGBM for Ruby
  • Eps - Machine Learning for Ruby

Credits

Thanks to the xgboost gem for serving as an initial reference.

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 and testing:

git clone https://github.com/ankane/xgb.git
cd xgb
bundle install
bundle exec rake test