concept

Fairness, privacy and accessibility

Compute exact conditional error rates and selection; undefined rates return None.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
rates(tp, fp, tn, fn)

Working Example

Example Snippetartificial-intelligence
from fractions import Fraction
def rates(tp, fp, tn, fn):    if any(type(x) is not int or x < 0 for x in (tp, fp, tn, fn)):        raise ValueError("counts must be nonnegative integers")    def ratio(a, b):        return Fraction(a, b) if b else None    return {"selection": ratio(tp+fp, tp+fp+tn+fn),            "fpr": ratio(fp, fp+tn), "fnr": ratio(fn, fn+tp),            "accuracy": ratio(tp+tn, tp+fp+tn+fn)}
for name, counts in [("A", (8, 2, 8, 2)), ("B", (6, 4, 6, 4))]:    print(name, {k: str(v) for k, v in rates(*counts).items()})print(rates(0, 0, 0, 0))