如何为ctree()的终端节点提取拆分规则 [英] How to extract the splitting rules for the terminal nodes of ctree()
问题描述
我有一个数据集,该数据集包含6个类别变量,级别从5到28.我从 ctree()(方包)获得了具有17个终端节点的输出.我从
I have a data set with 6 categorical variables with levels ranging from 5 to 28. I have obtained an output from ctree() (party package) with 17 terminal nodes. I have followed the inputs by @Galled from ctree() - How to get the list of splitting conditions for each terminal node? to arrive at my desired output.
但是,我在运行代码时收到以下错误消息:
But, I'm getting the following error post running the code:
Error in data.frame(ResulTable, Means, Counts) :
arguments imply differing number of rows: 17, 2
我尝试添加以下额外的行:
I have tried adding this extra lines:
ResulTable <- rbind(ResulTable, cbind(Node = Node, Path = Path2))
ResulTable$Node <- rownames(ResulTable)
melt(ResulTable)
但到目前为止没有成功.哪里有问题的指针吗?
but no success so far. Any pointers on where it is going wrong?
推荐答案
我建议使用ctree()
的新partykit
实现而不是旧的party
包,然后可以使用函数.list.rules.party()
.它尚未正式导出,但可用于提取所需的信息.
I would recommend to use the new partykit
implementation of ctree()
rather than the old party
package, then you can use the function .list.rules.party()
. This is not officially exported, yet, but can be leveraged to extract the desired information.
library("partykit")
airq <- subset(airquality, !is.na(Ozone))
ct <- ctree(Ozone ~ ., data = airq)
partykit:::.list.rules.party(ct)
## 3 5
## "Temp <= 82 & Wind <= 6.9" "Temp <= 82 & Wind > 6.9 & Temp <= 77"
## 6 8
## "Temp <= 82 & Wind > 6.9 & Temp > 77" "Temp > 82 & Wind <= 10.3"
## 9
## "Temp > 82 & Wind > 10.3"
这篇关于如何为ctree()的终端节点提取拆分规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!