【发布时间】:2013-07-09 23:34:37
【问题描述】:
如何获取每行rpart 模型的终端节点的 ID(或名称)? predict.rpart 只能返回分类树的预测类别(数字或因子)或类别概率或某种组合(使用 type="matrix")。
我想做这样的事情:
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
plot(fit) # there are 5 terminal nodes
predict(fit, type = "node_id") # should return IDs of terminal nodes (e.g. 1-5) (does not work)
【问题讨论】: