The saving and re-use of training model in machine learning-python

Source: Internet
Author: User
Tags svm

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.