fair_seldonian package#
Subpackages#
- fair_seldonian.algorithms package
- fair_seldonian.constraints package
- Submodules
- fair_seldonian.constraints.affine module
- fair_seldonian.constraints.bounds module
- fair_seldonian.constraints.expression_tree module
- fair_seldonian.constraints.expression_tree_ext module
- fair_seldonian.constraints.fairness module
- fair_seldonian.constraints.inequalities module
- Module contents
- fair_seldonian.data package
- fair_seldonian.experiments package
- fair_seldonian.models package
Submodules#
fair_seldonian.config module#
- fair_seldonian.config.DEFAULT_CONFIG = SeldonianConfig(delta=0.05, inequality=<Inequality.HOEFFDING_INEQUALITY: 2>, constraint='TP(1) TP(0) - abs 0.25 TP(1) * -', candidate_ratio=0.4, optimizer='Powell', max_iter=10000, penalty=100.0)#
The configuration every entry point falls back to when none is passed –
QSA(),ghat()and the rest all default to it. Being a frozen dataclass it is safe to share; build a variant withdataclasses.replaceor by constructing a newSeldonianConfig.
- class fair_seldonian.config.SeldonianConfig(
- delta=0.05,
- inequality=Inequality.HOEFFDING_INEQUALITY,
- constraint='TP(1) TP(0) - abs 0.25 TP(1) * -',
- candidate_ratio=0.4,
- optimizer='Powell',
- max_iter=10000,
- penalty=100.0,
Bases:
objectConfiguration for the Seldonian algorithm.
The
constraintis the fairness/behavioral requirement thatQSA()must certify, given as a reverse-Polish (postfix) string over the per-group confusion-matrix cellsTP(g),FP(g),FN(g),TN(g). You can supply it two ways:a built-in fairness constraint from
fair_seldonian.constraints.fairness(recommended) -demographic_parity(),equal_opportunity(),equalized_odds(),error_rate(), orerror_rate_parity(); ora custom postfix string you write yourself.
Both produce the same kind of string, so they are interchangeable:
from fair_seldonian import SeldonianConfig, demographic_parity SeldonianConfig(constraint=demographic_parity(epsilon=0.1)) SeldonianConfig(constraint="PR(1) PR(0) - abs 0.1 -")
The constraint is validated on construction (via
validate_constraint()), so a malformed custom string raisesValueErrorimmediately rather than failing inside QSA.- Parameters:
delta (float) – the constraint must hold with probability >= 1 - delta.
inequality (Inequality) – concentration inequality used for the confidence bound.
constraint (str) – the postfix constraint string (see above).
candidate_ratio (float) – fraction of data used to pick the candidate solution.
optimizer (str) – any
methodaccepted byscipy.optimize.minimize().max_iter (int) – iteration cap handed to the optimizer.
penalty (float) –
weight on the constraint violation in candidate selection. Candidate selection minimises
log_loss + penalty * max(0, u)whereuis the predicted upper bound on the constraint.A continuous penalty matters more than it looks. The tempting alternative is a hard barrier - return some large constant plus
uwhen infeasible and the loss when feasible - but SciPy’s Powell convergence test is relative: with an objective of order 1e4 and the defaultftol=1e-4the stopping threshold is about 1.0, whileuvaries by only about 1e-2 over the whole parameter space. Powell then reports success after a single iteration while still infeasible, andmax_iternever binds. An exact penalty keeps the objective order 1 and gives the optimizer usable signal on the infeasible side.
- inequality: Inequality = 2#