mlr-org / mlr3proba

Probabilistic Learning for mlr3
https://mlr3proba.mlr-org.com
GNU Lesser General Public License v3.0
126 stars 20 forks source link

An error occurred when using learner `surv.xgboost` for tuning #351

Closed pengjunwe1 closed 7 months ago

pengjunwe1 commented 7 months ago

Hi, I used Xgboost to analyze the time-to-data data. I wanted hyperparameter tuning with the tune function first, but I couldn't resolve the Error: Error in predict.xgb.Booster(model, newdata = newdata) : Feature names stored in ‘object’ and ‘newdata’ are different!

Here's a simple example I used:

library(mlr3verse)
library(mlr3extralearners)
library(mlr3proba)
library(survival)

data <- rats
data <- data[,c('litter','rx','time','status')]
task <- as_task_surv(data,time = 'time',event = 'status')
learner <- lrn('surv.xgboost',eta = to_tune(0.001,1))

#Error occured
instance <- tune(tuner = tnr('random_search'),
                 task = task,
                 learner = learner,
                 resampling = rsmp('holdout'),
                 measures = msr('surv.cindex'),
                 term_evals = 1)  

I would appreciate it if you could help me see where the problem might be.

jemus42 commented 7 months ago

I can not reproduce any error here, using reprex to run your code it looks like it works just fine:

library(mlr3verse)
#> Loading required package: mlr3
library(mlr3extralearners)
library(mlr3proba)
library(survival)

data <- rats
data <- data[,c('litter','rx','time','status')]
task <- as_task_surv(data,time = 'time',event = 'status')
learner <- lrn('surv.xgboost',eta = to_tune(0.001,1))

#Error occured
instance <- tune(tuner = tnr('random_search'),
                 task = task,
                 learner = learner,
                 resampling = rsmp('holdout'),
                 measures = msr('surv.cindex'),
                 term_evals = 1)  
#> INFO  [15:53:52.206] [bbotk] Starting to optimize 1 parameter(s) with '<OptimizerRandomSearch>' and '<TerminatorEvals> [n_evals=1, k=0]'
#> INFO  [15:53:52.221] [bbotk] Evaluating 1 configuration(s)
#> INFO  [15:53:52.229] [mlr3] Running benchmark with 1 resampling iterations
#> INFO  [15:53:52.248] [mlr3] Applying learner 'surv.xgboost' on task 'data' (iter 1/1)
#> INFO  [15:53:52.277] [mlr3] Finished benchmark
#> INFO  [15:53:52.292] [bbotk] Result of batch 1:
#> INFO  [15:53:52.294] [bbotk]          eta surv.cindex warnings errors runtime_learners
#> INFO  [15:53:52.294] [bbotk]  0.002075346   0.6221179        0      0            0.007
#> INFO  [15:53:52.294] [bbotk]                                 uhash
#> INFO  [15:53:52.294] [bbotk]  12565c12-11b4-4fa6-8603-a3f37ffcf20c
#> INFO  [15:53:52.297] [bbotk] Finished optimizing after 1 evaluation(s)
#> INFO  [15:53:52.297] [bbotk] Result:
#> INFO  [15:53:52.298] [bbotk]          eta learner_param_vals  x_domain surv.cindex
#> INFO  [15:53:52.298] [bbotk]  0.002075346          <list[5]> <list[1]>   0.6221179

Created on 2024-01-25 with reprex v2.1.0

I don't see anything wrong with your example code per se though, so I could only speculate what caused the error message unfortunately.

bblodfon commented 7 months ago

@pengjunwe1 issue solved? you may need to update the packages?

pengjunwe1 commented 7 months ago

@bblodfon @jemus42 I uninstalled and reinstalled these packages (mlr3verse ,xgboost ,mlr3proba,mlr3extralearners), but they still didn't work.

bblodfon commented 7 months ago

@pengjunwe1 library versions you used?

bblodfon commented 7 months ago

@pengjunwe1 please install the latest mlr3extralearners version from github with

remotes::install_github("mlr-org/mlr3extralearners")

and your problem will be fixed

pengjunwe1 commented 7 months ago

@pengjunwe1 please install the latest mlr3extralearners version from github with

remotes::install_github("mlr-org/mlr3extralearners")

and your problem will be fixed

Woo~, issue solved! Thanks