Compute the Fairness Tensor given a Prediction and a Task
Source:R/fairness_tensor.R
fairness_tensor.RdA fairness tensor is a list of groupwise confusion matrices.
Usage
fairness_tensor(object, normalize = "all", ...)
# S3 method for class 'data.table'
fairness_tensor(object, normalize = "all", task, ...)
# S3 method for class 'PredictionClassif'
fairness_tensor(object, normalize = "all", task, ...)
# S3 method for class 'ResampleResult'
fairness_tensor(object, normalize = "all", ...)Arguments
- object
(
data.table::data.table()| mlr3::PredictionClassif | mlr3::ResampleResult)
A data.table with columnstruthandprediction, a mlr3::PredictionClassif or a mlr3::ResampleResult.- normalize
(
character)
How should the fairness tensor be normalized? "all" normalizes entries by dividing by dataset size, "group" normalizes entries by dividing by group size and "none" does not conduct any normalization at all.- ...
any
Currently not used.- task
(mlr3::TaskClassif)
A mlr3::TaskClassif. Needscol_role"pta"to be set.
Value
list() of confusion matrix for every group in "pta".
Protected Attributes
The protected attribute is specified as a col_role in the corresponding mlr3::Task():<Task>$col_roles$pta = "name_of_attribute"
This also allows specifying more than one protected attribute,
in which case fairness will be considered on the level of intersecting groups defined by all columns
selected as a predicted attribute.
Examples
library("mlr3")
task = tsk("compas")
prediction = lrn("classif.rpart")$train(task)$predict(task)
fairness_tensor(prediction, task = task)
#> $Male
#> truth
#> response 0 1
#> 0 0.3016850 0.1407971
#> 1 0.1197343 0.2474076
#>
#> $Female
#> truth
#> response 0 1
#> 0 0.09332469 0.02867790
#> 1 0.03013610 0.03823720
#>