mlr-org / mlr3

mlr3: Machine Learning in R - next generation
https://mlr3.mlr-org.com
GNU Lesser General Public License v3.0
906 stars 84 forks source link

Results are not repeatable #1025

Open zhengxingSong opened 1 month ago

zhengxingSong commented 1 month ago

I have an svm-rfe model with a random number seed, but the results are inconsistent after each optimization. How can I modify the code to make my analysis repeatable? This is my code.

set.seed(1234)  
task <- TaskClassif$new(id = "predict", 
                          backend = data,
                          target = "group", 
                          positive = "1")

  optimizer <- fs("rfecv",
                  n_features = 1,      
                  feature_number = 1,    
                  recursive = TRUE)      

  learner <- lrn("classif.svm",
                 type = "C-classification",
                 kernel = "linear",
                 predict_type = "prob")

instance <- fsi(
        task = task,
        learner = learner,
        resampling = rsmp("cv", folds = 10),
        measures = msr("classif.acc"),
        terminator = trm("none"),
        callbacks = clbk("mlr3fselect.svm_rfe")
)

optimizer$optimize(instance)

Thanks!

larskotthoff commented 1 month ago

Hmm, this should work. Can you post a complete example that allows to reproduce the problem please?