Measures¶
Binary performance measures, each carrying the metadata the framework needs to reason about it.
A measure is not merely a function of the four confusion-matrix counts. Whether the framework’s identities apply to it depends on structural properties that are recorded here alongside the formula:
linearCoefficients \((\mathbf{a}, \mathbf{b})\) such that \(M = \langle a, v\rangle / \langle b, v\rangle\) with \(v = (tp, fp, fn, tn)\), or
Noneif no such representation exists. A measure with coefficients is aggregation-decomposable: micro-averaging equals denominator-weighted macro-averaging. Without them the identity fails, and the pooled value need not even lie in the convex hull of the per-class values.skew_invariantWhether the measure is unchanged when the two classes are rescaled independently, equivalently whether it is a function of recall and specificity alone.
tn_dependent_at_zeroWhether the value at
tp == 0still depends ontn. This determines whether the measure can attain its nominal minimum under one-hot multiclass encoding, where an incorrectly classified example still contributesm - 2true negatives.greater_is_betterDirection, needed for ranking and for the scikit-learn scorer interface.
- class aggmetrics.measures.BinaryMeasure(name, fn, greater_is_better=True, linear=None, skew_invariant=False, tn_dependent_at_zero=False, aliases=<factory>, note='')¶
Bases:
objectA binary measure together with its structural properties.
- Parameters:
- bayes_threshold()¶
Optimal decision threshold on the conditional probability, or None.
For a measure whose numerator is linear with coefficients
(alpha, -beta, -gamma, delta)and whose denominator does not depend on the predictions, the population-optimal rule is to predict positive when the conditional probability exceeds(beta + delta) / (alpha + beta + gamma + delta).Returns None when the measure is not of that form, in which case no such closed form exists and an iterative procedure is required.
- Return type:
float | None
- erm_consistent()¶
Whether the measure is maximised by the Bayes rule for 0/1 loss.
- Return type:
bool | None
- attainable_floor(m)¶
Value attained under one-hot encoding when every prediction is wrong.
With
mclasses andnexamples all misclassified, the pooled counts aretp = 0,fp = fn = nandtn = n (m - 2). Measures that do not depend ontnattp = 0reach their nominal minimum; the rest are bounded away from it by an amount that grows withm.
- aggmetrics.measures.get_measure(name)¶
Look up a measure by name or alias.
- Parameters:
name (str | BinaryMeasure)
- Return type: