ModelOriented / forester

Trees are all you need
https://modeloriented.github.io/forester/
GNU General Public License v3.0
113 stars 15 forks source link

label must be provided when data is a matrix - XGBoost #96

Closed RickPack closed 1 year ago

RickPack commented 1 year ago

This causes XGBoost to return: Error in xgb.get.DMatrix(data, label, missing, weight, nthread = merged$nthread) : label must be provided when data is a matrix

Using economics from the ggplot2 package:

library(forester)
library(ggplot2)

test_model <-
  train(
    data.frame(economics) %>% select(-date),
    type = 'regression',
    y = 'uempmed',
    engine = c('xgboost'))
RickPack commented 1 year ago

The error is defined in the R source code for XGboost here: https://github.com/dmlc/xgboost/blob/master/R-package/R/xgb.DMatrix.R

# get dmatrix from data, label
# internal helper method
xgb.get.DMatrix <- function(data, label = NULL, missing = NA, weight = NULL, nthread = NULL) {
  if (inherits(data, "dgCMatrix") || is.matrix(data)) {
    if (is.null(label)) {
      stop("label must be provided when data is a matrix")
    }
HubertR21 commented 1 year ago

As mentioned in Issue #97 we've already found a solution for that problem