美文网首页程序员
2018-12-02 (SVM classification)

2018-12-02 (SVM classification)

作者: 麓山侠 | 来源:发表于2018-12-31 01:27 被阅读0次

Classifier

SVC, NuSVC and LinearSVC are classes capable of performing multi-class classification on a dataset.

SVC and NuSVC are similar methods, but accept slightly different sets of parameters and have different mathematical

formulations. LinearSVC does not accept keyword kernel, as this is assumed to be linear. It also lacks some of the members ofSVC and NuSVC, like support_.

Input

Array X: an array X of size [n_samples,n_features] holding the training samples

Array y: array y of class labels (strings or integers), size [n_samples]

Example (Training)

>>> from sklearn import svm

>>> X = [[0, 0], [1, 1]]

>>> y = [0, 1]

>>> clf = svm.SVC(gamma='scale')

>>> clf.fit(X, y) 

SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False)

Example (Predicting)

>>>clf.predict([[2., 2.]])

Note

SVMs decision function depends on some subset of the training data, called the support vectors. Some properties of these support vectors can be found in members support_vectors_, support_ and n_support

>>> # get support vectors

>>> clf.support_vectors_array([[0., 0.], [1., 1.]])

>>> # get indices of support vectors

>>> clf.support_ array([0, 1]...)

>>> # get number of support vectors for each class

>>> clf.n_support_ array([1, 1]...)

相关文章

网友评论

    本文标题:2018-12-02 (SVM classification)

    本文链接:https://www.haomeiwen.com/subject/dvbdcqtx.html