# Compute the Fairness Tensor given a Prediction and a Task

Source:`R/fairness_tensor.R`

`fairness_tensor.Rd`

A fairness tensor is a list of groupwise confusion matrices.

## Usage

```
fairness_tensor(object, normalize = "all", ...)
# S3 method for data.table
fairness_tensor(object, normalize = "all", task, ...)
# S3 method for PredictionClassif
fairness_tensor(object, normalize = "all", task, ...)
# S3 method for ResampleResult
fairness_tensor(object, normalize = "all", ...)
```

## Arguments

- object
(

`data.table()`

| PredictionClassif | ResampleResult)

A data.table with columns`truth`

and`prediction`

, a PredictionClassif or a 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
(TaskClassif)

A TaskClassif. Needs`col_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 `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.3956578 0.0000000
#> 1 0.0257615 0.3882048
#>
#> $Female
#> truth
#> response 0 1
#> 0 0.119896306 0.000000000
#> 1 0.003564485 0.066915100
#>
```