README.md in xgb-0.1.0 vs README.md in xgb-0.1.1
- old
+ new
@@ -2,10 +2,12 @@
[XGBoost](https://github.com/dmlc/xgboost) - the high performance machine learning library - for Ruby
:fire: Uses the C API for blazing performance
+[![Build Status](https://travis-ci.org/ankane/xgb.svg?branch=master)](https://travis-ci.org/ankane/xgb)
+
## Installation
First, [install XGBoost](https://xgboost.readthedocs.io/en/latest/build.html). On Mac, copy `lib/libxgboost.dylib` to `/usr/local/lib`.
Add this line to your application’s Gemfile:
@@ -14,16 +16,20 @@
gem 'xgb'
```
## Getting Started
+This library follows the [Core Data Structure, Learning and Scikit-Learn APIs](https://xgboost.readthedocs.io/en/latest/python/python_api.html) of the Python library. Some methods and options are missing at the moment. PRs welcome!
+
+## Learning API
+
Train a model
```ruby
params = {objective: "reg:squarederror"}
-train_set = Xgb::DMatrix.new(x_train, label: y_train)
-booster = Xgb.train(params, train_set)
+dtrain = Xgb::DMatrix.new(x_train, label: y_train)
+booster = Xgb.train(params, dtrain)
```
Predict
```ruby
@@ -31,21 +37,99 @@
```
Save the model to a file
```ruby
-booster.save_model("model.txt")
+booster.save_model("my.model")
```
Load the model from a file
```ruby
-booster = Xgb::Booster.new(model_file: "model.txt")
+booster = Xgb::Booster.new(model_file: "my.model")
```
-## Reference
+Get the importance of features
-This library follows the [Core Data Structure and Learning APIs](https://xgboost.readthedocs.io/en/latest/python/python_api.html) for the Python library. Some methods and options are missing at the moment. PRs welcome!
+```ruby
+booster.score
+```
+
+Early stopping
+
+```ruby
+Xgb.train(params, dtrain, evals: [[dtrain, "train"], [dtest, "eval"]], early_stopping_rounds: 5)
+```
+
+CV
+
+```ruby
+Xgb.cv(params, dtrain, nfold: 3, verbose_eval: true)
+```
+
+## Scikit-Learn API
+
+Prep your data
+
+```ruby
+x = [[1, 2], [3, 4], [5, 6], [7, 8]]
+y = [1, 2, 3, 4]
+```
+
+Train a model
+
+```ruby
+model = Xgb::Regressor.new
+model.fit(x, y)
+```
+
+> For classification, use `Xgb::Classifier`
+
+Predict
+
+```ruby
+model.predict(x)
+```
+
+> For classification, use `predict_proba` for probabilities
+
+Save the model to a file
+
+```ruby
+model.save_model("my.model")
+```
+
+Load the model from a file
+
+```ruby
+model.load_model("my.model")
+```
+
+Get the importance of features
+
+```ruby
+model.feature_importances
+```
+
+## Data
+
+Data can be an array of arrays
+
+```ruby
+[[1, 2, 3], [4, 5, 6]]
+```
+
+Or a Daru data frame
+
+```ruby
+Daru::DataFrame.from_csv("houses.csv")
+```
+
+Or a Numo NArray
+
+```ruby
+Numo::DFloat.new(3, 2).seq
+```
## Helpful Resources
- [Parameters](https://xgboost.readthedocs.io/en/latest/parameter.html)
- [Parameter Tuning](https://xgboost.readthedocs.io/en/latest/tutorials/param_tuning.html)