from sklearn import svm
from sklearn import datasets
X,y = datasets.load_iris(return_X_y=True)
clf = svm.SVC().fit(X, y)
import pickle
s = pickle.dumps(clf)
clf2 = pickle.loads(s)
clf2.predict(X[0:1])
y[0]
0
dump
& load
methods.from joblib import dump,load
dump(clf, 'filename.joblib')
['filename.joblib']
clf = load('filename.joblib')
Pickle (and joblib by extension) have maintainability & security issues. Never unpickle untrusted data.
To rebuild a model with future versions of scikit-learn, save the following objects along with the pickled model: