mlr3

How to tune kernel.pars of surv.svm in mlr3


For survival SVM model, different kernel has different parameters, for example, the kernel "poly_kernel"(polynomial) has the degree parameter, but it is included in the kernel.pars argument. Then how can I tune the degree? Also, how can I tune degree and kernel together?

Thank you very much.


Solution

  • I can only find little information about the kernel.pars parameter in the documentation of survivalsvm::survivalsvm(). According to the documentation, kernel.pars should be a vector of length 1. The code of survivalsvm does not work if kernel.pars is longer than 1. However, if the kernel is set to poly_kernel, a second element is accessed here. Probably the degree parameter. So I can't get survivalsvm to run with poly_kernel. Maybe you have to ask the maintainer. On the mlr3 side you have to use a transformation function to use such special parameters. Here you can find more information.

    library(mlr3tuning)
    library(mlr3extralearners)
    library(mlr3proba)
    
    search_space = ps(
        kernel = p_fct(c("lin_kernel", "poly_kernel")),
        degree = p_int(lower = 2, upper = 5, depends = kernel == "poly_kernel"),
        gamma = p_dbl(lower = 1e-4, upper = 1e4, depends = kernel == "poly_kernel"),
        .extra_trafo = function(x, param_set) {
            if (x$kernel == "poly_kernel") {
            x$kernel.pars = c(x$gamma, x$degree)
            x$degree = NULL
            x$gamma = NULL
            }
            x
      }
    )
    
    # hyperparameter configs on the tuner side
    design = paradox::generate_design_random(search_space, n = 10)
    design
    
    # hyperparameter configs on the learner side
    design$transpose()
    
    # tuning
    instance = tune(
        tuner = tnr("random_search"),
        task = tsk("rats"),
        learner = lrn("surv.svm", gamma.mu = 1),
        resampling = rsmp("cv", folds = 3),
        terminator = trm("evals", n_evals = 20),
        search_space = search_space
    )