基于sklearn的SVM模型保存与调用
(1)保存模型
from sklearn.externals import joblib
from sklearn import svm
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = svm.SVC()
clf.fit(X, y)
joblib.dump(clf, "my_model.m")
(2)调用模型预测
from sklearn.externals import joblib
clf = joblib.load("my_model.m")
test_X = [[0.5, 0.5], [1.5, 1.5]]
print(clf.predict(test_X))
(3)对于训练模型精度查看,以及支持向量查看
print(clf.score(X,y))
print(clf.support_vectors_)