【问题标题】:R - Problems with nodes() for a partykit treeR - 派对工具树的节点()问题
【发布时间】:2018-08-09 10:16:24
【问题描述】:

我有一个类似的问题

how to get all terminal nodes - weight & response prediction 'ctree' in r

我想得到这样的结果。然而,在我的情况下,nodes() 函数不能正常工作。我不明白为什么。

tree <- ctree(DV ~ IV, data = data)

nodes(tree, unique(where(tree))) 

当我运行它时,我总是得到以下错误:

Error in match.arg(data, choices = c("all", "organization", "endpoint",  : 
  'arg' must be NULL or a character vector

我该怎么做才能使该功能正常工作?

非常感谢您!

【问题讨论】:

  • 您能否说明您要准确提取哪些信息? party 中的 nodes() 和 where() 函数在 partykit 中不可用。取而代之的是一个更干净、更标准的界面,例如,您可以使用 [ 运算符等轻松子集树。因此,如果您说出要提取的内容,我们可以轻松地在 @ 中提供有关如何执行此操作的指导987654329@.

标签: r party


【解决方案1】:

尝试使用party 包的ctree 函数:

library(party)
set.seed(1)
x <- rnorm(100)
y <- x+runif(100)
data <- data.frame(DV=y , IV=x)

tree <- party::ctree(DV ~ IV, data = data)
nodes(tree, unique(where(tree))) 

# [[1]]
# 3)*  weights = 19 

# [[2]]
# 6)*  weights = 26 

# [[3]]
# 9)*  weights = 19 

# [[4]]
# 8)*  weights = 19 

# [[5]]
# 5)*  weights = 17

【讨论】:

  • 感谢您指出代码nodes(tree, unique(where(tree))) 属于旧的party,而不是新的partykit 包。但是,强烈建议转换到较新的partykit 接口,因此我不建议仅仅为了使用这个旧代码 sn-p 降级到party。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 1970-01-01
  • 2013-01-24
  • 2022-01-05
  • 1970-01-01
  • 2021-02-14
  • 1970-01-01
相关资源
最近更新 更多