grid <- expand.grid(nrouds = c(75, 100), max_depth = c(2, 3), eta = c(.01, .1, ....
🚨 错误信息
grid <- expand.grid(nrouds = c(75, 100),
max_depth = c(2, 3),
eta = c(.01, .1, .3),
gamma = c(.5, .25),
colsamples_bytree = 1,
min_child_weight = 1,
subsample = .5)
# 一些控制参数,重抽样方法选择5折交叉验证
ctrl <- trainControl(method = 'cv',
number = 5,
verboseIter = F,
returnData = F,
returnResamp = 'final')
# 开始调优
set.seed(123)
train.xgb <- train(x = train[, 1:8],
y = train$diabetes,
trControl = ctrl,
tuneGrid = grid,
method = 'xgbTree')
XGBoost运行的时候总产生这个错误:“错误: The tuning parameter grid should have columns nrounds, max_depth, eta, gamma, colsample_bytree, min_child_weight, subsample”,但是我的tune grid是存在这些参数的,有大佬知道是怎么回事吗
🤖 AI解决方案
错误翻译
原文:The tuning parameter grid should have columns nrounds, max_depth, eta, gamma, colsample_bytree, min_child_weight, subsample
译文:调优参数网格应包含列 nrounds、max_depth、eta、gamma、colsample_bytree、min_child_weight、subsample
原因分析
- 根本原因:参数名拼写错误。您在
expand.grid()中将nrounds误写为nrouds(缺少字母n) - 错误位置:
grid数据框的第一列参数名称定义错误
解决方案
# 修复拼写错误:将 nrouds 改为 nrounds
grid <- expand.grid(nrounds = c(75, 100), # 修正拼写
max_depth = c(2, 3),
eta = c(.01, .1, .3),
gamma = c(.5, .25),
colsample_bytree = 1, # 修正拼写
min_child_weight = 1,
subsample = .5)
️ 预防措施
names(grid)检查列名是否正确匹配?train查看method='xgbTree'所需的准确参数名修正后重新运行代码即可解决问题!