ctree 中有一个maxdepth 选项。它位于ctree_control()
你可以如下使用它
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq, controls = ctree_control(maxdepth = 3))
您还可以将拆分大小和存储桶大小限制为“不小于”
airct <- ctree(Ozone ~ ., data = airq, controls = ctree_control(minsplit= 50, minbucket = 20))
你也可以减少增加感性和降低P值
airct <- ctree(Ozone ~ ., data = airq, controls = ctree_control(mincriterion = 0.99))
您提到的weights = 4349 只是该特定节点中的观察数。 ctree 默认为每个观察值赋予 1 的权重,但如果您认为您的观察值值得更大的权重,您可以向 ctree() 添加一个权重向量,该向量必须与数据集的长度相同并且必须是非负整数。完成此操作后,weights = 4349 必须谨慎解读。
使用weights 的一种方法是查看哪些观察结果落在某个节点中。使用上面示例中的数据,我们可以执行以下操作
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq, controls = ctree_control(maxdepth = 3))
unique(where(airct)) #in order the get the terminal nodes
[1] 5 3 6 9 8
因此我们可以检查例如节点 5 中的内容
n <- nodes(airct , 5)[[1]]
x <- airq[which(as.logical(n$weights)), ]
x
Ozone Solar.R Wind Temp Month Day
1 41 190 7.4 67 5 1
2 36 118 8.0 72 5 2
3 12 149 12.6 74 5 3
4 18 313 11.5 62 5 4
...
使用此方法,您可以创建包含终端节点信息的数据集,然后将它们导入 SAS 或 SQL
您还可以使用下面我的答案中的函数获取拆分条件列表
ctree() - How to get the list of splitting conditions for each terminal node?