mayer79 / flashlight

Machine learning explanations
https://mayer79.github.io/flashlight/
GNU General Public License v2.0
22 stars 4 forks source link

Not compatible with mlr pakage #34

Closed vijay2492 closed 4 years ago

vijay2492 commented 4 years ago

light_importance function for permutation variable importance is not working with models built using mlr pipeline.

Decision Tree Model from Rpart
fl_rpart <- flashlight(model = dt_model, data = train, y = "x1", label = "rpart", metrics = list(auc = AUC), predict_function = function(mod, X) predict(mod, X)[,2])

imp_rpart <- light_importance(fl_rpart, m_repetitions = 5)

works as expected, but when i build same model on same dataset using mlr package -

fl_rpart_mlr <- flashlight(model = dt_model_mlr, data = train, y = "x1", label = "rpart_mlr", metrics = list(auc = AUC), predict_function = function(model, newdata) predict(model, newdata = train)$data$prob.1)

imp_rpart_mlr <- light_importance(fl_rpart_mlr, m_repetitions = 5)

I get importance of all the variables = 0.

I checked that output of predict_function is both the cases is same.

Can you highlight, if i am doing something wrong or the package can't be used with mlr models?

vijay2492 commented 4 years ago

For mlr models, create the flashlight like below -

fl_rpart_mlr <- flashlight(model = dt_model_mlr, data = train, y = "x1", label = "rpart_mlr", metrics = list(auc = AUC), 
predict_function = function(mod, X) predict(model = mod, newdata =X)$data$prob.1)