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 # 导入svm的svc类(支持向量分类)
clf = SVC() # 创建分类器对象
clf.fit(X, y) # 用训练数据拟合分类器模型
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
clf.predict([[-0.8, -1]]) # 用训练好的分类器去预测[-0.8, -1]数据的标签[1]
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) #数据特征
y = np.array([1, 1, 2, 2]) # 数据对应的标签
from sklearn.svm import SVC # 导入svm的svc类(支持向量分类)
clf = SVC() # 创建分类器对象
clf.fit(X, y) # 用训练数据拟合分类器模型
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
clf.predict([[-0.8, -1]]) # 用训练好的分类器去预测[-0.8, -1]数据的标签[1]
本文通过使用Python的scikit-learn库实现支持向量机(SVM)分类器,并以具体数据集为例,演示了如何训练模型及进行预测。首先定义了特征数据与标签,接着利用SVC类创建分类器并拟合数据,最后对未知数据点进行预测。
2084

被折叠的 条评论
为什么被折叠?



