Skip to content

DDecisions · fairness.threshold

Fair decision thresholds (post-processing)

Which group-specific thresholds keep decisions fair at the lowest cost in errors?

Chooses a (possibly randomized) score threshold for each group that minimizes expected cost — errors, or a cost per false positive and false negative — subject to demographic parity, equal opportunity or equalized odds within a tolerance, and an optional capacity (largest share selected): the post-processing of Hardt, Price & Srebro (2016), as in Fairlearn's ThresholdOptimizer. Shows what fairness costs against each group's own best threshold and a single shared threshold.

Verified in Python and R Python and R agree to 6 decimals

A real result

Example “Parity exact”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Fair decision thresholdsRecorded · Python and R agreeRecorded 2026-11-17 · 24 values compared
R

Under demographic parity, the best group thresholds give an expected errors of 0.303 per decision, against 0.291 when each group gets its own best threshold and 0.318 for one threshold of 0.5. Selection rates after: A 64.8%, B 64.8%, C 64.8%.

Expected errors per decision (fair)
0.3026
Each group's own best
0.2905
One threshold (0.5)
0.3176

Plots

Rates by group: one threshold vs fair thresholdsDo a model's decisions or error rates differ across groups, and by how much?
View data
groupMetricRate
ASelection (one threshold)0.5756
ASelection (fair)0.6481
ATPR (one threshold)0.7336
ATPR (fair)0.8107
BSelection (one threshold)0.3720
BSelection (fair)0.6481
BTPR (one threshold)0.5161
BTPR (fair)0.8086
CSelection (one threshold)0.6605
CSelection (fair)0.6481
CTPR (one threshold)0.8000
CTPR (fair)0.8000

Decision rule per group

groupnRuleSelection rateTPRFPRAccuracySelection at 0.5TPR at 0.5
A476score ≥ 0.495; 0.391 ≤ score < 0.495 selected with probability 0.46164.8%81.1%42.8%71.0%57.6%73.4%
B250score ≥ 0.32; 0.218 ≤ score < 0.32 selected with probability 0.55164.8%80.9%49.0%65.8%37.2%51.6%
C162score ≥ 0.53164.8%80.0%40.3%72.2%66.0%80.0%

Disparities before and after

MetricOne threshold (0.5)Fair thresholds
Demographic parity difference0.28850
Equal opportunity difference (TPR)0.28390.0107
False-positive rate difference0.20530.0870
  • 12 of 900 rows were left out because a value was missing.
  • Cost per decision = (1 × false negatives + 1 × false positives) / n, expected over the randomization. Solved exactly over the lower convex hull of each group's operating points.
  • Group-specific thresholds use the group attribute at decision time; check that this is lawful and acceptable for your decision before using them.
Python

Under demographic parity, the best group thresholds give an expected errors of 0.303 per decision, against 0.291 when each group gets its own best threshold and 0.318 for one threshold of 0.5. Selection rates after: A 64.8%, B 64.8%, C 64.8%.

Expected errors per decision (fair)
0.3026
Each group's own best
0.2905
One threshold (0.5)
0.3176

To keep this page light, the plots are shown once, under the R tab.

Decision rule per group

groupnRuleSelection rateTPRFPRAccuracySelection at 0.5TPR at 0.5
A476score ≥ 0.495; 0.391 ≤ score < 0.495 selected with probability 0.46164.8%81.1%42.8%71.0%57.6%73.4%
B250score ≥ 0.32; 0.218 ≤ score < 0.32 selected with probability 0.55164.8%80.9%49.0%65.8%37.2%51.6%
C162score ≥ 0.53164.8%80.0%40.3%72.2%66.0%80.0%

Disparities before and after

MetricOne threshold (0.5)Fair thresholds
Demographic parity difference0.28850
Equal opportunity difference (TPR)0.28390.0107
False-positive rate difference0.20530.0870
  • 12 of 900 rows were left out because a value was missing.
  • Cost per decision = (1 × false negatives + 1 × false positives) / n, expected over the randomization. Solved exactly over the lower convex hull of each group's operating points.
  • Group-specific thresholds use the group attribute at decision time; check that this is lawful and acceptable for your decision before using them.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Parity exacto2_credit · group: group · outcome: repaid · score: score
  • Opportunity costso2_credit · group: age band · outcome: repaid · score: score
  • Odds lpo2_credit · group: group · outcome: repaid · score: score
  • Parity capacity lpo2_credit · group: group · outcome: repaid · score: score

In the guides

Where it sits in the decision guides

  • Constrained optimization (risk, fairness, cost) · DS & ML Decision Guide · Optimize / decide

What you need

Group (sensitive attribute)categorical / boolean · 1 column · 2–50 levels
The sensitive attribute (for example, sex or age band) whose groups should be treated fairly.
True outcomeboolean / categorical / numeric · 1 column · 2–2 levels
The real outcome (numeric outcomes must be 0/1).
Scorenumeric · 1 column
Higher score = more likely positive (e.g. a predicted probability).

Choices you make

options

Fairness constraintdefault demographic_parity

What fairness means here: equal selection rates, equal true-positive rates, or equal TPR and FPR across groups.

  • Demographic parity (equal selection rates)(default) — Makes selection rates match across groups; pick it when the decision should be shared evenly, whatever the base rates.
  • Equal opportunity (equal true-positive rates) — Makes true-positive rates match, so real positives are found equally often; pick it when missing one is the main harm.
  • Equalized odds (equal TPR and FPR) — Makes true- and false-positive rates both match; the strictest of the three and usually the costliest.
  • None (each group's own best threshold) — Picks each group's best threshold with no fairness constraint; use it as the baseline to compare against.
Allowed differencedefault 0

Each group's rate may differ from the shared rate by up to this much.

Cost of a false positivedefault 1

Cost of a false positive relative to a false negative (cost 1). Used to pick thresholds.

Cost of a false negativedefault 1

Equal costs minimize errors (maximize accuracy).

Capacity (largest share selected)default —

Largest share of people that may be selected (for example, limited places). Empty means no limit.

Shared threshold for comparisondefault 0.5

Single shared threshold shown for comparison with the group thresholds.

Positive outcomedefault —

The outcome level that counts as positive (for example, 'approved').

What it reports

cost
How much decision cost rises when you add a fairness constraint, compared with the best unconstrained thresholds.
cost_unconstrained
How much decision cost rises when you add a fairness constraint, compared with the best unconstrained thresholds.
cost_baseline
How much decision cost rises when you add a fairness constraint, compared with the best unconstrained thresholds.
solver
How the fair thresholds were found: exact (a search over each group's ROC hull) or lp (a linear program).
n
How many independent units the analysis used; it sets precision and power.

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-9). Python uses numpy, pandas, scipy, codesplash; R uses stats, nanoparquet, highs, codesplashr.

Default traps between the two languages

  • Demographic parity and equal opportunity without a capacity are solved exactly (lower convex hull of each group's operating points; smallest shared rate on ties), identical in both engines.
  • Equalized odds and capacity constraints solve one linear program with HiGHS (scipy's bundled build vs the R highs package); rates and cost agree to the solver tolerance, and the mixture of thresholds can differ when the optimum is not unique (only rates and costs are compared).
Python

The exact script CodeSplash ran for example “Parity exact” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Fair decision thresholds (post-processing)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method fairness.threshold 1.0.1 · spec 075c92e5d6ac479a
# Dataset: o2_credit (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.decide import fairness  # twin of codesplashr::cs_fair_thresholds (exact hull search; HiGHS LP)

# %% Data
df = pd.read_parquet("tests/parity/fixtures/o2_credit.parquet", columns=["group", "repaid", "score"])
n_input = len(df)
df["group"] = pd.Categorical(df["group"], categories=["A", "B", "C"])  # stored level order
df["repaid"] = pd.Categorical(df["repaid"], categories=["false", "true"])  # stored level order
df = df.dropna(subset=["group", "repaid", "score"])  # listwise deletion over the analysis columns
df["group"] = df["group"].cat.remove_unused_categories()
df["repaid"] = df["repaid"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["group", "repaid", "score"])  # infinite values stop the run (registry/errors.yaml)

# %% Inputs
g_col, y_col, s_col = "group", "repaid", "score"
constraint = "demographic_parity"
tolerance = 0
cost_fp, cost_fn = 1, 1
capacity = None  # None = no limit
baseline = 0.5
group_levels = [str(x) for x in df[g_col].cat.categories]
group = df[g_col].astype(str).to_numpy()
score = df[s_col].to_numpy(dtype=float)
if isinstance(df[y_col].dtype, pd.CategoricalDtype):
    ycats = [str(x) for x in df[y_col].cat.categories]
    y_pos = ycats[-1]  # default: the second stored level
    y = (df[y_col].astype(str) == y_pos).to_numpy(dtype=float)
else:
    y = df[y_col].to_numpy(dtype=float)
    if not np.isin(y, [0.0, 1.0]).all():
        raise ValueError(f"{y_col} must be 0/1 (or yes/no).")
n = len(y)

# %% Thresholds
fair = fairness.thresholds(group, y, score, group_levels, constraint, cost_fp=cost_fp, cost_fn=cost_fn, capacity=capacity, tolerance=tolerance)
free = fairness.thresholds(group, y, score, group_levels, "none", cost_fp=cost_fp, cost_fn=cost_fn)
levels = fair["levels"]
# A single shared threshold for comparison.
pred0 = (score >= baseline).astype(float)
cost_baseline = float((cost_fn * ((pred0 == 0) & (y == 1)) + cost_fp * ((pred0 == 1) & (y == 0))).sum() / n)
base = fairness.group_metrics(group, pred0, y, None, levels, boot=0)
after_disp = fairness.disparities({lv: {k: fair["groups"][lv][k] for k in ("selection", "tpr", "fpr", "accuracy")} | {"ppv": float("nan")} for lv in levels})


def rule(mixture):
    pts = [(t, w) for t, w in mixture if w > 0]
    if len(pts) == 1:
        t = pts[0][0]
        return "nobody selected" if np.isinf(t) else f"score ≥ {t:g}"
    if len(pts) == 2:
        (t_hi, _), (t_lo, w_lo) = sorted(pts, key=lambda p: -p[0])
        hi_text = "nobody for sure" if np.isinf(t_hi) else f"score ≥ {t_hi:g}"
        return f"{hi_text}; {t_lo:g} ≤ score < {t_hi:g} selected with probability {w_lo:.3f}" if not np.isinf(t_hi) else f"score ≥ {t_lo:g} selected with probability {w_lo:.3f}"
    return "randomized mixture of " + ", ".join(f"score ≥ {t:g} (weight {w:.3f})" for t, w in pts)


# %% Result
labels = {"demographic_parity": "demographic parity", "equal_opportunity": "equal opportunity", "equalized_odds": "equalized odds", "none": "no constraint"}
unit = "errors" if cost_fp == cost_fn == 1 else "cost"
summary = (
    f"Under {labels[constraint]}" + (f" (± {tolerance:g})" if tolerance else "") + (f" with at most {capacity:.0%} selected" if capacity is not None else "")
    + f", the best group thresholds give an expected {unit} of {fair['cost']:.3f} per decision, against {free['cost']:.3f} when each group gets its own best "
    f"threshold and {cost_baseline:.3f} for one threshold of {baseline:g}. Selection rates after: "
    + ", ".join(f"{lv} {fair['groups'][lv]['selection']:.1%}" for lv in levels) + "."
)
rows = []
values = {"cost": fair["cost"], "cost_unconstrained": free["cost"], "cost_baseline": cost_baseline, "price_of_fairness": fair["cost"] - free["cost"],
          "solver": fair["solver"], "n": n}
for lv in levels:
    a, b = fair["groups"][lv], base["groups"][lv]
    rows.append({"group": lv, "n": a["n"], "rule": rule(a["mixture"]), "selection": a["selection"], "tpr": a["tpr"], "fpr": a["fpr"],
                 "accuracy": a["accuracy"], "selection_before": b["selection"], "tpr_before": b["tpr"]})
    for k in ("selection", "tpr", "fpr", "accuracy"):
        values[f"{k}[{lv}]"] = a[k]
for k in ("dp_diff", "eop_diff", "fpr_diff"):
    values[f"{k}_after"] = after_disp[k]
    values[f"{k}_before"] = base["disparities"][k]
cs.publish({
    "method": "fairness.threshold",
    "methodVersion": "1.0.1",
    "title": "Fair decision thresholds",
    "engine": cs.engine_info("numpy", "pandas", "scipy"),
    "n": n,
    "summary": summary,
    "statistics": [
        {"key": "cost", "label": f"Expected {unit} per decision (fair)", "value": fair["cost"]},
        {"key": "cost_unconstrained", "label": "Each group's own best", "value": free["cost"]},
        {"key": "cost_baseline", "label": f"One threshold ({baseline:g})", "value": cost_baseline},
    ],
    "tables": [
        {"key": "thresholds", "title": "Decision rule per group",
         "columns": [{"key": "group", "label": g_col, "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
                     {"key": "rule", "label": "Rule", "type": "string"}, {"key": "selection", "label": "Selection rate", "type": "percent"},
                     {"key": "tpr", "label": "TPR", "type": "percent"}, {"key": "fpr", "label": "FPR", "type": "percent"},
                     {"key": "accuracy", "label": "Accuracy", "type": "percent"}, {"key": "selection_before", "label": f"Selection at {baseline:g}", "type": "percent"},
                     {"key": "tpr_before", "label": f"TPR at {baseline:g}", "type": "percent"}],
         "rows": rows},
        {"key": "disparities", "title": "Disparities before and after",
         "columns": [{"key": "metric", "label": "Metric", "type": "string"}, {"key": "before", "label": f"One threshold ({baseline:g})", "type": "number"},
                     {"key": "after", "label": "Fair thresholds", "type": "number"}],
         "rows": [{"metric": "Demographic parity difference", "before": base["disparities"]["dp_diff"], "after": after_disp["dp_diff"]},
                  {"metric": "Equal opportunity difference (TPR)", "before": base["disparities"]["eop_diff"], "after": after_disp["eop_diff"]},
                  {"metric": "False-positive rate difference", "before": base["disparities"]["fpr_diff"], "after": after_disp["fpr_diff"]}]},
    ],
    "warnings": warnings,
    "notes": [
        f"Cost per decision = ({cost_fn:g} × false negatives + {cost_fp:g} × false positives) / n, expected over the randomization. "
        + ("Solved exactly over the lower convex hull of each group's operating points." if fair["solver"] == "exact" else "Solved as a linear program (HiGHS)."),
        "Group-specific thresholds use the group attribute at decision time; check that this is lawful and acceptable for your decision before using them.",
    ],
    "values": values,
    "charts": [
        cs.chart("rates", "group-metrics", f"Rates by {g_col}: one threshold vs fair thresholds", {
            "group": cs.col(g_col, [lv for lv in levels for _ in range(4)], levels=levels),
            "metric": cs.col("Metric", [m for _ in levels for m in ("Selection (one threshold)", "Selection (fair)", "TPR (one threshold)", "TPR (fair)")],
                             levels=["Selection (one threshold)", "Selection (fair)", "TPR (one threshold)", "TPR (fair)"]),
            "value": cs.col("Rate", [v for lv in levels for v in (base["groups"][lv]["selection"], fair["groups"][lv]["selection"],
                                                                  base["groups"][lv]["tpr"], fair["groups"][lv]["tpr"])]),
        }, controls={"reference": None, "band_low": 0, "band_high": 0}),
    ],
})
R

The exact script CodeSplash ran for example “Parity exact” · R version 4.5.1 (2025-06-13)

# Fair decision thresholds (post-processing)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method fairness.threshold 1.0.1 · spec 075c92e5d6ac479a
# Dataset: o2_credit (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_fair_thresholds(): twin of codesplash.decide.fairness (exact hull search; HiGHS LP via the highs package)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/o2_credit.parquet", col_select = c("group", "repaid", "score")))
n_input <- nrow(df)
df[["group"]] <- factor(df[["group"]], levels = c("A", "B", "C"))  # stored level order
df[["repaid"]] <- factor(df[["repaid"]], levels = c("false", "true"))  # stored level order
df <- df[stats::complete.cases(df[c("group", "repaid", "score")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("group", "repaid", "score"))  # infinite values stop the run (registry/errors.yaml)

# %% Inputs
g_col <- "group"
y_col <- "repaid"
s_col <- "score"
constraint <- "demographic_parity"
tolerance <- 0
cost_fp <- 1
cost_fn <- 1
capacity <- NULL # NULL = no limit
baseline <- 0.5
group_levels <- levels(df[[g_col]])
group <- as.character(df[[g_col]])
score <- as.numeric(df[[s_col]])
if (is.factor(df[[y_col]])) {
  ycats <- levels(df[[y_col]])
  y_pos <- ycats[length(ycats)] # default: the second stored level
  y <- as.numeric(as.character(df[[y_col]]) == y_pos)
} else {
  y <- as.numeric(df[[y_col]])
  if (!all(y %in% c(0, 1))) stop(sprintf("%s must be 0/1 (or yes/no).", y_col))
}
n <- length(y)

# %% Thresholds
fair <- cs_fair_thresholds(group, y, score, group_levels, constraint, cost_fp = cost_fp, cost_fn = cost_fn, capacity = capacity, tolerance = tolerance)
free <- cs_fair_thresholds(group, y, score, group_levels, "none", cost_fp = cost_fp, cost_fn = cost_fn)
lv_all <- fair$levels
# A single shared threshold for comparison.
pred0 <- as.numeric(score >= baseline)
cost_baseline <- sum(cost_fn * (pred0 == 0 & y == 1) + cost_fp * (pred0 == 1 & y == 0)) / n
base <- cs_fair_group_metrics(group, pred0, y, NULL, lv_all, boot = 0)
after_disp <- cs_fair_disparities(lapply(stats::setNames(lv_all, lv_all), function(lv) {
  a <- fair$groups[[lv]]
  list(selection = a$selection, tpr = a$tpr, fpr = a$fpr, accuracy = a$accuracy, ppv = NaN)
}))

rule <- function(mixture) {
  pts <- Filter(function(p) p[2] > 0, mixture)
  if (length(pts) == 1) {
    t <- pts[[1]][1]
    return(if (is.infinite(t)) "nobody selected" else sprintf("score ≥ %s", format(t)))
  }
  if (length(pts) == 2) {
    o <- pts[order(-vapply(pts, function(p) p[1], numeric(1)))]
    t_hi <- o[[1]][1]
    t_lo <- o[[2]][1]
    w_lo <- o[[2]][2]
    if (is.infinite(t_hi)) return(sprintf("score ≥ %s selected with probability %.3f", format(t_lo), w_lo))
    return(sprintf("score ≥ %s; %s ≤ score < %s selected with probability %.3f", format(t_hi), format(t_lo), format(t_hi), w_lo))
  }
  paste("randomized mixture of", paste(vapply(pts, function(p) sprintf("score ≥ %s (weight %.3f)", format(p[1]), p[2]), ""), collapse = ", "))
}

# %% Result
labels <- c(demographic_parity = "demographic parity", equal_opportunity = "equal opportunity", equalized_odds = "equalized odds", none = "no constraint")
unit <- if (cost_fp == 1 && cost_fn == 1) "errors" else "cost"
summary <- paste0(
  "Under ", labels[[constraint]], if (tolerance > 0) sprintf(" (± %s)", format(tolerance)) else "",
  if (!is.null(capacity)) sprintf(" with at most %.0f%% selected", 100 * capacity) else "",
  sprintf(", the best group thresholds give an expected %s of %.3f per decision, against %.3f when each group gets its own best threshold and %.3f for one threshold of %s. Selection rates after: ",
          unit, fair$cost, free$cost, cost_baseline, format(baseline)),
  paste(vapply(lv_all, function(lv) sprintf("%s %.1f%%", lv, 100 * fair$groups[[lv]]$selection), ""), collapse = ", "), "."
)
values <- list(cost = fair$cost, cost_unconstrained = free$cost, cost_baseline = cost_baseline, price_of_fairness = fair$cost - free$cost,
               solver = fair$solver, n = n)
rows <- do.call(rbind, lapply(lv_all, function(lv) {
  a <- fair$groups[[lv]]
  b <- base$groups[[lv]]
  data.frame(group = lv, n = a$n, rule = rule(a$mixture), selection = a$selection, tpr = a$tpr, fpr = a$fpr, accuracy = a$accuracy,
             selection_before = b$selection, tpr_before = b$tpr)
}))
for (lv in lv_all) for (k in c("selection", "tpr", "fpr", "accuracy")) values[[sprintf("%s[%s]", k, lv)]] <- fair$groups[[lv]][[k]]
for (k in c("dp_diff", "eop_diff", "fpr_diff")) {
  values[[paste0(k, "_after")]] <- after_disp[[k]]
  values[[paste0(k, "_before")]] <- base$disparities[[k]]
}
metric_names <- c("Selection (one threshold)", "Selection (fair)", "TPR (one threshold)", "TPR (fair)")
cs_publish(list(
  method = "fairness.threshold",
  methodVersion = "1.0.1",
  title = "Fair decision thresholds",
  engine = cs_engine_info("stats", "highs", "codesplashr"),
  n = n,
  summary = summary,
  statistics = list(
    list(key = "cost", label = sprintf("Expected %s per decision (fair)", unit), value = fair$cost),
    list(key = "cost_unconstrained", label = "Each group's own best", value = free$cost),
    list(key = "cost_baseline", label = sprintf("One threshold (%s)", format(baseline)), value = cost_baseline)
  ),
  tables = list(
    list(key = "thresholds", title = "Decision rule per group",
         columns = list(list(key = "group", label = g_col, type = "string"), list(key = "n", label = "n", type = "integer"),
                        list(key = "rule", label = "Rule", type = "string"), list(key = "selection", label = "Selection rate", type = "percent"),
                        list(key = "tpr", label = "TPR", type = "percent"), list(key = "fpr", label = "FPR", type = "percent"),
                        list(key = "accuracy", label = "Accuracy", type = "percent"),
                        list(key = "selection_before", label = sprintf("Selection at %s", format(baseline)), type = "percent"),
                        list(key = "tpr_before", label = sprintf("TPR at %s", format(baseline)), type = "percent")),
         rows = rows),
    list(key = "disparities", title = "Disparities before and after",
         columns = list(list(key = "metric", label = "Metric", type = "string"), list(key = "before", label = sprintf("One threshold (%s)", format(baseline)), type = "number"),
                        list(key = "after", label = "Fair thresholds", type = "number")),
         rows = data.frame(metric = c("Demographic parity difference", "Equal opportunity difference (TPR)", "False-positive rate difference"),
                           before = c(base$disparities$dp_diff, base$disparities$eop_diff, base$disparities$fpr_diff),
                           after = c(after_disp$dp_diff, after_disp$eop_diff, after_disp$fpr_diff)))
  ),
  warnings = warnings,
  notes = list(
    paste0(sprintf("Cost per decision = (%s × false negatives + %s × false positives) / n, expected over the randomization. ", format(cost_fn), format(cost_fp)),
           if (fair$solver == "exact") "Solved exactly over the lower convex hull of each group's operating points." else "Solved as a linear program (HiGHS)."),
    "Group-specific thresholds use the group attribute at decision time; check that this is lawful and acceptable for your decision before using them."
  ),
  values = values,
  charts = list(cs_chart("rates", "group-metrics", sprintf("Rates by %s: one threshold vs fair thresholds", g_col), list(
    group = cs_col(g_col, rep(lv_all, each = 4), levels = lv_all),
    metric = cs_col("Metric", rep(metric_names, times = length(lv_all)), levels = metric_names),
    value = cs_col("Rate", unlist(lapply(lv_all, function(lv) c(base$groups[[lv]]$selection, fair$groups[[lv]]$selection,
                                                                   base$groups[[lv]]$tpr, fair$groups[[lv]]$tpr))))
  ), controls = list(reference = NA, band_low = 0, band_high = 0)))
))

Sources

  • Hardt, M., Price, E., & Srebro, N. (2016). Equality of opportunity in supervised learning. NeurIPS, 3315–3323.
  • Bird, S., et al. (2020). Fairlearn: A toolkit for assessing and improving fairness in AI. Microsoft Technical Report MSR-TR-2020-32.
  • Huangfu, Q., & Hall, J. A. J. (2018). Parallelizing the dual revised simplex method. Mathematical Programming Computation, 10, 119–142.

From the CodeSplash method registry · fairness.threshold v1.0.1.