[英]How to find the observation in each node of the MOB tree? (partykit package)
I have used the partykit package to create a Model-Based Partitioning (MOB) tree on a dataset and I wondered if there was a way to see which observations in our dataset pass that rules and fall in each node. 我已经使用partykit包在数据集上创建了基于模型的分区(MOB)树,我想知道是否有一种方法可以查看数据集中的哪些观测值通过该规则并落入每个节点。 (I want to have separate data frame for each node base on the tree rules). (我想基于树规则为每个节点设置单独的数据框)。
You can use predict(..., type = "node")
for all partykit
trees to obtain the predicted terminal node ID. 您可以对所有partykit
树使用predict(..., type = "node")
以获取预测的终端节点ID。 And then you can use that for split()
ting the data set. 然后,您可以将其用于split()
设置数据集。 For example: 例如:
library("partykit")
tr <- lmtree(dist ~ speed, data = cars)
plot(tr)
split(cars, predict(tr, type = "node"))
## $`3`
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
## 7 10 18
## 8 10 26
## 9 10 34
## 10 11 17
## 11 11 28
## 12 12 14
## 13 12 20
## 14 12 24
## 15 12 28
##
## $`4`
## speed dist
## 16 13 26
## 17 13 34
## 18 13 34
## 19 13 46
## 20 14 26
## 21 14 36
## 22 14 60
## 23 14 80
## 24 15 20
## 25 15 26
## 26 15 54
## 27 16 32
## 28 16 40
## 29 17 32
## 30 17 40
## 31 17 50
##
## $`5`
## speed dist
## 32 18 42
## 33 18 56
## 34 18 76
## 35 18 84
## 36 19 36
## 37 19 46
## 38 19 68
## 39 20 32
## 40 20 48
## 41 20 52
## 42 20 56
## 43 20 64
## 44 22 66
## 45 23 54
## 46 24 70
## 47 24 92
## 48 24 93
## 49 24 120
## 50 25 85
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.