Search code examples
rdecision-treemlr3

Variable importance not defined in mlr3 rpart learner


I trained and tested a decision tree classifier with mlr3 package in R:

pred_probability = learner_DT$train(task_train)$predict(task_test)

How can I get the variable importance from this model? I tried learner_DT$importance() but the outcome was named numeric(0)

Any help is appreciated.


Solution

  • Your code looks right (you don't need to call $predict() to get the importance, but it doesn't hurt). The documentation of rpart.object states:

    variable.importance: a named numeric vector giving the importance of each variable. (Only present if there are any splits.) When printed by 'summary.rpart' these are rescaled to add to 100.

    So possibly you've fitted a tree without splits (you should see this in the printed output of learner_DT$model).