【问题标题】:R how to determine the largest possible tree with Rpart and TreeR如何用Rpart和Tree确定最大可能的树
【发布时间】:2021-07-25 00:39:01
【问题描述】:

我想用 rpart 和 tree 包确定最大的树。我用这两个包创建了树,但我不知道如何到达可能的最大树。有谁知道吗?

【问题讨论】:

  • 你能提供一个相关数据的例子吗?
  • X_rpart=rpart(type~.,method="class",data = rawdata_trainingset, control=rpart.control(minsplit = 1))。这是我的树创建代码,它提供了 8 个节点树,但我想用给定的数据达到最大的树。例如,我可以用给定的数据创建 15 个节点树吗

标签: r tree rpart


【解决方案1】:

我不知道是否可以通过一些参数设置所需节点的数量,但是,您可以通过减少rpart.control 函数的cp 参数来增加树的复杂性。像这样:

library(rpart)
library(rpart.plot)
data(iris)
l <- lapply(c(0.1,0.01,0.001), function(x){
  X_rpart = rpart(
    Species ~ .,
    method = "class",
    data = iris,
    control = rpart.control(minsplit = 1,cp=x)
  )
})

for (i in 1:length(l)) {
  rpart.plot(l[[i]])
}

您可以看到,cp 越小,最终树中的节点数就越多。这里是 3 次迭代的图:

【讨论】:

  • 感谢您的评论:)))。我会试试的,我希望它会奏效。非常感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 2016-04-09
  • 2016-03-07
  • 2014-06-16
  • 2013-02-09
  • 2011-12-04
  • 2015-10-11
相关资源
最近更新 更多