Calculating prediction accuracy of a tree using rpart's predict method (R programming)

放肆的年华 提交于 2019-12-04 09:36:46

Try calculating the confusion matrix first:

confMat <- table(test$class,t_pred)

Now you can calculate the accuracy by dividing the sum diagonal of the matrix - which are the correct predictions - by the total sum of the matrix:

accuracy <- sum(diag(confMat))/sum(confMat)

My response is very similar to @mtoto's one but a bit more simply... I hope it also helps.

mean(test$class == t_pred)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!