Aggregation¶
The three aggregation operators, plus the conventions they require.
Given indicator matrices \(Y, \hat{Y} \in \{0,1\}^{n \times m}\), the four cell matrices are formed entrywise and then reduced in one of three ways:
Operator |
Reduction |
Conventional name |
|---|---|---|
|
over all entries |
micro |
|
column-wise, then averaged |
macro (or weighted) |
|
row-wise, then averaged |
exemplar ( |
Column- and row-wise aggregation divide before averaging, so an individual entry
can be undefined when its denominator vanishes. Because the resolution changes the
reported value, it is an explicit parameter rather than an implicit default. The
package defaults to 'exclude', which averages over the defined entries only.
- aggmetrics.aggregation.cells(Y, P, mask=None)¶
Entrywise TP, FP, FN, TN matrices.
Works for crisp indicator matrices and, unchanged, for soft ones in
[0, 1]when they have already been combined by a t-norm (seeaggmetrics.tnorms).maskis an optional observation mask: entries wheremask == 0are treated as unobserved and contribute nothing, which covers partial labels, semi-supervised evaluation and masked-out abstentions.
- aggmetrics.aggregation.sigma_1(X)¶
Global aggregation: sum over all entries.
- aggmetrics.aggregation.sigma_m(X)¶
Column-wise aggregation: one value per class or label.
- aggmetrics.aggregation.sigma_n(X)¶
Row-wise aggregation: one value per example.
- aggmetrics.aggregation.sigma_k(cell_list)¶
Fold-wise aggregation across K cross-validation splits.
Sums the four cell matrices (TP, FP, FN, TN) across multiple folds.
- aggmetrics.aggregation.aggregate(Y, P, measure, how='micro', *, convention='exclude', mask=None, return_parts=False)¶
Apply
measureto(Y, P)under the operatorhow.- Parameters:
how (Literal['micro', 'macro', 'weighted', 'exemplar']) –
'micro'pools all entries before applying the measure;'macro'applies it per class and averages;'weighted'applies it per class and averages with weights proportional to the class prevalence;'exemplar'applies it per example and averages.convention (str) – Treatment of undefined per-class or per-example entries.
'exclude'averages over defined entries only.'zero'reproduces the behaviour ofsklearn’szero_division=0.return_parts (bool) – If True, also return the vector of per-class or per-example values, which is what the diagnostics use to check whether a pooled value lies inside their convex hull.
measure (str | BinaryMeasure)
- aggmetrics.aggregation.fold_aggregate(im_list, measure, how='macro', pooling='pooled', *, convention='exclude')¶
Aggregate a performance measure across K cross-validation folds.
- Parameters:
im_list (Sequence) – Sequence of
IndicatorMatrixinstances, one per fold.measure (str | BinaryMeasure) – The performance measure to compute.
how (Literal['micro', 'macro', 'weighted', 'exemplar']) – Intra-fold aggregation operator:
'micro','macro', or'exemplar'.pooling (Literal['pooled', 'averaged']) –
'pooled'concatenates the folds’ predictions before computing the non-linear ratio, so folds may differ in size;'averaged'computes the measure separately in each fold and returns the sample-weighted mean.convention (str) – Convention for undefined entries (
'exclude','zero', etc.).
- Return type: