1. 程式人生 > >Python(線性可分SVM)

Python(線性可分SVM)

predict_train = np.sign(np.dot(x_train,w)+b)    mistag = np.where(predict_train*y_train<=0)[0] train_acc = round((len(y_train)-len(mistag))/len(y_train),3) print('Train acc:\n',classification_report(y_train.astype(int),predict_train.astype(int))) predict_test = np.sign(np.dot(x_test,w)+b)    mistag = np.where(predict_test*y_test<=0)[0] test_acc = round((len(y_test)-len(mistag))/len(y_test),3) print('Test acc:\n',classification_report(y_test.astype(int),predict_test.astype(int))) print('Train acc = ',train_acc,' Test acc = ',test_acc)