R 序列错误。默认值(x,y,权重=w,…):无法确定最终调整参数

R 序列错误。默认值(x,y,权重=w,…):无法确定最终调整参数,r,random-forest,r-caret,kaggle,R,Random Forest,R Caret,Kaggle,我对机器学习非常陌生,正在尝试新的学习方法,但我很早就挂断了电话。当我运行下面的代码时,出现以下错误 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) 列车中的错误。默认值(x,y,权重=w,

我对机器学习非常陌生,正在尝试新的学习方法,但我很早就挂断了电话。当我运行下面的代码时,出现以下错误

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) 列车中的错误。默认值(x,y,权重=w,…): 无法确定最终调整参数 此外:有50个或更多警告(使用warnings()查看前50个)
#加载库
图书馆(GG2);图书馆(插入符号);库(AppliedPredictiveModeling)
图书馆(pROC)
图书馆(阿米莉亚)
种子集(1234)
#从csv文件加载森林覆盖数据集

rawdata以下方法应该有效:

model1 <- train(as.factor(Cover_Type) ~ Elevation + Aspect + Slope + Horizontal_Distance_To_Hydrology,
                          data = data.train,
                          method = "rf", tuneGrid = data.frame(mtry = 3))

我也在做Kaggle比赛,并一直在使用“插入符号”包来帮助选择“最佳”模型参数。在得到了许多这样的错误之后,我研究了幕后的脚本编写,发现调用了一个名为“class2ind”的函数,该函数不存在(至少在我知道的任何地方)。我终于在“nnet”包中找到了另一个名为“class.ind”的函数。我决定尝试创建一个名为“class2ind”的本地函数,并从“class.ind”函数中弹出代码。低头看,它成功了

# fix for caret
class2ind <- function(cl)
{
        n <- length(cl)
        cl <- as.factor(cl)
        x <- matrix(0, n, length(levels(cl)) )
        x[(1:n) + n*(unclass(cl)-1)] <- 1
        dimnames(x) <- list(names(cl), levels(cl))
        x
}
#修复插入符号

Class2这是有帮助的(+1),但我在使用
method=“parRF”
运行
train
时遇到了这个问题,即使我使用
tuneGrid=data.frame(mtry=3)
时,这个问题仍然存在,而我使用
method=“rf”
时没有错误,请显示
warnings()
> modelLookup("rf")
#  model parameter                         label forReg forClass probModel
#1    rf      mtry #Randomly Selected Predictors   TRUE     TRUE      TRUE
# fix for caret
class2ind <- function(cl)
{
        n <- length(cl)
        cl <- as.factor(cl)
        x <- matrix(0, n, length(levels(cl)) )
        x[(1:n) + n*(unclass(cl)-1)] <- 1
        dimnames(x) <- list(names(cl), levels(cl))
        x
}