In the model training, especially in the training set to do cross-validation, usually want to save the model, and then put on a separate test set test, the following is the Python training model to save and reuse.
Scikit-learn already has the model persisted operation, the import joblib can
fromimport joblib
Model Save
>>> Os.chdir ( "Workspace/model_save" ) >>> from sklearn import SVM >>> X = [[0 , 0 ], [1 , 1 ]]>>> y = [ 0 , 1 ]>>> CLF = SVM. SVC () >>> clf.fit (X, y) >>> Clf.fit (train_x,train_y) >>> joblib.dump (CLF, "TRAIN_MODEL.M" )
By Joblib dump you can save the model locally, CLF is a trained classifier
Model Recall from local
>>> clf = joblib.load("train_model.m")
The saved model is loaded by the Joblib load method.
Then you can test it on the test set.
clf.predit(test_X,test_y)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The saving and re-use of training model in machine learning-python