模型
sklearn.svm中的支持向量机:
Classify:SVC
、nuSVC
、LinearSVC
Regression:SVR
、nuSVR
、LinearSVR
OneClassSVM
本文采用Classify系列,classify三个模型的区别;参数详解
预处理
import pandas as pd
path = "../Data/classify.csv"
rawdata = pd.read_csv(path)
X = rawdata.iloc[:,:13]
Y = rawdata.iloc[:,14] # {”A":0,"B":1,"C":2}
Y = pd.Categorical(Y).codes # ABC变成123
建模
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, recall_score
import sklearn.svm as svm
x_train, x_test, y_train, y_test = \
train_test_split(X, Y, test_size=0.3)
model = svm.SVC(kernel="linear", decision_function_shape="ovo")
训练
acu_train = model.score(x_train, y_train)
acu_test = model.score(x_test, y_test)
y_pred = model.predict(x_test)
recall = recall_score(y_test, y_pred