# training data set
data(x_train)
# training data label
data(y_train)
# test data set
data(x_test)
# test data label
data(y_test)
library(e1071)
#svm
svm_model = svm(x_train,y_train)
y_pred_svm = predict(svm_model,x_test)
y_pred_svm = round(y_pred_svm)
accuracy_svm = sum(y_pred_svm==y_test)/dim(y_test)[1]
#naive bayes
bayes_model = naiveBayes(x_train,y_train)
y_pred_bayes = predict(bayes_model,x_test)
y_pred_bayes = round(y_pred_bayes)
accuracy_bayes = sum(y_pred_bayes==y_test)/dim(y_test)[1]
标签是1到5之间的数字。
此代码适用于SVM,但不适用于Naive Bayes分类器,更具体,y_pred_svm是数字向量,但y_pred_bayes不是。
我在包中找到了很多关于naiveBayes函数的例子,但是数据和标签不在单独的数组中。谁能帮我吗?感谢。