Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Staged Prediction

All fit NGBoost objects support staged prediction.

For instance, to get the predictions on the first 5 examples after fitting 415 base learners, use:

array([1, 1, 0, 1, 0])
{'p0': array([0.00201258, 0.00201258, 0.52907719, 0.08351746, 0.97426859]), 'p1': array([0.99785485, 0.99785485, 0.46686649, 0.91584223, 0.02395252]), 'p2': array([0.00013257, 0.00013257, 0.00405632, 0.00064031, 0.00177889])}

This is useful in conjunction with tracking errors on a validation set, which you can do by passing the X_val and Y_val arguments and then inspecting the .best_val_loss_itr instance attribute.

[iter 0] loss=5.7429 val_loss=5.8408 scale=1.0000 norm=64.6711
[iter 100] loss=5.3637 val_loss=5.6704 scale=2.0000 norm=85.8650
[iter 200] loss=5.0970 val_loss=5.8551 scale=1.0000 norm=33.6059
[iter 300] loss=4.9509 val_loss=6.2818 scale=1.0000 norm=30.4502
[iter 400] loss=4.8622 val_loss=6.7078 scale=1.0000 norm=28.7510
100

Early Stopping

NGBoost also has early stopping. If an integer early_stopping_rounds and a validation set (X_val,Y_val) are passed to fit(), the algorithm will stop running after the validation loss has increased for early_stopping_rounds of consecutive iterations.

[iter 0] loss=5.7429 val_loss=5.8408 scale=1.0000 norm=64.6711
== Early stopping achieved.
== Best iteration / VAL91 (val_loss=5.6711)

Validation set sample weights can be passed using the val_sample_weight argument to fit.

Using sklearn Model Selection

sklearn methods are compatible with NGBoost.

{'Base': DecisionTreeRegressor(criterion='friedman_mse', max_depth=2), 'minibatch_frac': 0.5}