首页 > 其他分享 >支持向量机SVM

支持向量机SVM

时间:2023-03-14 12:36:36浏览次数:39  
标签:__ SVM clf 支持 train Xd test 向量 predicted


支持向量机SVM
二分类模型 非线性分类器
学习策略:间隔最大化
学习目标:在特征空间中找到一个超平面

from sklearn.svm import LinearSVC
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import numpy as np

if __name__ == "__main__":
dataset = load_iris()
X = dataset.data
y = dataset.target

Xd_train, Xd_test, y_train, y_test = train_test_split(X, y, random_state=14)

clf = LinearSVC(random_state=0)
clf = clf.fit(Xd_train, y_train)
y_predicted = clf.predict(Xd_test)

accuracy = np.mean(y_predicted == y_test) * 100
print("y_test ", y_test)
print("y_predicted", y_predicted)
print("accuracy:", accuracy)


标签:__,SVM,clf,支持,train,Xd,test,向量,predicted
From: https://blog.51cto.com/u_16006123/6120306

相关文章