如何获取每行模型的终端节点的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)
kyphosis["id_node"] <-fit$where
将叶子ID分配给原始数据框。 - Tomas Greif