from sklearn import svm
from sklearn import datasets
clf = svm.SVC()
iris = datasets.load_iris()
X, y = iris.data, iris.target
clf.fit(X, y)
保存模型
import pickle
with open('../save/clf.pickle', 'wb') as f:
pickle.dump(clf, f)
调用模型
import pickle
with open('../save/clf.pickle', 'rb') as f:
clf2 = pickle.load(f)
print(clf2.predict(X[0:1]))
保存模型
import joblib
joblib.dump(clf, '../save/clf.pkl')
调用模型
clf3 = joblib.load('../save/clf.pkl')
print(clf3.predict(X[0:1]))