Code Monkey home page Code Monkey logo

xgboost-1's Introduction

XGBoost

XGBoost - high performance gradient boosting - for Ruby

Build Status Build status

Installation

Add this line to your application’s Gemfile:

gem 'xgb'

On Mac, also install OpenMP:

brew install libomp

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 = XGBoost::DMatrix.new(x, label: y)
booster = XGBoost.train(params, dtrain)

Predict

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

Save the model to a file

booster.save_model("my.model")

Load the model from a file

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

Get the importance of features

booster.score

Early stopping

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

CV

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

Set metadata about a model

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

Scikit-Learn API

Prep your data

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

Train a model

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

For classification, use XGBoost::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 Numo array

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

Or a Rover data frame

Rover.read_csv("houses.csv")

Or a Daru data frame

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

Helpful Resources

Related Projects

  • 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:

git clone https://github.com/ankane/xgboost.git
cd xgboost
bundle install
bundle exec rake vendor:all
bundle exec rake test

xgboost-1's People

Contributors

ankane avatar owst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.