# NGBoost: Natural Gradient Boosting for Probabilistic Prediction
<h4 align="center">

[](https://github.com/stanfordmlgroup/ngboost/graphs/contributors)
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/psf/black)
[](https://pypi.org/project/ngboost)
[](https://pypistats.org/packages/ngboost)
</h4>
ngboost is a Python library that implements Natural Gradient Boosting, as described in ["NGBoost: Natural Gradient Boosting for Probabilistic Prediction"](https://stanfordmlgroup.github.io/projects/ngboost/). It is built on top of [Scikit-Learn](https://scikit-learn.org/stable/), and is designed to be scalable and modular with respect to choice of proper scoring rule, distribution, and base learner. A didactic introduction to the methodology underlying NGBoost is available in this [slide deck](https://docs.google.com/presentation/d/1Tn23Su0ygR6z11jy3xVNiLGv0ggiUQue/edit?usp=share_link&ouid=102290675300480810195&rtpof=true&sd=true).
## Installation
```sh
via pip
pip install --upgrade ngboost
via conda-forge
conda install -c conda-forge ngboost
```
## Usage
Probabilistic regression example on the Boston housing dataset:
```python
from ngboost import NGBRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
#Load Boston housing dataset
data_url = "http://lib.stat.cmu.edu/datasets/boston"
raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
Y = raw_df.values[1::2, 2]
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)
ngb = NGBRegressor().fit(X_train, Y_train)
Y_preds = ngb.predict(X_test)
Y_dists = ngb.pred_dist(X_test)
# test Mean Squared Error
test_MSE = mean_squared_error(Y_preds, Y_test)
print('Test MSE', test_MSE)
# test Negative Log Likelihood
test_NLL = -Y_dists.logpdf(Y_test).mean()
print('Test NLL', test_NLL)
```
Details on available distributions, scoring rules, learners, tuning, and model interpretation are available in our [user guide](https://stanfordmlgroup.github.io/ngboost/intro.html), which also includes numerous usage examples and information on how to add new distributions or scores to NGBoost.
## License
[Apache License 2.0](https://github.com/stanfordmlgroup/ngboost/blob/master/LICENSE).
## Reference
Tony Duan, Anand Avati, Daisy Yi Ding, Khanh K. Thai, Sanjay Basu, Andrew Y. Ng, Alejandro Schuler. 2019.
NGBoost: Natural Gradient Boosting for Probabilistic Prediction.
[arXiv](https://arxiv.org/abs/1910.03225)
Raw data
{
"_id": null,
"home_page": "https://github.com/stanfordmlgroup/ngboost",
"name": "ngboost",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Stanford ML Group",
"author_email": "avati@cs.stanford.edu",
"download_url": "https://files.pythonhosted.org/packages/96/f5/f49f39823c1563dbe99c79aefe1a9724f46f2fc4de708a65f97fa5080ea2/ngboost-0.5.3.tar.gz",
"platform": null,
"description": "# NGBoost: Natural Gradient Boosting for Probabilistic Prediction\n\n<h4 align=\"center\">\n\n\n[](https://github.com/stanfordmlgroup/ngboost/graphs/contributors)\n[](https://opensource.org/licenses/Apache-2.0)\n[](https://github.com/psf/black)\n[](https://pypi.org/project/ngboost)\n[](https://pypistats.org/packages/ngboost)\n\n</h4>\n\nngboost is a Python library that implements Natural Gradient Boosting, as described in [\"NGBoost: Natural Gradient Boosting for Probabilistic Prediction\"](https://stanfordmlgroup.github.io/projects/ngboost/). It is built on top of [Scikit-Learn](https://scikit-learn.org/stable/), and is designed to be scalable and modular with respect to choice of proper scoring rule, distribution, and base learner. A didactic introduction to the methodology underlying NGBoost is available in this [slide deck](https://docs.google.com/presentation/d/1Tn23Su0ygR6z11jy3xVNiLGv0ggiUQue/edit?usp=share_link&ouid=102290675300480810195&rtpof=true&sd=true).\n\n## Installation\n\n```sh\nvia pip\n\npip install --upgrade ngboost\n\nvia conda-forge\n\nconda install -c conda-forge ngboost\n```\n\n## Usage\n\nProbabilistic regression example on the Boston housing dataset:\n\n```python\nfrom ngboost import NGBRegressor\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\n\n#Load Boston housing dataset\ndata_url = \"http://lib.stat.cmu.edu/datasets/boston\"\nraw_df = pd.read_csv(data_url, sep=\"\\s+\", skiprows=22, header=None)\nX = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\nY = raw_df.values[1::2, 2]\n\nX_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)\n\nngb = NGBRegressor().fit(X_train, Y_train)\nY_preds = ngb.predict(X_test)\nY_dists = ngb.pred_dist(X_test)\n\n# test Mean Squared Error\ntest_MSE = mean_squared_error(Y_preds, Y_test)\nprint('Test MSE', test_MSE)\n\n# test Negative Log Likelihood\ntest_NLL = -Y_dists.logpdf(Y_test).mean()\nprint('Test NLL', test_NLL)\n```\n\nDetails on available distributions, scoring rules, learners, tuning, and model interpretation are available in our [user guide](https://stanfordmlgroup.github.io/ngboost/intro.html), which also includes numerous usage examples and information on how to add new distributions or scores to NGBoost.\n\n## License\n\n[Apache License 2.0](https://github.com/stanfordmlgroup/ngboost/blob/master/LICENSE).\n\n## Reference\n\nTony Duan, Anand Avati, Daisy Yi Ding, Khanh K. Thai, Sanjay Basu, Andrew Y. Ng, Alejandro Schuler. 2019.\nNGBoost: Natural Gradient Boosting for Probabilistic Prediction.\n[arXiv](https://arxiv.org/abs/1910.03225)\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Library for probabilistic predictions via gradient boosting.",
"version": "0.5.3",
"project_urls": {
"Documentation": "https://stanfordmlgroup.github.io/ngboost/intro",
"Homepage": "https://github.com/stanfordmlgroup/ngboost",
"Repository": "https://github.com/stanfordmlgroup/ngboost"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e5cc0eec41ebd72d73dd10268427e7ac66c99b2337ca376c8b8c33bbf688a066",
"md5": "7a5fd1fa57620aa45b9b88b358ff0476",
"sha256": "4e6072747471cd6e841855e12290e658b7701b97280003ef8420043693332113"
},
"downloads": -1,
"filename": "ngboost-0.5.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7a5fd1fa57620aa45b9b88b358ff0476",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.9",
"size": 33631,
"upload_time": "2025-02-01T04:38:01",
"upload_time_iso_8601": "2025-02-01T04:38:01.709214Z",
"url": "https://files.pythonhosted.org/packages/e5/cc/0eec41ebd72d73dd10268427e7ac66c99b2337ca376c8b8c33bbf688a066/ngboost-0.5.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "96f5f49f39823c1563dbe99c79aefe1a9724f46f2fc4de708a65f97fa5080ea2",
"md5": "600421ca12dede46dd41490613c11ac9",
"sha256": "99156a38d595b82ad75d91b070c417657c35626e0f94fd959bfd25a7c1674d47"
},
"downloads": -1,
"filename": "ngboost-0.5.3.tar.gz",
"has_sig": false,
"md5_digest": "600421ca12dede46dd41490613c11ac9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.9",
"size": 27589,
"upload_time": "2025-02-01T04:38:05",
"upload_time_iso_8601": "2025-02-01T04:38:05.217086Z",
"url": "https://files.pythonhosted.org/packages/96/f5/f49f39823c1563dbe99c79aefe1a9724f46f2fc4de708a65f97fa5080ea2/ngboost-0.5.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-01 04:38:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stanfordmlgroup",
"github_project": "ngboost",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "ngboost"
}