项目作者: ankane

项目描述 :
High performance gradient boosting for Ruby
高级语言: Ruby
项目地址: git://github.com/ankane/xgboost-ruby.git
创建时间: 2019-08-15T10:56:06Z
项目社区:https://github.com/ankane/xgboost-ruby

开源协议:Apache License 2.0

下载


XGBoost Ruby

XGBoost - high performance gradient boosting - for Ruby

Build Status

Installation

Add this line to your application’s Gemfile:

  1. gem "xgb"

On Mac, also install OpenMP:

  1. brew install libomp

Learning API

Prep your data

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

Train a model

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

Predict

  1. dtest = XGBoost::DMatrix.new(x)
  2. booster.predict(dtest)

Save the model to a file

  1. booster.save_model("my.model")

Load the model from a file

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

Get the importance of features

  1. booster.score

Early stopping

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

CV

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

Set metadata about a model

  1. booster["key"] = "value"
  2. booster.attributes

Scikit-Learn API

Prep your data

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

Train a model

  1. model = XGBoost::Regressor.new
  2. model.fit(x, y)

For classification, use XGBoost::Classifier

Predict

  1. model.predict(x)

For classification, use predict_proba for probabilities

Save the model to a file

  1. model.save_model("my.model")

Load the model from a file

  1. model.load_model("my.model")

Get the importance of features

  1. model.feature_importances

Early stopping

  1. model = XGBoost::Regressor.new(early_stopping_rounds: 5)
  2. model.fit(x, y, eval_set: [[x_test, y_test]])

Data

Data can be an array of arrays

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

Or a Numo array

  1. Numo::NArray.cast([[1, 2, 3], [4, 5, 6]])

Or a Rover data frame

  1. Rover.read_csv("houses.csv")

Or a Daru data frame

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

Helpful Resources

  • LightGBM - LightGBM for Ruby
  • Eps - Machine learning for Ruby

Credits

This library follows the Python API, with the get_ and set_ prefixes removed from methods to make it more Ruby-like.

Thanks to the xgboost gem for showing how to use FFI.

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:

  1. git clone https://github.com/ankane/xgboost-ruby.git
  2. cd xgboost-ruby
  3. bundle install
  4. bundle exec rake vendor:all
  5. bundle exec rake test