rpart node assignment

让人想犯罪 __ 提交于 2019-12-09 23:00:54

问题


Is it possible to extract the node assignment for a fitted rpart tree? What about when I apply the model to new data?

The idea is that I would like to use the nodes as a way to cluster my data. In other packages (e.g. SPSS), I can save the predicted class, probabilities, and node number for further analysis.

Given how powerful R can be, I imagine there is a simple solution to this.


回答1:


Try using the partykit package:

library(rpart)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)
library(partykit)
z.auto2 <- as.party(z.auto)
predict(z.auto2, car.test.frame[1:3,], type = "node")

# Eagle Summit 4 Ford Escort   4  Ford Festiva 4 
#              7               7               7 


来源:https://stackoverflow.com/questions/9797447/rpart-node-assignment

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