"Wrong model type for classification" in regression problems in R-Caret

I am trying to use various prediction algorithms from the Caret package in R for a regression problem which is my continuous target variable. Caret thinks that classification is the appropriate class for the problem, and when I submit any of the regression models, the error message "Wrong model type for classification" appears. For reproducibility see Section Data Set for Combined Cycle Power Plant . The data is in CCPP.zip. Let the predictable power depend on other variables. Power is a continuous variable.

  library(readxl)
  library(caret)
  power_plant = read_excel("Folds5x2_pp.xlsx")
  apply(power_plant,2, class)   # shows all columns are numeric

  control <- trainControl(method="repeatedcv", number=10, repeats=5)

  my_glm <- train(power_plant[,1:4], power_plant[,5],
           method = "lm",
           preProc = c("center", "scale"),
            trControl = control)

      

Below is a screenshot:

enter image description here

+3


source to share


1 answer


For some reason, caret

tibles is obfuscated, which is a tidy-versatile variant of the data frame returned read_excel

. By converting it to a simple dataframe before passing it to the carriage everything works:

library(readxl)
library(caret)
power_plant = read_excel("Folds5x2_pp.xlsx")
apply(power_plant,2, class)   # shows all columns are numeric

power_plant <- data.frame(power_plant)
control <- trainControl(method="repeatedcv", number=10, repeats=5)

my_glm <- train(power_plant[,1:4], power_plant[,5],
                method = "lm",
                preProc = c("center", "scale"),
                trControl = control)

my_glm

      



getting:

Linear Regression 

9568 samples
   4 predictor

Pre-processing: centered (4), scaled (4) 
Resampling: Cross-Validated (10 fold, repeated 5 times) 
Summary of sample sizes: 8612, 8612, 8611, 8612, 8612, 8610, ... 
Resampling results:

  RMSE      Rsquared 
  4.556703  0.9287933

Tuning parameter 'intercept' was held constant at a value of TRUE

      

+1


source







All Articles