{"id":13710485,"url":"https://github.com/dmitryikh/leaves","last_synced_at":"2025-05-06T19:31:08.542Z","repository":{"id":44339303,"uuid":"148888029","full_name":"dmitryikh/leaves","owner":"dmitryikh","description":"pure Go implementation of prediction part for GBRT (Gradient Boosting Regression Trees) models from popular frameworks","archived":false,"fork":false,"pushed_at":"2024-07-03T17:46:42.000Z","size":1280,"stargazers_count":432,"open_issues_count":34,"forks_count":72,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-11-13T20:40:48.807Z","etag":null,"topics":["boosting","decision-trees","go","golang","lightgbm","machine-learning","xgboost"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmitryikh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-15T09:26:59.000Z","updated_at":"2024-11-08T06:46:06.000Z","dependencies_parsed_at":"2022-08-12T11:02:39.805Z","dependency_job_id":"5f5f7c63-d1fd-4d47-b142-04ddb30eb40b","html_url":"https://github.com/dmitryikh/leaves","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitryikh%2Fleaves","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitryikh%2Fleaves/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitryikh%2Fleaves/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitryikh%2Fleaves/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmitryikh","download_url":"https://codeload.github.com/dmitryikh/leaves/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252753268,"owners_count":21798940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boosting","decision-trees","go","golang","lightgbm","machine-learning","xgboost"],"created_at":"2024-08-02T23:00:57.171Z","updated_at":"2025-05-06T19:31:03.528Z","avatar_url":"https://github.com/dmitryikh.png","language":"Go","readme":"# leaves\n\n[![version](https://img.shields.io/badge/version-0.8.0-yellow.svg)](https://semver.org)\n[![Build Status](https://travis-ci.org/dmitryikh/leaves.svg?branch=master)](https://travis-ci.org/dmitryikh/leaves)\n[![GoDoc](https://godoc.org/github.com/dmitryikh/leaves?status.png)](https://godoc.org/github.com/dmitryikh/leaves)\n[![Coverage Status](https://coveralls.io/repos/github/dmitryikh/leaves/badge.svg?branch=master)](https://coveralls.io/github/dmitryikh/leaves?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dmitryikh/leaves)](https://goreportcard.com/report/github.com/dmitryikh/leaves)\n\n![Logo](logo.png)\n\n## Introduction\n\n_leaves_ is a library implementing prediction code for GBRT (Gradient Boosting Regression Trees) models in **pure Go**. The goal of the project - make it possible to use models from popular GBRT frameworks in Go programs without C API bindings.\n\n**NOTE**: Before `1.0.0` release the API is a subject to change.\n\n## Features\n  * General Features:\n    * support parallel predictions for batches\n    * support sigmoid, softmax transformation functions\n    * support getting leaf indices of decision trees\n  * Support LightGBM ([repo](https://github.com/Microsoft/LightGBM)) models:\n    * read models from `text` format and from `JSON` format\n    * support `gbdt`, `rf` (random forest) and `dart` models\n    * support multiclass predictions\n    * addition optimizations for categorical features (for example, _one hot_ decision rule)\n    * addition optimizations exploiting only prediction usage\n  * Support XGBoost ([repo](https://github.com/dmlc/xgboost)) models:\n    * read models from binary format\n    * support `gbtree`, `gblinear`, `dart` models\n    * support multiclass predictions\n    * support missing values (`nan`)\n  * Support scikit-learn ([repo](https://github.com/scikit-learn/scikit-learn)) tree models (experimental support):\n    * read models from pickle format (protocol `0`)\n    * support `sklearn.ensemble.GradientBoostingClassifier`\n\n\n## Usage examples\n\nIn order to start, go get this repository:\n\n```sh\ngo get github.com/dmitryikh/leaves\n```\n\nMinimal example:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/dmitryikh/leaves\"\n)\n\nfunc main() {\n\t// 1. Read model\n\tuseTransformation := true\n\tmodel, err := leaves.LGEnsembleFromFile(\"lightgbm_model.txt\", useTransformation)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// 2. Do predictions!\n\tfvals := []float64{1.0, 2.0, 3.0}\n\tp := model.PredictSingle(fvals, 0)\n\tfmt.Printf(\"Prediction for %v: %f\\n\", fvals, p)\n}\n```\n\nIn order to use XGBoost model, just change `leaves.LGEnsembleFromFile`, to `leaves.XGEnsembleFromFile`.\n\n## Documentation\n\nDocumentation is hosted on godoc ([link](https://godoc.org/github.com/dmitryikh/leaves)). Documentation contains complex usage examples and full API reference. Some additional information about usage examples can be found in [leaves_test.go](leaves_test.go).\n\n## Compatibility\n\nMost _leaves_ features are tested to be compatible with old and coming versions of GBRT libraries. In [compatibility.md](compatibility.md) one can found detailed report about _leaves_ correctness against different versions of external GBRT libraries.\n\nSome additional information on new features and backward compatibility can be found in [NOTES.md](NOTES.md).\n\n## Benchmark\n\nBelow are comparisons of prediction speed on batches (~1000 objects in 1 API\ncall). Hardware: MacBook Pro (15-inch, 2017), 2,9 GHz Intel Core i7, 16 ГБ\n2133 MHz LPDDR3. C API implementations were called from python bindings. But\nlarge batch size should neglect overhead of python bindings. _leaves_\nbenchmarks were run by means of golang test framework: `go test -bench`. See\n[benchmark](benchmark) for mode details on measurments. See\n[testdata/README.md](testdata/README.md) for data preparation pipelines.\n\nSingle thread:\n\n| Test Case | Features | Trees | Batch size |  C API  | _leaves_ |\n|-----------|----------|-------|------------|---------|----------|\n| LightGBM [MS LTR](https://github.com/Microsoft/LightGBM/blob/master/docs/Experiments.rst#comparison-experiment) | 137 |500 | 1000 | 49ms | 51ms |\n| LightGBM [Higgs](https://github.com/Microsoft/LightGBM/blob/master/docs/Experiments.rst#comparison-experiment) | 28 | 500 | 1000 | 50ms | 50ms |\n| LightGBM KDD Cup 99* | 41 | 1200 | 1000 | 70ms | 85ms |\n| XGBoost Higgs | 28 | 500 | 1000 | 44ms | 50ms |\n\n4 threads:\n\n| Test Case | Features | Trees | Batch size |  C API  | _leaves_ |\n|-----------|----------|-------|------------|---------|----------|\n| LightGBM [MS LTR](https://github.com/Microsoft/LightGBM/blob/master/docs/Experiments.rst#comparison-experiment) | 137 |500 | 1000 | 14ms | 14ms |\n| LightGBM [Higgs](https://github.com/Microsoft/LightGBM/blob/master/docs/Experiments.rst#comparison-experiment) | 28 | 500 | 1000 | 14ms | 14ms |\n| LightGBM KDD Cup 99* | 41 | 1200 | 1000 | 19ms | 24ms |\n| XGBoost Higgs | 28 | 500 | 1000 | ? | 14ms |\n\n(?) - currenly I'm unable to utilize multithreading form XGBoost predictions by means of python bindings\n\n(*) - KDD Cup 99 problem involves continuous and categorical features simultaneously\n\n## Limitations\n\n  * LightGBM models:\n    * limited support of transformation functions (support only sigmoid, softmax)\n  * XGBoost models:\n    * limited support of transformation functions (support only sigmoid, softmax)\n    * could be slight divergence between C API predictions vs. _leaves_ because of floating point convertions and comparisons tolerances\n  * scikit-learn tree models:\n    * no support transformations functions. Output scores is _raw scores_ (as from `GradientBoostingClassifier.decision_function`)\n    * only pickle protocol `0` is supported\n    * could be slight divergence between sklearn predictions vs. _leaves_ because of floating point convertions and comparisons tolerances\n\n## Contacts\n\nIn case if you are interested in the project or if you have questions, please contact with me by\nemail: khdmitryi ```at``` gmail.com\n","funding_links":[],"categories":["Machine Learning Framework","Go"],"sub_categories":["General Purpose Framework","Tools","[Tools](#tools-1)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitryikh%2Fleaves","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmitryikh%2Fleaves","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitryikh%2Fleaves/lists"}