NGBoost
raw JSON → 0.5.10 verified Mon Apr 27 auth: no python
NGBoost is a library for probabilistic prediction via gradient boosting that estimates full probability distributions rather than point predictions. Current version is 0.5.10, supporting Python 3.9–3.14. It uses natural gradient boosting to learn parameters of a parametric distribution. Release cadence is periodic, with recent versions adding distribution support (Weibull, HalfNormal, Beta, etc.), numpy2 compatibility, and sklearn compatibility. Maintained by the Stanford ML Group.
pip install ngboost Common errors
error ImportError: cannot import name 'NGBRegressor' from 'ngboost' ↓
cause Incorrect installation or trying to import from a different environment.
fix
Run
pip install ngboost and ensure you are in the correct Python environment. Then use from ngboost import NGBRegressor. error ModuleNotFoundError: No module named 'sklearn.metrics._pairwise_distances' ↓
cause Incompatible scikit-learn version (likely <0.22) with newer ngboost.
fix
Upgrade scikit-learn:
pip install --upgrade scikit-learn error AttributeError: 'NGBRegressor' object has no attribute 'pred_dist' ↓
cause Using an older version of ngboost where the method is called `predict_dist` instead of `pred_dist`.
fix
Use
ngb.pred_dist(X) for ngboost>=0.5.0; for older versions use ngb.predict_dist(X). error ValueError: When `natural_gradient` is True, `Score` must be an instance of `LogScore` or a class that implements `natural_gradient`. ↓
cause Attempting to use natural_gradient with a custom Score that doesn't support it.
fix
Either set
natural_gradient=False or use a built-in Score like LogScore. Warnings
breaking Version 0.5.5 upgraded sklearn dependency to >1.6. If using older sklearn, upgrade or pin ngboost<0.5.5. ↓
fix Update scikit-learn to >=1.6 or use ngboost<0.5.5
breaking Version 0.5.2 added support for Numpy 2.0. Code relying on numpy<2 behavior (e.g., object dtype in arrays) may break with ngboost>=0.5.2. ↓
fix Pin numpy<2 if using older scikit-learn or custom code that is not numpy2-compatible.
deprecated The 'natural_gradient' parameter in some internal methods was deprecated in v0.5.8 and may be removed in future. ↓
fix Avoid using 'natural_gradient' parameter; default behavior is correct.
gotcha Default distribution is Normal with LogScore. If you use a different distribution, ensure the Score matches the distribution (e.g., LogScore for exponential family). Mismatch leads to silent poor performance. ↓
fix Always specify both Dist and Score parameters explicitly.
gotcha Models saved with sklearn <1.3 may not load with sklearn >=1.3 due to pickle format. ngboost>=0.5.10 includes a compatibility loader `load_ngboost_model`. ↓
fix Use `from ngboost import load_ngboost_model` and call it instead of joblib.load.
Imports
- NGBRegressor
from ngboost import NGBRegressor - NGBClassifier wrong
from ngboost.ngboost import NGBClassifiercorrectfrom ngboost import NGBClassifier - Normal wrong
from ngboost import Normalcorrectfrom ngboost.distns import Normal - LogScore wrong
from ngboost import LogScorecorrectfrom ngboost.scores import LogScore
Quickstart
import numpy as np
from ngboost import NGBRegressor
from ngboost.distns import Normal
from ngboost.scores import LogScore
# Generate sample data
np.random.seed(42)
X = np.random.randn(100, 1)
y = X[:, 0] + 0.1*np.random.randn(100)
# Train probabilistic model
ngb = NGBRegressor(Dist=Normal, Score=LogScore, n_estimators=100, learning_rate=0.01, verbose=False)
ngb.fit(X, y)
# Predict: mean and variance (or scale) of Normal distribution
y_preds = ngb.predict(X)
# Use ngb.pred_dist(X) to get distribution object