Variable importance by "mlr3filters" does not work in "mlr3proba" after preprocessing data with "mlr3pipelines"
Asked Answered
G

0

6

Running the code below using mlr3proba and mlr3pipelines and mlr3filters packages of R to implement rpart algorithm on a preporcessed dataset and performing "variable importance", shows an error:

task <- tsk("iris")

learner <- lrn("classif.rpart")

learner <- po("encode") %>>% po("scale") %>>% po("learner", learner)      # preprocessing

learner <- GraphLearner$new(learner)  #applying learner on a graph in mlr3pipelines

filter <- flt("importance", learner = learner)    #using filter for variable importance

filter$calculate(task)
#Error: 

Error in learner$importance() : attempt to apply non-function 

But when I run the code above, without preprocessing, it works:

task <- tsk("iris")

learner <- lrn("classif.rpart")

filter <- flt("importance", learner = learner)

filter$calculate(task)

as.data.table(filter)
#Results:

        feature     score
1:  Petal.Width  88.96940
2: Petal.Length  81.34496
3: Setal.Length  54.09606
4:  Sepal.Width  36.01309

So, what is wrong?

Gracye answered 4/5, 2021 at 8:32 Comment(2)
Welcome to SO. Five upvotes and no answer in my onion means you probably stumbled on a bug. Perhaps post an issue here: github.com/mlr-org/mlr3pipelines/issues and explain that a GraphLearner tagged with the importance property can not be used to filter features by because it did not inherit the importance extractor from the base learner.Yah
Indeed, a bug / missing functionality. This PR addresses your question: github.com/mlr-org/mlr3/pull/648Zoroaster

© 2022 - 2024 — McMap. All rights reserved.