I am tuning parameters for multiple learners using parallel computing. However, I am encountering this error message for the learner ‘classif.svm
‘:
<simpleError: '<OptimizerMbo>' does not support param sets with dependencies!>
I don’t understand why I am receiving this error message because there doesn’t seem to be any dependency according to this command:
> learner_svm$param_set$values
$type
[1] "C-classification"
$cost
Tuning over:
range [1e-04, 10000] (log scale)
$kernel
Tuning over:
p_fct(levels = c("polynomial", "radial", "sigmoid", "linear"))
$degree
Tuning over:
range [2, 5]
$gamma
Tuning over:
range [1e-04, 10000] (log scale)
Why am I encountering this issue? But then again, is this normal because in the book, it is noted that SVM models have dependencies?
Here is an example to reproduce this problem. I have ten different learners, but to speed things up, I’m only using two of them:
library(mlr3)
library(mlr3learners)
library(mlr3verse)
library(mlr3spatial)
library(mlr3spatiotempcv)
library(mlr3tuning)
library(mlr3pipelines)
data <- data.frame(ID = 1:1742, x = runif(1742, -130.88, -61.12), y = runif(1742, 12.12, 61.38), year = runif(1742, 2005, 2020), presence = rep(0:1, each=871),
V1 = runif(1742, -3.66247, 2.95120), V2 = runif(1742, -1.6501, 7.5510))
## head(data)
data$presence <- as.factor(data$presence)
classification_task_sp <- mlr3spatial::as_task_classif_st(x = data, target = response, positive = "1", coordinate_names = c("x", "y"), crs = "+proj=longlat +datum=WGS84 +no_defs +type=crs")
classification_task_sp$set_col_roles(ID, roles = "space")
classification_task_sp$set_col_roles(year, roles = "time")
learner_glmnet <- mlr3tuningspaces::lts(mlr3::lrn("classif.glmnet", predict_type = "prob"))
learner_svm <- mlr3tuningspaces::lts(mlr3::lrn("classif.svm", predict_type = "prob", type = "C-classification"))
learners <- c(learner_glmnet, learner_glmnet, learner_glmnet, learner_glmnet, learner_glmnet, learner_glmnet, learner_svm)
inner_resampling <- mlr3::rsmp("sptcv_cstf", folds = 2)
measures <- c(mlr3::msr("classif.sensitivity"), mlr3::msr("classif.specificity"), mlr3::msr("classif.acc"))
tuner <- mlr3tuning:::tnr("mbo")
cl <- parallel::makeCluster(4, outfile = "test.txt")
doSNOW::registerDoSNOW(cl)
tuned_hyperparameter_list <- foreach::foreach(learner_ID = 1:length(learners), .errorhandling = "pass", .packages = c("dplyr")) %dopar% {
set.seed(1)
tuning_instance <- mlr3tuning::ti(task = task,
learner = learners[[learner_ID]],
resampling = inner_resampling,
measures = measures,
terminator = mlr3tuning::trm("evals", n_evals = 1))
## Run the tuning process
tuner$optimize(tuning_instance)
df <- data.frame(tuning_instance$result)
## print(df)
## Return a data frame
return(df)
}
parallel::stopCluster(cl)