PhilippPro / tuneRanger

Automatic tuning of random forests
32 stars 9 forks source link

Model cannot be tuned while forcing variables in the model #13

Open sibipx opened 7 months ago

sibipx commented 7 months ago

Hi! I want to tune a model while forcing a variable in the model using always.split.variables.

It would also be nice to be able to specify bounds for the tuned parameters. Probably specifying upper bound for mtry at number of variables minus one would fix the problem.

Thanks!

library(ranger)
library(tuneRanger)
data("iris")

measure <- list(multiclass.brier)
task <- makeClassifTask(data = iris,
                        target = "Species")

parameters <- list(respect.unordered.factors = "order",
                   replace = TRUE,
                   always.split.variables = c("Sepal.Length"),
                   importance = "none")

res <- tuneRanger(task, measure = measure,
                  num.trees = 100,
                  show.info = TRUE,
                  tune.parameters = c("mtry", "min.node.size"),
                  parameters = parameters,
                  build.final.model = FALSE)

Computing y column(s) for design. Not provided.
Error: Number of variables to be always considered for splitting plus mtry cannot be larger than number of independent variables. Ranger will EXIT now.
Error in ranger::ranger(formula = NULL, dependent.variable.name = tn,  : 
  User interrupt or internal error.
PhilippPro commented 1 month ago

This would be possible by adjusting the tuneRanger function here: https://github.com/PhilippPro/tuneRanger/blob/master/R/tuneRanger.R

It is not so hard, so if you want and if you have time, give it a try and make a pull request here.