ModelOriented / DALEX

moDel Agnostic Language for Exploration and eXplanation
https://dalex.drwhy.ai
GNU General Public License v3.0
1.38k stars 166 forks source link

Issue creating a DALEXtra-explainer with response-type mlr3 learners #549

Closed DominicTheHOST closed 1 year ago

DominicTheHOST commented 1 year ago

I am trying to wrap an mlr3-learner with the predict_type = 'response' with the DALEXtra function explain_mlr3(). Due to mlr3pipelines syntax restrictions, I am unable to change the predict_type to include the probabilities. If I am trying to create the explainer, an error occurs with the prediction function.

library(fairml)
library(mlr3)
library(mlr3misc)
library(DALEX)
library(DALEXtra)
library(tidyverse)
library(titanic)

data("titanic_imputed")

titanic_imputed

titanic_imputed$survived <- as.factor(titanic_imputed$survived)

task_classif <- TaskClassif$new(id = "1", backend = titanic_imputed, target = "survived")

learner_classif <- lrn("classif.rpart", predict_type = "response")

learner_classif$train(task_classif)

explain_mlr3(learner_classif, data = titanic_imputed,
             y = as.numeric(as.character(titanic_imputed$survived))
             )

gives the output

Preparation of a new explainer is initiated
  -> model label       :  R6  (  default  )
  -> data              :  2207  rows  8  cols 
  -> target variable   :  2207  values 
  -> predict function  :  yhat.LearnerClassif  will be used (  default  )
  -> predicted values  :  No value for predict function target column. (  default  )
  -> model_info        :  package mlr3 , ver. 0.14.1 , task classification (  default  ) 
  -> predicted values  :  the predict_function returns an error when executed (  WARNING  ) 
  -> residual function :  difference between y and yhat (  default  )
  -> residuals         :  the residual_function returns an error when executed (  WARNING  ) 
  A new explainer has been created!  

Unfortunately I have been unable to find an example, where this has been adressed. Is there any way to compute the predicted values and the residuals with no access to the probabilities in the model?

hbaniecki commented 1 year ago

Hi @DominicTheHOST, what is the goal of your analysis?

Is there any way to compute the predicted values and the residuals with no access to the probabilities in the model?

Probabilities are the predicted values, so no.

I am trying to wrap an mlr3-learner with the predict_type = 'response' with the DALEXtra function explain_mlr3().

Please note that all explanations are computed using predicted values (probabilities for classification).

DominicTheHOST commented 1 year ago

Thank you @hbaniecki for your quick response!

what is the goal of your analysis? I am working on a project involving mlr3 and shiny for creating and explaining different types of supervised ML-models. I want to create an explainer depending on the users input, wether it be linear regression, random forest etc. For these models, I want to use DALEX to compute feature importance with model_parts, as well as pdp and ALE-plot with model_profile

hbaniecki commented 1 year ago

Sure, so both PD and ALE explain the classifier through probabilities. Permutational feature importance can work without probabilities if you use 1-accuracy loss function.

hbaniecki commented 1 year ago

treating this issue as answered