Metrics 0.3.0 pairconfusionmatrix - CyrilB1531/lodestar GitHub Wiki

Lodestar.Metrics 0.3.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

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.