我正试图将树的数量和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网格。
ntree
不能是随机林的tuneGrid
的一部分,只能是mtry
(请参阅此处每个模型的调整参数的详细目录(;你只能通过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)