Skip to content

jeethu/gbm2py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbm2py logo

gbm2py

Turn any gradient boosted tree ensemble into pure Python (and Swift) code.

Supported Backends

Backend Supported Models
scikit-learn HistGradientBoostingRegressor, HistGradientBoostingClassifier
XGBoost XGBRegressor, XGBClassifier, Booster
LightGBM LGBMRegressor, LGBMClassifier, Booster
CatBoost CatBoostRegressor, CatBoostClassifier, CatBoost
WarpGBM WarpGBM

Output languages: Python, Swift

Quick Start — Python API

from export_gbm import export_model

export_model(model, "my_model.py")

Quick Start — CLI

python export_gbm.py --model model.pkl --output model.py

Key flags:

  • --language — Export language (python or swift, default: python)
  • --model-name — Exported class/type name (defaults to output filename stem)
  • --force — Overwrite output file if it already exists

Supported Input Formats

  • joblib (.joblib)
  • pickle (.pkl)
  • XGBoost native (.json, .ubj)
  • LightGBM native (.txt)
  • CatBoost native (.cbm)
  • Numerai-style cloudpickle (auto-unwraps predict functions)

Numerai

gbm2py is especially useful for anyone using Numerai's model upload feature. gbm2py can also directly load Numerai-style cloudpickle files (which wrap a predict function) and auto-extract the embedded model.

WarpGBM needs a CUDA capable GPU for training and inference. Using gbm2py you can export WarpGBM models and use them in any environment, even Numerai's model upload docker environment.

For reference, the Numerai example model with 2000 estimators turns into a 12MB Python file. But then again, if you're using pickle for serialization, file sizes are the least of your problems. :)

How It Works

Train a gradient boosted tree model with your favorite library, then point gbm2py at the saved model file. gbm2py walks the tree structure and serializes every split into a self-contained source file with zero dependencies.

Running Tests

python tests/test_export_histgbm.py
python tests/test_export_xgboost.py
python tests/test_export_lightgbm.py
python tests/test_export_catboost.py
python tests/test_export_warpgbm.py
python tests/test_export_numerai_pickle.py

License

This project is licensed under the Apache License 2.0.

About

Turn any GBM into pure Python (and Swift) code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages