Default / 默认 · September 1, 2021

sk才是大成者,深度学习中 还能屹立不倒

Table of Content

sk才是大成者,深度学习中 还能屹立不倒

https://colab.research.google.com/drive/1_Z-tAmypFr9grcjjLpbCS4MV14J4qtwm?usp=sharing

sklearn #保存模型

What you are looking for is called Model persistence in sklearn words and it is documented in introduction and in model persistence sections.

So you have initialized your classifier and trained it for a long time with

clf = some.classifier()
clf.fit(X, y)

After this you have two options:

1) Using Pickle

import pickle
<h1>now you can save it to a file</h1>
with open('filename.pkl', 'wb') as f:
    pickle.dump(clf, f)
<h1>and later you can load it</h1>
with open('filename.pkl', 'rb') as f:
    clf = pickle.load(f)

<p><strong>2) Using Joblib</strong>
/usr/local/lib/python3.7/dist-packages/sklearn/externals/joblib/init.py:15: FutureWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+. warnings.warn(msg, category=FutureWarning)</p>
<p>还是pickle吧,那个更加通用,无恼用就可以。

from sklearn.externals import joblib</p>
<h1>now you can save it to a file</h1>
joblib.dump(clf, 'filename.pkl') 
<h1>and later you can load it</h1>
clf = joblib.load('filename.pkl')

https://stackoverflow.com/questions/10592605/save-classifier-to-disk-in-scikit-learn

scikit-learn自带的参数优化

https://scikit-learn.org/stable/modules/grid_search.html

%d bloggers like this: