2017-10-12 84 views
0

我正在使用朴素贝叶斯包在R中的机器学习模型。如何获得预测列在R

以下是模型框架'readFromCsv包含具有有效值的多个行和列。

model <- naiveBayes(student~ ., data = studentDataSet) 

我做了预测,并且给了我一个类作为预测。

predict(model, studentDataSet[1:10,], type = "class") 

但是,我所试图实现的是从预测类,比如,班级,学生,商标,等级等,让整列的详细信息,在数据集中行的名单,我想所有来自预测列的值。

感谢您的任何建议。

+4

我不太清楚你是否了解一个分​​类的机制,但你可以简单地合并的预测结果和数据用'rbind(预测,studentDataSet [1:10,]' –

回答

0

如果studentDataSet_test是在要预测你的数据帧,则:

studentDataSet_test$prediction <- predict(model, studentDataSet_test, type = "class") 
print(studentDataSet_test) 
# This will print all details with the prediction