指标精度不适用于回归模型

时间:2019-04-01 03:05:31

标签: r

我正在尝试使用R进行机器学习研究我的模型。一般的培训模式效果不佳。

# # 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

程序始终在fit_glmnet_phy <-火车(甲烷〜。,.. 该命令并显示

Metric Accuracy not applicable for regression models

我不知道这个错误 我还附上了洋甘菊的类型 enter image description here

1 个答案:

答案 0 :(得分:1)

尝试标准化输入列并将输出列映射为因子。这帮助我解决了一个类似的问题。