mlr-org / mlr3pipelines

Dataflow Programming for Machine Learning in R
https://mlr3pipelines.mlr-org.com/
GNU Lesser General Public License v3.0
140 stars 25 forks source link

Variable importance by "mlr3filters" does not work in "mlr3proba" after preprocessing data with "mlr3pipelines" #579

Open The-Killbill opened 3 years ago

The-Killbill commented 3 years ago

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
adibender commented 3 years ago

I think this is a more general issue: https://github.com/mlr-org/mlr3pipelines/issues/291

mb706 commented 3 years ago

I will address #291 within the next three weeks.

HongxiangXu commented 2 years ago

Have the problem fixed? I still get the same problem.