Metrics pairconfusionmatrix - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Metrics is 0.3.0 โ read its documentation.
Home โบ Metrics โบ Clustering metrics
PairConfusionMatrix
How two labellings pair the samples up: for every ordered pair, whether each labelling put the two together.
public readonly record struct PairConfusionMatrix(
long DifferentInBoth,
long SameInPredictedOnly,
long SameInTrueOnly,
long SameInBoth)
Example โ one class split into two clusters.
using Lodestar.Metrics;
PairConfusionMatrix pairs = PairConfusionMatrix.Compute([0, 0, 1, 1], [0, 1, 2, 3]);
long agreeing = pairs.SameInBoth; // => 0
long disagreeing = pairs.SameInTrueOnly; // => 4
Remarks โ four fields, all long. This is not a ConfusionMatrix,
which is a different type answering a different question: ConfusionMatrix counts labels, one
cell per (true class, predicted class); this type counts ordered pairs of samples, one cell
per (were-they-together-in-truth, were-they-together-in-the-prediction). Reusing the name would
have been wrong and reusing the type would have been worse โ a caller reading ConfusionMatrix
would expect label counts and get pair counts instead.
They are long because they reach long scale fast: the four values sum to nยฒ, which is about
5ยท10โน at a hundred thousand samples โ past int.MaxValue.
The names follow a truth-table reading, and RandIndex.Score is built from
exactly these four: DifferentInBoth and SameInBoth are the pairs the two labellings agree
about, and dividing their sum by the total is the whole of the Rand index.
Being a record struct, it compares by value and deconstructs โ var (diff, predOnly, trueOnly, both) = pairs; works, in declaration order.
Applies to โ net10.0, netstandard2.0.
See also โ ConfusionMatrix, RandIndex.Score,
the clustering index.
Members
| Member | What it does |
|---|---|
PairConfusionMatrix.Compute |
Counts the pairs two labellings agree and disagree about. |
PairConfusionMatrix.ToArray |
The same four counts as a 2ร2 array, in scikit-learn's own order. |