data(hpc_cv)
# `demographic_parity`, among other fairness metrics,
# is generated with `new_groupwise_metric()`:
diff_range <- function(x) {diff(range(x$.estimate))}
demographic_parity_ <-
new_groupwise_metric(
fn = detection_prevalence,
name = "demographic_parity",
aggregate = diff_range
)
m_set <- metric_set(demographic_parity_(Resample))
m_set(hpc_cv, truth = obs, estimate = pred)
# the `post` argument can be used to accommodate a wide
# variety of parameterizations. to encode demographic
# parity as a ratio inside of a difference, for example:
ratio_range <- function(x, ...) {
range <- range(x$.estimate)
range[1] / range[2]
}
demographic_parity_ratio <-
new_groupwise_metric(
fn = detection_prevalence,
name = "demographic_parity_ratio",
aggregate = ratio_range
)
Run the code above in your browser using DataLab