R- Xgboost:xgb.DMatrix 未使用参数中出现错误
这是我的第一个问题,如果我不清楚,我很抱歉。
我正在构建一个 Xgboost 模型来预测多个时间序列。我已经创建了训练和测试 xgb.DMatrix,还有 xgb_trcontrol 和 xgb_grid 调整参数,但是当我尝试构建模型时,我收到如下错误消息:
[.xgb.DMatrix
(x, 0, , drop = FALSE) 中出现错误:未使用参数 (下降=假)
此外,训练矩阵和测试矩阵中的所有列都是数字。 请找到下面的代码:
xgb_train <- base_proyecto[1:split_factor,]
xgb_test <- base_proyecto[(split_factor+1):132,]
#Transform train and test data to DMatrix form
train_Dmatrix <- xgb_train %>% #Here I've ommited date, and target variable
dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>%
as.matrix() %>%
xgb.DMatrix()
pred_Dmatrix <- xgb_test %>% #Here I've ommited date, and target variable
dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>%
as.matrix() %>%
xgb.DMatrix()
targets <- xgb_train$credito_total
#Cross-validation
xgb_trcontrol <- trainControl(
method = "cv",
number = 5,
allowParallel = TRUE,
verboseIter = FALSE,
returnData = FALSE
)
#Building parameters set
xgb_grid <- base::expand.grid(
list(
nrounds = c(100,200),
max_depth = c(10,15,20),
colsample_bytree = seq(0.5),
eta = 0.1,
gamma = 0,
min_child_weight = 1,
subsample = 1)
)
#Building the model (The error message pops up here)
model_xgb <- train(
train_Dmatrix,targets,
trControl = xgb_trcontrol,
tuneGrid = xgb_grid,
method = "xgbTree",
nthread = 1
)
PD:我的数据看起来像这样
> head(base_proyecto)
credito_total google_q1 google_q2 google_q3 google_q4 inflacion tasa_activa tasa_pasiva precio_wti fecha
1 -2.390521 -1.2273561 -2.056537 -1.11448 -1.2664245 0.2832895 1.3848000 -1.4575066 0.5764112 2010-10-01
2 -2.027531 -1.2273561 -2.056537 -1.11448 -1.2664245 0.3342099 1.3848000 -1.4575066 0.6711702 2010-11-01
3 -2.121730 -1.2273561 -2.056537 -1.11448 -1.2664245 1.0908061 0.8240173 -1.4904277 0.8905438 2010-12-01
4 -1.834393 -1.0333890 -1.337906 -1.11448 -1.2664245 1.6026221 0.6299002 -1.0459930 0.9052552 2011-01-01
5 -1.280232 -0.5484713 -1.158248 -1.11448 0.4406159 1.2168620 -0.1034311 -1.1118351 0.9013610 2011-02-01
6 -1.131422 -1.0333890 0.997645 -1.11448 -0.7786986 0.5394940 0.7593116 -0.9801508 1.4893860 2011-03-01
year yday month
1 2010 274 10
2 2010 305 11
3 2010 335 12
4 2011 1 1
5 2011 32 2
6 2011 60 3
欢迎有关如何解决此问题的任何建议吗?
This is my first question here so I'm sorry if I'm not clear.
I was building an Xgboost model to forecast multiple time series. I've created the train and test xgb.DMatrix, also the xgb_trcontrol and xgb_grid tunning parameters, nevertheless when I try to build the model I get an error message like this:
Error in
[.xgb.DMatrix
(x, 0, , drop = FALSE) : unused argument
(drop = FALSE)
Also, all the columns in the train and test matrix are numeric.
Please find the code below:
xgb_train <- base_proyecto[1:split_factor,]
xgb_test <- base_proyecto[(split_factor+1):132,]
#Transform train and test data to DMatrix form
train_Dmatrix <- xgb_train %>% #Here I've ommited date, and target variable
dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>%
as.matrix() %>%
xgb.DMatrix()
pred_Dmatrix <- xgb_test %>% #Here I've ommited date, and target variable
dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>%
as.matrix() %>%
xgb.DMatrix()
targets <- xgb_train$credito_total
#Cross-validation
xgb_trcontrol <- trainControl(
method = "cv",
number = 5,
allowParallel = TRUE,
verboseIter = FALSE,
returnData = FALSE
)
#Building parameters set
xgb_grid <- base::expand.grid(
list(
nrounds = c(100,200),
max_depth = c(10,15,20),
colsample_bytree = seq(0.5),
eta = 0.1,
gamma = 0,
min_child_weight = 1,
subsample = 1)
)
#Building the model (The error message pops up here)
model_xgb <- train(
train_Dmatrix,targets,
trControl = xgb_trcontrol,
tuneGrid = xgb_grid,
method = "xgbTree",
nthread = 1
)
PD: My data looks like this
> head(base_proyecto)
credito_total google_q1 google_q2 google_q3 google_q4 inflacion tasa_activa tasa_pasiva precio_wti fecha
1 -2.390521 -1.2273561 -2.056537 -1.11448 -1.2664245 0.2832895 1.3848000 -1.4575066 0.5764112 2010-10-01
2 -2.027531 -1.2273561 -2.056537 -1.11448 -1.2664245 0.3342099 1.3848000 -1.4575066 0.6711702 2010-11-01
3 -2.121730 -1.2273561 -2.056537 -1.11448 -1.2664245 1.0908061 0.8240173 -1.4904277 0.8905438 2010-12-01
4 -1.834393 -1.0333890 -1.337906 -1.11448 -1.2664245 1.6026221 0.6299002 -1.0459930 0.9052552 2011-01-01
5 -1.280232 -0.5484713 -1.158248 -1.11448 0.4406159 1.2168620 -0.1034311 -1.1118351 0.9013610 2011-02-01
6 -1.131422 -1.0333890 0.997645 -1.11448 -0.7786986 0.5394940 0.7593116 -0.9801508 1.4893860 2011-03-01
year yday month
1 2010 274 10
2 2010 305 11
3 2010 335 12
4 2011 1 1
5 2011 32 2
6 2011 60 3
Any suggestions on how to fix this are welcome?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论