Fair-Seldonian#
Train a model that provably satisfies a fairness constraint — or refuses.
Given a behavioural constraint and a confidence level , the Quasi-Seldonian Algorithm (QSA) returns a model satisfying the constraint with probability , or returns No Solution Found. It never returns a model it cannot certify.
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.
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).
Affine-form compilation roughly halves the slack over interval arithmetic, worth about 4x the data at a fixed confidence level.
Hoeffding, empirical Bernstein and betting intervals are distribution-free; Student’s t is available for comparison against the literature.
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.
Repository |
|
Python |
3.10+ |