Saving Models
from ngboost import NGBRegressor
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
X, Y = load_boston(True)
X_reg_train, X_reg_test, Y_reg_train, Y_reg_test = train_test_split(X, Y, test_size=0.2)
Saving ngboost models is easy with the pickle
package:
ngb = NGBRegressor().fit(X_reg_train, Y_reg_train)
import pickle
from pathlib import Path
file_path = Path.home()/'Desktop'/'ngbtest.p'
with file_path.open("wb") as f:
pickle.dump(ngb, f)
with file_path.open("rb") as f:
ngb_unpickled = pickle.load(f)
Y_preds = ngb_unpickled.predict(X_reg_test)
Y_dists = ngb_unpickled.pred_dist(X_reg_test)
Y_dists[0:5].params