reweight: Reweight

Description Usage Arguments Details Value References Examples

View source: R/reweight.R

Description

Function returns weights for model training. The purpose of this weights is to mitigate bias in statistical parity. In fact this could potentially worsen the overall performance in other fairness metrics. This affects also model's performance metrics (accuracy).

Usage

1
reweight(protected, y)

Arguments

protected

factor, protected variables with subgroups as levels (sensitive attributes)

y

numeric, vector with classes 0 and 1, where 1 means favorable class.

Details

Method produces weights for each subgroup for each class. Firstly assumes that protected variable and class are independent and calculates expected probability of this certain event (that subgroup == a and class = c). Than it calculates the actual probability of this event based on empirical data. Finally the weight is quotient of those probabilities

Value

numeric, vector of weights

References

This method was implemented based on Kamiran, Calders 2011 https://link.springer.com/content/pdf/10.1007/s10115-011-0463-8.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
data("german")

data <- german
data$Age <- as.factor(ifelse(data$Age <= 25, "young", "old"))
data$Risk <- as.numeric(data$Risk) -1

# training 2 models
weights <- reweight(protected = data$Age, y = data$Risk)

gbm_model          <- gbm::gbm(Risk ~. , data = data)
gbm_model_weighted <- gbm::gbm(Risk ~. , data = data, weights = weights)

gbm_explainer          <- DALEX::explain(gbm_model, data = data[,-1], y = data$Risk)
gbm_weighted_explainer <- DALEX::explain(gbm_model_weighted, data = data[,-1], y = data$Risk)

fobject <- fairness_check(gbm_explainer, gbm_weighted_explainer,
                          protected = data$Age,
                          privileged = "old",
                          label = c("original","weighted"))
# fairness check
fobject
plot(fobject)

# radar
plot(fairness_radar(fobject))

fairmodels documentation built on May 31, 2021, 5:07 p.m.