from sklearn import datasets from sklearn import neighbors from sklearn import svm from sklearn.metrics import classification_report from sklearn.model_selection import train_test_split svm =svm.SVC() iris = datasets.load_iris() X=iris.data Y=iris.target x_train,x_test,y_train,y_test=train_test_split(X,Y,test_size=0.3,random_state=0) svm.fit(x_train,y_train) print("svm模型训练集的准确率:%.3f"%svm.score(x_train,y_train)) print("svm模型测试集的准确率:%.3f"%svm.score(x_test,y_test)) target_names =['setosa','versicolor','virginica'] y_hat=svm.predict(x_test) print(classification_report(y_test,y_hat,target_names=target_names))
支持向量机svm
最新推荐文章于 2024-09-08 21:19:52 发布