0

I am currently making an RFE thanks to the mlr3 package following this methodology: https://doi.org/10.3390/rs14215381. When I use the resample function to optimize the random forest parameters based on the new variable selection, the command does not complete and returns the following message: Error in learner$importance() : attempt to apply non-function. See example below thanks to the iris dataset. Am I missing something ? Any help appreciated :).

library(mlr3verse)
library(mlr3filters)
library(mlr3tuning)

rm(list = ls())
data(iris)

task = as_task_regr(x = iris,
                    target = "Petal.Width",
                    positive = T, 
                    data = iris)

resampling_meth = rsmp(.key = "cv", folds = 2)
measure_meth = msr(.key = "regr.rsq")

learner = lrn(
    .key = "regr.ranger",
    importance = "impurity",
    num.threads = 8,
    num.trees = to_tune(500, 1500),
    mtry.ratio = to_tune(0.1, 1), 
    max.depth = to_tune(0, 1500)
)

at = auto_tuner(
    method = mlr3tuning::tnr(.key = "grid_search", 
                             resolution = 4),
    learner = learner,
    resampling = resampling_meth,
    measure = measure_meth, 
    store_tuning_instance = F, 
    store_benchmark_result = F,
    store_models = F, 
    check_values = F
)
# Auto selector for var importance with auto_tuner integrated
afs = auto_fselector(
    method = fs(.key = "rfe", recursive = T, feature_number = 1),
    learner = at,
    resampling = resampling_meth,
    measure = measure_meth,
    store_fselect_instance = F, 
    check_values = F
)

rr = resample(
    task = task,
    learner = afs,
    resampling = resampling_meth,
    store_models = F,
    store_backends = F,
    allow_hotstart = F
)
#> Error in learner$importance(): attempt to apply non-function

<sup>Created on 2022-11-09 with reprex v2.0.2</sup>

0 Answers0