mlr-org / mlr3tuning

Hyperparameter optimization package of the mlr3 ecosystem
https://mlr3tuning.mlr-org.com/
GNU Lesser General Public License v3.0
52 stars 5 forks source link

New error of mlr3tuning::tune() #411

Closed beiwo07 closed 4 months ago

beiwo07 commented 5 months ago

Hi there, I have used the same R script to run my survival analysis successfully. But now it shows error message as below. Is this caused by package updates?

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': non-conformable arguments

Reproducible code:

library(dplyr)
library(tidyverse)
library(survival)
library(mlr3proba)
library(mlr3tuning)
library(mlr3extralearners)
library(glmnet)
library(mlr3)
library(mlr3verse)

df<- survival::rats2
task= as_task_surv(df, time= "time1", event= "status")
alpha_vals<- seq(0,1,0.2)

learner<- lrn("surv.cv_glmnet", 
             alpha= to_tune(c(alpha_vals)))

instance<- mlr3tuning::tune(
  tuner = tnr("grid_search"), 
  task = task, 
  learner = learner, 
  resampling = rsmp("cv", folds=5), 
  measure= msr("surv.cindex")
)

Session Info:

R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

Random number generation:
 RNG:     L'Ecuyer-CMRG 
 Normal:  Inversion 
 Sample:  Rejection 

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mlr3verse_0.2.8         glmnet_4.1-8            Matrix_1.6-5            mlr3extralearners_0.7.0
 [5] mlr3tuning_0.19.2       paradox_0.11.1          mlr3proba_0.5.2         mlr3_0.17.2            
 [9] survival_3.5-7          lubridate_1.9.3         forcats_1.0.0           stringr_1.5.1          
[13] purrr_1.0.2             readr_2.1.5             tidyr_1.3.1             tibble_3.2.1           
[17] ggplot2_3.4.4           tidyverse_2.0.0         dplyr_1.1.4            

loaded via a namespace (and not attached):
 [1] rlang_1.1.3            magrittr_2.0.3         clue_0.3-65            compiler_4.3.0        
 [5] flexmix_2.3-19         vctrs_0.6.5            pkgconfig_2.0.3        shape_1.4.6           
 [9] crayon_1.5.2           fastmap_1.1.1          backports_1.4.1        utf8_1.2.4            
[13] rmarkdown_2.25         tzdb_0.4.0             mlr3cluster_0.1.8      xfun_0.41             
[17] modeltools_0.2-23      cachem_1.0.8           mlr3misc_0.13.0        jsonlite_1.8.8        
[21] uuid_1.2-0             fpc_2.2-11             mlr3fselect_0.11.0     parallel_4.3.0        
[25] prabclus_2.3-3         cluster_2.1.6          R6_2.5.1               bslib_0.6.1           
[29] stringi_1.8.3          parallelly_1.36.0      jquerylib_0.1.4        diptest_0.77-0        
[33] Rcpp_1.0.12            iterators_1.0.14       knitr_1.45             future.apply_1.11.1   
[37] splines_4.3.0          nnet_7.3-19            timechange_0.3.0       tidyselect_1.2.0      
[41] rstudioapi_0.15.0      yaml_2.3.8             mlr3viz_0.7.0          codetools_0.2-19      
[45] param6_0.2.4           listenv_0.9.1          lattice_0.22-5         withr_3.0.0           
[49] evaluate_0.23          future_1.33.1          mclust_6.0.1           kernlab_0.9-32        
[53] pillar_1.9.0           mlr3mbo_0.2.1          mlr3filters_0.7.1      checkmate_2.3.1       
[57] renv_1.0.3             foreach_1.5.2          stats4_4.3.0           generics_0.1.3        
[61] bbotk_0.7.3            hms_1.1.3              munsell_0.5.0          scales_1.3.0          
[65] dictionar6_0.1.3       globals_0.16.2         distr6_1.6.15          class_7.3-22          
[69] RhpcBLASctl_0.23-42    glue_1.7.0             tools_4.3.0            mlr3pipelines_0.5.0-2 
[73] robustbase_0.99-2      data.table_1.14.10     mlr3hyperband_0.4.5    set6_0.2.5            
[77] grid_4.3.0             mlr3data_0.7.0         colorspace_2.1-0       palmerpenguins_0.1.1  
[81] spacefillr_0.3.2       cli_3.6.2              fansi_1.0.6            ooplah_0.2.0          
[85] gtable_0.3.4           DEoptimR_1.1-3         sass_0.4.8             digest_0.6.34         
[89] lgr_0.4.4              htmltools_0.5.7        lifecycle_1.0.4        mlr3learners_0.5.8    
[93] mlr3tuningspaces_0.4.0 MASS_7.3-60.0.1 
beiwo07 commented 5 months ago

Update: I have restored from mlr3tuning_0.19.2 to mlr3tuning_0.19.0 and the code runs successfully again. It seems the error is related to the update?

be-marc commented 4 months ago

Hey, thanks for reporting. Unfortunately, I cannot reproduce the bug with either 0.19.2 or the current main branch. Maybe something went wrong when installing the packages? This code works for me without any problems. The packages are first installed in a clean environment.


renv::init(bare = TRUE)
# restart r
renv::install(c("mlr-org/mlr3proba", "mlr3tuning", "mlr-org/mlr3extralearners", "mlr3", "glmnet"))

library(mlr3proba)
library(mlr3tuning)
library(mlr3extralearners)
library(mlr3)

df = survival::rats2
task= as_task_surv(df, time= "time1", event= "status")
alpha_vals= seq(0,1,0.2)

learner =  lrn("surv.cv_glmnet", 
             alpha= to_tune(c(alpha_vals)))

instance = mlr3tuning::tune(
  tuner = tnr("grid_search"), 
  task = task, 
  learner = learner, 
  resampling = rsmp("cv", folds=5), 
  measure= msr("surv.cindex")
)