【发布时间】:2022-06-20 08:55:49
【问题描述】:
我正在使用 xgboost 进行时间序列预测,他们运行 train 函数它给了我这个错误:[.xgb.DMatrix(x, 0, , drop = FALSE) 中的错误:未使用的参数 (drop = FALSE)
代码:
data <- economics %>% dplyr::select(date, unemploy)
extended_data <- data %>%
rbind(tibble::tibble(date = seq(from = lubridate::as_date("2015-05-01"),
by = "month", length.out = 12),
unemploy = rep(NA, 12)))
extended_data_mod <- extended_data %>%
dplyr::mutate(.,
months = lubridate::month(date),
years = lubridate::year(date))
train <- extended_data_mod[1:nrow(data), ] # initial data
pred <- extended_data_mod[(nrow(data) + 1):nrow(extended_data), ] # extended time index
trainig <- sparse.model.matrix( ~ .-1, data = train)
x_train <- xgboost::xgb.DMatrix(as.matrix(train %>%
dplyr::select(months, years)))
x_pred <- xgboost::xgb.DMatrix(as.matrix(pred %>%
dplyr::select(months, years)))
y_train <- train$unemploy
xgb_trcontrol <- caret::trainControl(
method = "cv",
number = 5,
allowParallel = TRUE,
verboseIter = FALSE,
returnData = FALSE
)
xgb_grid <- base::expand.grid(
list(
nrounds = c(100, 200),
max_depth = c(10, 15, 20), # maximum depth of a tree
colsample_bytree = seq(0.5), # subsample ratio of columns when construction each tree
eta = 0.1, # learning rate
gamma = 0, # minimum loss reduction
min_child_weight = 1, # minimum sum of instance weight (hessian) needed ina child
subsample = 1 # subsample ratio of the training instances
))
xgb_model <- caret::train(
x_train, y_train,
trControl = xgb_trcontrol,
tuneGrid = xgb_grid,
method = "xgbTree",
nthread = 1
)
我还没有发现任何其他东西,也许有些人有其他实现或如何解决这个问题?
【问题讨论】:
标签: r time time-series xgboost forecast