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?