Fair-Seldonian#

Train a model that provably satisfies a fairness constraint — or refuses.

Given a behavioural constraint and a confidence level δ\delta, the Quasi-Seldonian Algorithm (QSA) returns a model satisfying the constraint with probability 1δ\geq 1 - \delta, or returns No Solution Found. It never returns a model it cannot certify.

Never an unsafe model

The safety test runs on data held out from candidate selection, so the guarantee is a genuine high-confidence bound rather than a training-set measurement.

Mathematical Background
Five fairness definitions

Demographic parity, equal opportunity, equalized odds, error rate and error-rate parity — ready to use, or write your own in the constraint domain-specific language (DSL).

Fairness constraints
Tighter bounds

Affine-form compilation roughly halves the slack over interval arithmetic, worth about 4x the data at a fixed confidence level.

Algorithm Variants
Choose your inequality

Hoeffding, empirical Bernstein and betting intervals are distribution-free; Student’s t is available for comparison against the literature.

Concentration Inequalities

Get started#

pip install fair-seldonian
from fair_seldonian import QSA, SeldonianConfig, data_split, demographic_parity, get_data

data = get_data(N=20000, features=5, t_ratio=0.5,
                tp0_ratio=0.4, tp1_ratio=0.6, random_seed=42)
X_te, Y_te, T_te, X_tr, Y_tr, T_tr = data_split(
    frac=0.6, all_data=data, random_state=1, m_test=0.2)

config = SeldonianConfig(constraint=demographic_parity(epsilon=0.2), delta=0.05)
result = QSA(X_tr, Y_tr, T_tr, "opt", None, None, config)

if result.passed_safety:
    print(f"certified: bound <= {result.diagnostics.safety_upper_bound:+.4f}")
else:
    print(f"no solution ({result.diagnostics.failure_mode})")

See also

Quickstart walks through the same example in detail, and Examples has runnable notebooks including one on UCI Adult.