gpt4 book ai didi

r - 如何实现使用ctree(party包)构建的决策树的输出?

转载 作者:行者123 更新时间:2023-12-04 12:31:53 27 4
gpt4 key购买 nike

我使用 ctree 构建了一个决策树功能通过 party包裹。它有 1700 个节点。
首先,ctree有没有办法?给 maxdepth争论?我试过 control_ctree选项但是,它抛出了一些错误消息,说找不到 ctree 函数。

另外,我怎样才能消耗这棵树的输出?。如何为 SAS 或 SQL 等其他平台实现。我还对值 "* weights = 4349 " 有什么疑问在节点的末尾表示。我怎么知道哪个终端节点投票给哪个预测值。

最佳答案

有一个maxdepth ctree 中的选项。它位于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?

关于r - 如何实现使用ctree(party包)构建的决策树的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com