【问题标题】:decision tree in R error:fit is not a tree,just a rootR错误中的决策树:fit不是树,只是根
【发布时间】:2016-09-29 15:22:08
【问题描述】:

下午好! 我对决策树有疑问。

f11<-as.factor(Z24train$f1)
fit_f1 <- rpart(f11~TSU+TSL+TW+TP,data = Z24train,method="class")
plot(fit_f1, uniform=TRUE, main="Classification Tree for Kyphosis")

但是出现了这个错误:

Error in plot.rpart(fit_f1, uniform = TRUE, main = "Classification Tree for Kyphosis") : 
  fit is not a tree, just a root

这是什么问题? 感谢您的帮助:)

【问题讨论】:

    标签: decision-tree


    【解决方案1】:

    这可能是由于RPART 在使用默认控制参数后无法使用给定数据集创建决策树。

    rpart.control(minsplit = 20, minbucket = round(minsplit/3), cp = 0.01, 
    maxcompete = 4, maxsurrogate = 5, usesurrogate = 2, xval = 10,
    surrogatestyle = 0, maxdepth = 30, ...)
    

    如果要创建树,可以调整控制参数并创建过拟合树。

    tree <- rpart(f11~TSU+TSL+TW+TP,data = Z24train,method="class",control =rpart.control(minsplit =1,minbucket=1, cp=0))
    

    参数描述取自 r 文档 (https://stat.ethz.ch/R-manual/R-devel/library/rpart/html/rpart.control.html)

    最小分割
    为了尝试拆分,节点中必须存在的最小观察数。

    minbucket
    任何终端节点中的最小观测数。如果只指定了 minbucket 或 minsplit 之一,则代码将 minsplit 设置为 minbucket*3 或 minbucket 设置为 minsplit/3,视情况而定。

    cp
    复杂度参数。不会尝试任何不会将整体失配度降低 cp 的拆分。例如,对于 anova 分裂,这意味着整体 R 平方必须在每一步增加 cp。这个参数的主要作用是通过修剪明显不值得的分裂来节省计算时间。本质上,用户通知程序任何不能通过 cp 改善拟合的分割都可能会被交叉验证剪除,因此程序不需要继续它

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2016-05-18
      • 2014-08-21
      • 1970-01-01
      • 2016-12-20
      • 2014-07-19
      • 2017-05-03
      • 2014-08-20
      相关资源
      最近更新 更多