Fei Long
Fei Long

Reputation: 31

Metric Accuracy not applicable for regression models

I am trying to investigate my model with R with machine learning. Training model in general works not well.

# # Logistic regression multiclass
for (i in 1:30) {
  # split data into training/test 
  trainPhyIndex <- createDataPartition(subs_phy$Methane, p=10/17,list =  FALSE)
  trainingPhy <- subs_phy[trainPhyIndex,]
  testingPhy <- subs_phy[-trainPhyIndex,]
  # Pre-process predictor values

  trainXphy <- trainingPhy[,names(trainingPhy)!= "Methane"]
  preProcValuesPhy <- preProcess(x= trainXphy,method = c("center","scale"))

  # using boot to avoid over-fitting
  fitControlPhyGLMNET <- trainControl(method = "repeatedcv",
                           number = 10,
                           repeats = 4,
                           savePredictions="final",
                           classProbs = TRUE
                           )

  fit_glmnet_phy <- train (Methane~.,
                           trainingPhy,
                           method = "glmnet", 
                           tuneGrid = expand.grid(
                             .alpha =0.1,
                             .lambda = 0.00023),
                           metric = "Accuracy",
                           trControl = fitControlPhyGLMNET)
  pred_glmnet_phy <- predict(fit_glmnet_phy, testingPhy)


  # Get the confusion matrix to see accuracy value

  u <- union(pred_glmnet_phy,testingPhy$Methane)
  t <- table(factor(pred_glmnet_phy, u), factor(testingPhy$Methane, u))
  accu_glmnet_phy <- confusionMatrix(t)
#   accu_glmnet_phy<-confusionMatrix(pred_glmnet_phy,testingPhy$Methane) 

glmnetstatsPhy[(nrow(glmnetstatsPhy)+1),] = accu_glmnet_phy$overall

}
glmnetstatsPhy

The program always stopped on fit_glmnet_phy <- train (Methane~., .. this command and shows

Metric Accuracy not applicable for regression models

I have no idea about this error I also attached the type of mathane enter image description here

Upvotes: 3

Views: 6904

Answers (1)

vaishnavi telukuntla
vaishnavi telukuntla

Reputation: 31

Try normalizing the input columns and mapping the output column as factors. This helped me resolve an issue similar to it.

Upvotes: 3

Related Questions