R caret train Error in evalSummaryFunction: cannnot compute class probabilities for regression

前端 未结 2 587
梦毁少年i
梦毁少年i 2021-01-19 10:23
> cv.ctrl <- trainControl(method = \"repeatedcv\", repeats = 3,
+                         summaryFunction = twoClassSummary,
+                         classPro         


        
相关标签:
2条回答
  • 2021-01-19 10:50

    If you changed the values in y to "YES" and "NO" instead of 1 and zero respectively, then the code will run.

    y=ifelse(train.batch$y==0,"No","Yes")
    
    0 讨论(0)
  • 2021-01-19 10:56

    Apparently this error is due to the fact that my y is not a Factor.

    Following code works fine:

    library(caret)
    library(mlbench)
    data(Sonar)
    
    ctrl <- trainControl(method = "cv", 
                         summaryFunction = twoClassSummary, 
                         classProbs = TRUE)
    set.seed(1)
    gbmTune <- train(Class ~ ., data = Sonar,
                     method = "gbm",
                     metric = "ROC",
                     verbose = FALSE,                    
                     trControl = ctrl)
    

    Then doing:

    Sonar$Class = as.numeric(Sonar$Class)
    

    and same code throws the error:

    > gbmTune <- train(Class ~ ., data = Sonar,
    +                  method = "gbm",
    +                  metric = "ROC",
    +                  verbose = FALSE,                    
    +                  trControl = ctrl)
    Error in evalSummaryFunction(y, trControl, classLevels, metric, method) : 
      train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl()
    In addition: Warning message:
    In train.default(x, y, weights = w, ...) :
      cannnot compute class probabilities for regression
    

    But caret train documentation says:

    y   a numeric or factor vector containing the outcome for each sample.
    
    0 讨论(0)
提交回复
热议问题