在rpart情节中只形成一片叶子

问题描述 投票:-3回答:1

click here for the outputi尝试下面的代码用于插入训练一个rpart情节,但只有一片叶子形式可以任何人告诉为什么这发生我尝试的代码是制作一个插入火车控制集然后做了一个rpart火车设置与下面使用的功能然后我试图用prp函数绘制rpart图,然后只有一片叶子正在形成我得到的输出是在第一行上方的图像链接中。

 [> 





     structure(list(source = structure(c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 


                    7L, 7L, 7L), .Label = c("IN", "MA", "NR", 
                        "OT", "PA", "P", "R", 
                        "S", "U", "Z"), class = "factor"),age = structure(c(2L, 1L, 1L, 
2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c("L17", 
"U17"), class = "factor"),, name = structure(c(3L, 2L, 2L, 
                        1L, 2L, 3L, 1L, 1L, 2L, 2L), .Label = c("f", "l", "s", 
                        "v", "z"), class = "factor"), success = structure(c(1L, 
                        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), 
                            day = structure(c(6L, 6L, 7L, 7L, 5L, 5L, 1L, 1L, 1L, 1L), .Label = c("Friday", 
                            "Monday", "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"
                            ), class = "factor"), country = structure(c(6L, 2L, 4L, 2L, 
                            2L, 4L, 1L, 2L, 7L, 2L), .Label = c("A", "C", 
                            "I", "Other", "S", "Ua", "U"
                            ), class = "factor")), row.names = c(NA, -10L), class = c("data.table", 
                        "data.frame"), .internal.selfref = <pointer: 0x0000000000101ef0>)





                   k<-ow
                            > str(k)
                           Classes ‘tbl_df’, ‘tbl’ and 'data.frame':    1898 obs. of  6 variables:
     $ source : Factor w/ 10 levels "I",..: 7 7 7 7 7 7 7 7 7 7 ...
     $ age    : Factor w/ 2 levels "L17","U17": 2 1 1 2 1 1 2 1 1 1 ...
     $ name   : Factor w/ 5 levels "f","l",..: 3 2 2 1 2 3 1 1 2 2 ...
     $ success: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
     $ day    : Factor w/ 7 levels "Fri","Monday",..: 6 6 7 7 5 5 1 1 1 1 ...
     $ country: Factor w/ 7 levels "A","C",..: 6 2 4 2 2 4 1 2 7 2 ...
                             - attr(*, ".internal.selfref")=<externalptr> 
                            > k.label<-k$success
                            > set.seed(37569)
                            > cv.3.folds<-createMultiFolds(k.label,k=3,times=10)
                            > ctrl.3<-trainControl(method = "repeatedcv",number = 3,repeats = 10,index=cv.3.folds)
                            >k.train.1<-k[,c("age","source","day")]
                            #i tried using rpat.oc function which is given down
                            > k.cv<-rpart.oc(94622,k.train.1,k.label,ctrl.3)
                           Warning messages:
        1: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 8 (<-activate.adobe.com:11086)
        2: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 7 (<-activate.adobe.com:11086)
        3: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 6 (<-activate.adobe.com:11086)
        4: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 5 (<-activate.adobe.com:11086)
        5: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 4 (<-activate.adobe.com:11086)
        6: In .Internal(gc(verbose, reset, full)) :
          closing unused connection 3 (<-activate.adobe.com:11086)
        7: Setting row names on a tibble is deprecated.  

                           > prp(k.cv$finalModel,type=0,extra=1,under=TRUE)



                            > View(rpart.oc)
                            function(seed,training,labels,otrl){
                            ol<-makeSOCKcluster(6,type="SOCK")
                            registerDoSNOW(ol)
                            set.seed(seed)
                            rpart.oc<-train(x=training,y=labels,method="rpart",tuneLength=30,trControl=otrl)
                            stopCluster(ol)
                            return(rpart.oc)
                            }
r r-caret rpart
1个回答
0
投票

有时,CART过程无法找到比仅截距模型更好地预测的分割(例如,用于回归的样本均值或用于分类的模式)。它基本上意味着您没有CART程序的信息预测器。

例如:

library(rpart)

dat <- data.frame(y = 1:10, x = rep(1:2, 5))
rpart(y ~ x, data = dat)
#> n= 10 
#> 
#> node), split, n, deviance, yval
#>       * denotes terminal node
#> 
#> 1) root 10 82.5 5.5 *

reprex package创建于2019-04-20(v0.2.1)

© www.soinside.com 2019 - 2024. All rights reserved.