The tuning parameter grid should have columns mtry

2023-01-10 11:26:00 浏览数 (1)

采用caret包train函数进行随机森林参数寻优,代码如下,出现The tuning parameter grid should have columns mtry

上网找了很多回答,解释为随机森林可供寻优的参数只有mtry,但是一个一个更换ntree参数比较麻烦,请问只能用这种方法吗?

fit <- train(x=Csoc[,-c(1:5)],

y=Csoc[,5],

data = Csoc[,-c(1:4)],

method = "rf",

trControl = trainControl(method = "repeatedcv",

number = 10,repeats = 3),

tuneGrid = expand.grid(mtry = seq(3,21,3),

ntree = seq(300,700,100)),

#ntree = 300,

metric = "Rsquared")

plot(fit)

fit

0 人点赞