支持向量机
一、算法原理
二、scikit-learn SVM
from sklearn.svm import LinearSVC
svm_clf = LinearSVC(C=1)
svm_clf.fit(X, y)
三、鸢尾花示例
import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
# 导入数据集
from sklearn.datasets import fetch_openml
iris = fetch_openml(name='iris')
# 切分数据集
X = iris['data'][:, 2:]
y = (iris['target'] == 'Iris-versicolor').astype(np.float64)
svm_clf = Pipeline([
('scalar', StandardScaler()),
('liner_svm', LinearSVC(C=1))
])
# 训练模型
svm_clf.fit(X, y)
# 预测
svm_clf.predict([[5.5, 1.7]])