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