2018-12-02 (SVM classification)

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]...)

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. 标题 markdown 内置了六种标题,如果有一段文字需要被设置为标题,只需要用#来开头一个行即可。如,想创...
    wwwwwwking阅读 255评论 0 1
  • 坦白说,这期2阶班是教得比较辛苦的一个班,除了原有1阶升上来的孩子,又插班加入两个新同学。他们很活跃,英语...
    TinaLiu丹阅读 329评论 0 0
  • 在这个充满未知的世界里,渺小的我们只能随命运奔流。风带着这颗十七岁却一事无成的少年的心,飘向远方。 他...
    象无阅读 521评论 0 0

友情链接更多精彩内容