我正在尝试使用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 <- train (Methane~., .. 这个命令时停止,并显示:
"最初的回答"
Metric Accuracy not applicable for regression models
我对这个错误没有任何想法。我还附上了mathane的类型。点击查看图片描述。最初的回答。
glmnet()
在度量标准设置为“Accuracy”的情况下运行回归模型,而此度量标准并不适用于回归模型。'Accuracy'是分类模型的度量标准。你希望'Methane'是什么类型的变量?它是连续的还是一个因子(离散的)?根据你想要混淆矩阵,我假设你希望它是一个因子变量,这样glment()
就会生成一个分类(逻辑回归)算法。 - undefinedglment()
使用回归而不是分类,因此你将无法创建混淆矩阵。甲烷代表什么?你能发布一份数据样本吗? - undefinedRMSE
替代准确率(Accuracy)
。是否有任何函数或命令可用于评估算法。我的意思是我们可以使用confusionMatrix
并设置metric='Accuracy'
来评估算法。我想知道是否有任何函数可用于使用metric='RMSE'
评估算法? - undefined