Chapter 17 Save and Load Machine Learning Models Flashcards
1
Q
HOW TO SAVE A MODEL AFTER FITTING, USING PICKLE(CODE+ RELEVANT LIBRARY IMPORT)? P110
A
from pickle import dump from pickle import load model.fit(X_train, Y_train) # save the model to disk filename = 'finalized_model.sav' dump(model, open(filename, 'wb')) # load the model from disk loaded_model = load(open(filename, 'rb')) result = loaded_model.score(X_test, Y_test)
2
Q
HOW TO SAVE A MODEL AFTER FITTING USING JOBLIB(CODE+ RELEVANT LIBRARY IMPORT)? P110
A
from sklearn.externals.joblib import dump from sklearn.externals.joblib import load #save the model to disk filename = 'finalized_model.sav' dump(model, filename) # load the model from disk loaded_model = load(filename) result = loaded_model.score(X_test, Y_test)