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.7668 val_loss=0.0000 scale=1.0000 norm=66.1233
[iter 100] loss=5.4328 val_loss=0.0000 scale=1.0000 norm=46.3134
[iter 200] loss=5.1892 val_loss=0.0000 scale=1.0000 norm=37.0310
[iter 300] loss=5.0486 val_loss=0.0000 scale=1.0000 norm=33.3591
[iter 400] loss=4.9421 val_loss=0.0000 scale=2.0000 norm=61.9588
{'loc': array([102.75600476, 86.74746331, 131.9187267 , 255.87765968, 259.75393727]), 'scale': array([30.81796348, 33.32142742, 31.33994613, 50.20769921, 33.37919638])}

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([102.75600476, 86.74746331, 131.9187267 , 255.87765968, 259.75393727]), 'scale': array([30.81796348, 33.32142742, 31.33994613, 50.20769921, 33.37919638])}