SelfExplainML / PiML-Toolbox

PiML (Python Interpretable Machine Learning) toolbox for model development & diagnostics
https://selfexplainml.github.io/PiML-Toolbox
Apache License 2.0
931 stars 111 forks source link

Registered model #11

Closed Aleconsi closed 1 year ago

Aleconsi commented 2 years ago

Hey guys, once the model are trained how can i save them to test on other dataset? I see that the model are registered in the experiment object but then i cannot retrieve them back. Thanks in advance

ZebinYang commented 2 years ago

Hi @Aleconsi, I think I have already replied your email.

In case anyone may also have the same question, I list the solution below:

import dill

clf = exp.get_model("GLM").estimator.__model__ # for GLM
clf = exp.get_model("EBM").estimator # for all the rest models.

# uncomment the line below in case you get an error related to __sklearn_is_fitted__.
# del clf.__sklearn_is_fitted__ 

with open('name_model.pkl', 'wb') as file:
    dill.dump(clf, file)

with open('name_model.pkl', 'rb') as file:
    clf_load = dill.load(file)

clf_load.predict(train_x)