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.

Saving ngboost models is easy with the pickle package:

[iter 0] loss=5.7647 val_loss=0.0000 scale=1.0000 norm=65.8357
[iter 100] loss=5.4150 val_loss=0.0000 scale=1.0000 norm=45.1825
[iter 200] loss=5.1782 val_loss=0.0000 scale=1.0000 norm=36.4965
[iter 300] loss=5.0259 val_loss=0.0000 scale=1.0000 norm=32.7998
[iter 400] loss=4.9240 val_loss=0.0000 scale=2.0000 norm=61.5887
{'loc': array([ 96.99460752, 149.95843629, 180.66874368, 84.50476373, 88.24486158]), 'scale': array([29.43302582, 36.20735616, 45.68591978, 25.37584676, 32.04836874])}

To avoid pickle, you can use skops, which does not run arbitrary code when it loads a file. Compress the file to keep it small, and check the list of types before you trust them:

['ngboost.api.NGBRegressor', 'ngboost.distns.normal.Normal', 'ngboost.scores.LogScore', 'sklearn.tree._tree.Tree']
{'loc': array([ 96.99460752, 149.95843629, 180.66874368, 84.50476373, 88.24486158]), 'scale': array([29.43302582, 36.20735616, 45.68591978, 25.37584676, 32.04836874])}