python SVM 使用实例

import numpy as np
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
y = np.array([1, 1, 2, 2])
from sklearn.svm import SVC
clf = SVC(gamma='auto')
clf.fit(X, y)
print(clf.predict([[-0.8, -1]]))

X = np.stack([-np.ones([100]),np.ones([100]),np.ones([100])*2,np.ones([100])*3])
y = np.array([1, 2, 3, 4])
from sklearn.svm import SVC
clf = SVC(gamma='auto')
clf.fit(X, y)
print(clf.predict([np.ones([100])*1.1,-np.ones([100])*1.1]))

print结果

[1]
[2 1]

你可能感兴趣的:(Python,机器学习)