The preservation of the Python Sklearn model

Source: Internet
Author: User
Tags svm

When using Python's machine learning package Sklearn, if the training set is fixed, we often want to save the results of a trained model for the next use, which avoids the hassle of retraining the model every time it runs.

In Python, there is a joblib that can save the model and take the saved model out for different sets of tests:

1  fromSklearnImportSVM2  fromSklearn.externalsImportJoblib3 4 #Training Model5CLF = Svc = SVM. SVC (kernel='Linear')6rf=Clf.fit (Array (trainmat), Array (listclasses))7 8 # Save Model9Joblib.dump (RF,'Rf.model')Ten  One # Load Model ARf=joblib.load ('Rf.model') -  - # Applying models for forecasting theResult=rf.predict (Thsdoc)

It is important to note that after Joblib.dump () is executed here, it is possible to generate several files in Rf.model_XX.npy-named format, which is probably the binary file used to save the coefficients in the model. The number of files that are generated will also vary depending on the classifier being called and the number of iterations in the classifier, sometimes generating a few, sometimes generating hundreds of.

The preservation of the Python Sklearn model

Related Article

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.