R

时间:2018-01-15 13:33:04

标签: r r-caret training-data

我最近开始玩护理包,我正在努力理解训练论点。下面我使用了Sonar数据集并创建了三个输入和输出。

 library(caret)
 library(mlbench)
 data(Sonar)
 set.seed(107)
 SonarImput1<-Sonar[,1:60]
 SonarImput2<-Sonar[,1:2]
 SonarImput3<-Sonar[,1]
 SonarOutCome<-Sonar[,61]
 mlp <- caret::train(SonarImput1,SonarOutCome, method = "mlp", preProc = c("center", "scale"))
 mlp2 <- caret::train(SonarImput2,SonarOutCome, method = "mlp", preProc = c("center", "scale"))
 mlp3 <- caret::train(SonarImput3,SonarOutCome, method = "mlp", preProc = c("center", "scale"))

为什么mlp3会产生错误?难道只能用输出创建一个预测变量吗?

  

出了点问题;缺少所有准确度指标值:   在eval(expr,envir,enclos)中:     Resample17的模型拟合失败:size = 3 x中的错误[modelIndex ,, drop = FALSE]:维数不正确

1 个答案:

答案 0 :(得分:0)

您需要为自变量(x)放置数据框而不是数字向量。试试这个

mlp3 <- caret::train(data.frame(x=SonarImput3),SonarOutCome, method = "mlp", preProc = c("center", "scale"))