零件节点分配 [英] rpart node assignment
本文介绍了零件节点分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为拟合的 rpart
树提取节点分配?当我将模型应用于新数据时该怎么办?
Is it possible to extract the node assignment for a fitted rpart
tree? What about when I apply the model to new data?
我的想法是,我想将节点用作群集数据的一种方式。在其他软件包(例如SPSS)中,我可以保存预测的类,概率和节点号以供进一步分析。
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.
鉴于R有多强大,我想有一个简单的解决方案。
Given how powerful R can be, I imagine there is a simple solution to this.
推荐答案
尝试使用partykit软件包:
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
这篇关于零件节点分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文