【问题标题】:Metric Accuracy not applicable for regression models度量精度不适用于回归模型
【发布时间】:2021-03-05 00:06:26
【问题描述】:

我正在尝试使用 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

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

【问题讨论】:

  • 该错误可能意味着您的目标变量是数字,导致glmnet() 运行回归模型,而您将指标设置为不适用于回归的“准确度”。 “准确度”是分类模型的指标。您期望“甲烷”是什么类型的变量?它是连续的还是一个因素?根据您对混淆矩阵的需求,我假设您希望它成为因子变量,以便 glment() 生成分类(逻辑回归)算法。
  • 谢谢!变量的类型是浮点数。这是导致错误的主要原因吗?有什么办法可以解决吗?我真的很感激。
  • 如果您预测数字(浮点)glment() 使用回归而不是分类,因此您将无法创建混淆矩阵。甲烷代表什么?您可以发布数据样本吗?
  • 你把甲烷做成二进制了吗?也就是给它某种形式的区间,然后把它变成一种“因子”变量。
  • 知道了。我正在尝试创建分类并将甲烷转换为二进制文件。非常感谢。我也尝试将RMSE 改为Accuracy。是否有任何功能或命令有助于评估算法。我的意思是我们可以使用confusionMatrix 来评估metric='Accuracy' 的算法。我想知道有什么函数可以用来评估 metric='RMSE' 的算法吗?

标签: r


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 2016-03-16
    • 2018-11-25
    • 2014-01-20
    • 1970-01-01
    • 2020-04-24
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多