Reweighing to balance disparate impact metric
Source:R/PipeOpReweighing.R
mlr_pipeops_reweighing.Rd
Adjusts class balance and protected group balance in order to achieve fair(er) outcomes.
Format
R6::R6Class object inheriting from mlr3pipelines::PipeOpTaskPreproc/mlr3pipelines::PipeOp.
PipeOpReweighingWeights
Adds a class weight column to the mlr3::Task that different mlr3::Learners
may be using. In case initial weights are present, those are multiplied with new weights.
Caution: Only fairness tasks are supported. Which means tasks need to have protected field.
tsk$col_roles$pta
.
PipeOpReweighingOversampling
Oversamples a mlr3::Task for more balanced ratios in subgroups and protected groups.
Can be used if a learner does not support weights.
Caution: Only fairness tasks are supported. Which means tasks need to have protected field.
tsk$col_roles$pta
.
Construction
id
(character(1)
).param_vals
(list()
)
Input and Output Channels
Input and output channels are inherited from mlr3pipelines::PipeOpTaskPreproc. Instead of a mlr3::Task, a mlr3::TaskClassif is used as input and output during training and prediction.
The output during training is the input mlr3::Task with added weights column according to target class. The output during prediction is the unchanged input.
State
The $state
is a named list
with the $state
elements inherited from mlr3pipelines::PipeOpTaskPreproc.
Parameters
alpha
(numeric()
): A number between 0 (no debiasing) and 1 (full debiasing).
Internals
Introduces, or overwrites, the "weights" column in the mlr3::Task. However, the mlr3::Learner method needs to respect weights for this to have an effect.
The newly introduced column is named reweighing.WEIGHTS
; there will be a naming conflict if this
column already exists and is not a weight column itself.
Fields
Only fields inherited from mlr3pipelines::PipeOpTaskPreproc/mlr3pipelines::PipeOp.
Methods
Methods inherited from mlr3pipelines::PipeOpTaskPreproc/mlr3pipelines::PipeOp.
References
Kamiran, Faisal, Calders, Toon (2012). “Data preprocessing techniques for classification without discrimination.” Knowledge and Information Systems, 33(1), 1–33.
See also
https://mlr3book.mlr-org.com/list-pipeops.html
Other PipeOps:
mlr_pipeops_equalized_odds
,
mlr_pipeops_explicit_pta
Super classes
mlr3pipelines::PipeOp
-> mlr3pipelines::PipeOpTaskPreproc
-> PipeOpReweighingWeights
Methods
Method new()
Creates a new instance of this R6::R6Class R6 class.
Usage
PipeOpReweighingWeights$new(id = "reweighing_wts", param_vals = list())
Arguments
id
character
The PipeOps identifier in the PipeOps library.param_vals
list
The parameter values to be set.alpha: controls the proportion between initial weight (1 if non existing) and reweighing weight. Defaults to 1. Here is how it works: new_weight = (1 - alpha) * 1 + alpha x reweighing_weight final_weight = old_weight * new_weight
Super classes
mlr3pipelines::PipeOp
-> mlr3pipelines::PipeOpTaskPreproc
-> PipeOpReweighingOversampling
Methods
Method new()
Usage
PipeOpReweighingOversampling$new(id = "reweighing_os", param_vals = list())
Examples
library("mlr3")
library("mlr3pipelines")
reweighing = po("reweighing_wts")
learner_po = po("learner", learner = lrn("classif.rpart"))
data = tsk("adult_train")
graph = reweighing %>>% learner_po
glrn = GraphLearner$new(graph)
glrn$train(data)
tem = glrn$predict(data)
tem$confusion
#> truth
#> response <=50K >50K
#> <=50K 21793 3640
#> >50K 1275 4010