train.default(x, y, weights = w, ...) 中的错误:无法确定最终调整参数
Error in train.default(x, y, weights = w, ...) : final tuning parameters could not be determined
我正在尝试使用 R 中的 caret
来预测结果。当我尝试训练模型时,出现错误:
Error in train.default(x, y, weights = w, ...) :
final tuning parameters could not be determined
我也用它们各自的 tuneGrid
数据框尝试了其他分类方法。我也尝试过这个 link 的解决方案,但它不起作用。
这是我的代码:
d <- read.csv("train.csv")
new <- d[1:50,-1]
library(caret)
modfit <- train(target~., method="rf", data=new)
Error in train.default(x, y, weights = w, ...) :
final tuning parameters could not be determined
In addition: There were 50 or more warnings (use warnings() to see the first 50)
modfit<- train(target~., data= new, method= "rf", tuneGrid= data.frame(mtry=3))
Error in train.default(x, y, weights = w, ...) :
final tuning parameters could not be determined
In addition: There were 27 warnings (use warnings() to see them)
第一行是 ID,因此已删除。
我下载了数据集,你这里有两个问题:
首先,既然你在做分类,最好指定目标是一个因素。即,
modfit <- train(as.factor(target)~., method="rf", data=new)
其次,数据集的前50行只有class_1。您至少需要两个不同的 类。如果你真的只想处理 50 行,你可以随机抽样。
new = d[sample(1:nrow(d), size = 50), ].
调用 warnings()
在这些情况下对于调试非常有用。
我正在尝试使用 R 中的 caret
来预测结果。当我尝试训练模型时,出现错误:
Error in train.default(x, y, weights = w, ...) : final tuning parameters could not be determined
我也用它们各自的 tuneGrid
数据框尝试了其他分类方法。我也尝试过这个 link 的解决方案,但它不起作用。
这是我的代码:
d <- read.csv("train.csv")
new <- d[1:50,-1]
library(caret)
modfit <- train(target~., method="rf", data=new)
Error in train.default(x, y, weights = w, ...) :
final tuning parameters could not be determined
In addition: There were 50 or more warnings (use warnings() to see the first 50)
modfit<- train(target~., data= new, method= "rf", tuneGrid= data.frame(mtry=3))
Error in train.default(x, y, weights = w, ...) :
final tuning parameters could not be determined
In addition: There were 27 warnings (use warnings() to see them)
第一行是 ID,因此已删除。
我下载了数据集,你这里有两个问题:
首先,既然你在做分类,最好指定目标是一个因素。即,
modfit <- train(as.factor(target)~., method="rf", data=new)
其次,数据集的前50行只有class_1。您至少需要两个不同的 类。如果你真的只想处理 50 行,你可以随机抽样。
new = d[sample(1:nrow(d), size = 50), ].
调用 warnings()
在这些情况下对于调试非常有用。