我尝试使用插入符号显式地将树的数量和mtry传递给随机森林算法:
library(caret)
library(randomForest)
repGrid<-expand.grid(.mtry=c(4),.ntree=c(350))
controlRep <- trainControl(method="cv",number = 5)
rfClassifierRep <- train(label~ .,
data=overallDataset,
method="rf",
metric="Accuracy",
trControl=controlRep,
tuneGrid = repGrid,)我得到了这个错误:
Error: The tuning parameter grid should have columns mtry我先试着用更明智的方式:
rfClassifierRep <- train(label~ .,
data=overallDataset,
method="rf",
metric="Accuracy",
trControl=controlRep,
ntree=350,
mtry=4,
tuneGrid = repGrid,)但这会导致一个错误,说明我有太多的超参数。这就是为什么我要做一个1x1的网格。
发布于 2021-04-09 23:55:42
ntree不能是随机林的tuneGrid的一部分,只能是mtry的一部分(请参阅每个模型here的调优参数的详细目录);您只能通过train传递它。相反,由于您调优了mtry,因此后者不能是train的一部分。
总而言之,这里的正确组合是:
repGrid <- expand.grid(.mtry=c(4)) # no ntree
rfClassifierRep <- train(label~ .,
data=overallDataset,
method="rf",
metric="Accuracy",
trControl=controlRep,
ntree=350,
# no mtry
tuneGrid = repGrid,)https://stackoverflow.com/questions/67024039
复制相似问题