The preservation and recovery of machine learning-training model (Sklearn)

Source: Internet
Author: User
Tags svm in python

When doing model training, especially for cross validation on a training set, you typically want to save the model and then put it on a separate test set, which describes the save and reuse of the training model in Python.

Scikit-learn already has the model to persist the operation, the import joblib can

From sklearn.externals import 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 ")

The model can be saved locally by the Joblib dump, and the CLF is a trained classifier model to be recalled from the local

>>> CLF = joblib.load ("TRAIN_MODEL.M")

Load the saved model through the Joblib load method.

And then you can test it on the test set.

Clf.predit (test_x) #此处test_X为特征集

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.