mlr-org / mlr3pipelines

Dataflow Programming for Machine Learning in R
https://mlr3pipelines.mlr-org.com/
GNU Lesser General Public License v3.0
132 stars 25 forks source link

Spatial resampling in the function 'PipeOpLearnerCV #774

Open marineReg opened 2 months ago

marineReg commented 2 months ago

Hello, I'm trying to modify the function 'PipeOpLearnerCV' to integrate a spatial resampling of type 'sptcv_cstf'. However, I'm getting an error message when I execute:

PipeOpLearnerCV_mod$new(learner = mlr3::lrn("classif.glmnet", predict_type = "prob"), param_vals = list(resampling.method = "sptcv_cstf", resampling.folds = 5))

Error in if (stratify) task$target_names else NULL : argument is of length zero This happened PipeOp classif.glmnet's $train()

Here are my edits in the function:

                              ########################################################################
                              ## My edits
                              private$.crossval_param_set = ps(
                                method = p_fct(levels = c("cv", "insample", "sptcv_cstf", "repeated_sptcv_cstf"), tags = c("train", "required")),
                                folds = p_int(lower = 2L, upper = Inf, tags = c("train", "required")), repeats = p_int(lower = 1L, upper = Inf),
                                keep_response = p_lgl(tags = c("train", "required"))
                              )
                              ########################################

                                ...
                                 if (pv$method == "cv") rdesc$param_set$values = list(folds = pv$folds)
                                ########################################################################
                                ## My edits
                                if (pv$method == "sptcv_cstf") rdesc$param_set$values = list(folds = pv$folds)
                                if (pv$method == "repeated_sptcv_cstf") rdesc$param_set$values = list(folds = pv$folds, repeats = pv$repeats)
                                ########################################################################

Thank you very much for your assistance