How to get percentages from decision tree for each node

纵饮孤独 提交于 2019-12-06 07:42:56

The where element of the rpart-object is the predicted class for the terminal nodes. You can get this in a table with:

> iris$where <- fit$where
> with(iris, table(Species, where))
            where
Species       2  4  5
  setosa     50  0  0
  versicolor  0 49  1
  virginica   0  5 45

I'm guessing you want the column sums divided by the total counts?

> 100*colSums(with(iris, table(Species, where)) )/150
       2        4        5 
33.33333 36.00000 30.66667 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!