Easier access to all plots in fairmodels. Provide plot type (that matches to function name), pass additional parameters and plot.

plot_fairmodels(x, type, ...)

# S3 method for explainer
plot_fairmodels(x, type = "fairness_check", ..., protected, privileged)

# S3 method for fairness_object
plot_fairmodels(x, type = "fairness_check", ...)

# S3 method for default
plot_fairmodels(x, type = "fairness_check", ...)

Arguments

x

object created with fairness_check or with explain

type

character, type of plot. Should match function name in fairmodels. Default is fairness_check.

...

other parameters passed to fairmodels functions.

protected

factor, vector containing sensitive attributes such as gender, race, etc...

privileged

character/factor, level in factor denoting privileged subgroup

Value

ggplot2 object

Details

types (function names) available:

  • fairness_check

  • stack_metrics

  • fairness_heatmap

  • fairness_pca

  • fairness_radar

  • group_metric

  • choose_metric

  • metric_scores

  • performance_and_fairness

  • all_cutoffs

  • ceteris_paribus_cutoff

Examples


data("german")

y_numeric <- as.numeric(german$Risk) - 1

lm_model <- glm(Risk ~ .,
  data = german,
  family = binomial(link = "logit")
)
explainer_lm <- DALEX::explain(lm_model, data = german[, -1], y = y_numeric)
#> Preparation of a new explainer is initiated
#>   -> model label       :  lm  (  default  )
#>   -> data              :  1000  rows  9  cols 
#>   -> target variable   :  1000  values 
#>   -> predict function  :  yhat.glm  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package stats , ver. 4.1.1 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.1369187 , mean =  0.7 , max =  0.9832426  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.9572803 , mean =  1.940006e-17 , max =  0.8283475  
#>   A new explainer has been created!  

# works with explainer when protected and privileged are passed
plot_fairmodels(explainer_lm,
  type = "fairness_radar",
  protected = german$Sex,
  privileged = "male"
)
#> Creating fairness classification object
#> -> Privileged subgroup		: character ( Ok  )
#> -> Protected variable		: factor ( Ok  ) 
#> -> Cutoff values for explainers	: 0.5 ( for all subgroups ) 
#> -> Fairness objects		: 0 objects 
#> -> Checking explainers		: 1 in total (  compatible  )
#> -> Metric calculation		: 13/13 metrics calculated for all models
#>  Fairness object created succesfully  


# or with fairness_object
fobject <- fairness_check(explainer_lm,
  protected = german$Sex,
  privileged = "male"
)
#> Creating fairness classification object
#> -> Privileged subgroup		: character ( Ok  )
#> -> Protected variable		: factor ( Ok  ) 
#> -> Cutoff values for explainers	: 0.5 ( for all subgroups ) 
#> -> Fairness objects		: 0 objects 
#> -> Checking explainers		: 1 in total (  compatible  )
#> -> Metric calculation		: 13/13 metrics calculated for all models
#>  Fairness object created succesfully  

plot_fairmodels(fobject, type = "fairness_radar")