Metrics brierscore multiclass - 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 › Classification metrics
The Brier score over a probability matrix — sklearn.metrics.brier_score_loss with 2-D probabilities.
public static double MultiClass(ReadOnlySpan<int> yTrue, ReadOnlySpan<double> yProba, int classCount, bool scaleByHalf = false, ReadOnlySpan<double> sampleWeight = default)Parameters — yTrue is the true class index of each sample, in [0, classCount). yProba is
the class probabilities row-major. classCount is how many classes each row scores. scaleByHalf
halves the sum over classes; false, the default, is what scale_by_half='auto' resolves to for a
matrix. sampleWeight is one weight per sample, or empty.
Returns — double, 0 or above. Unlike LogLoss.MultiClass, every
column contributes: the score is the squared distance from the one-hot truth across the whole row,
so a probability moved between two wrong classes changes it.
Exceptions — ArgumentException when yProba is not yTrue.Length × classCount, when a label
is not a class index below classCount, or when a probability falls outside [0, 1]. A sampleWeight holding NaN or an infinity is refused with "Input sample_weight contains NaN." or its infinity counterpart, and one that is zero throughout with "Sample weights must contain at least one non-zero number." — both ArgumentException naming sampleWeight, as scikit-learn's _check_sample_weight refuses them. Weights that merely sum to zero are refused too, with numpy's "Weights sum to zero, can't be normalized."
ArgumentOutOfRangeException when classCount is below two.
Example — four samples over three classes.
using Lodestar.Metrics;
int[] truth = [0, 1, 2, 1];
double[] probabilities =
[
0.7, 0.2, 0.1,
0.1, 0.8, 0.1,
0.2, 0.2, 0.6,
0.3, 0.4, 0.3,
];
double brier = BrierScore.MultiClass(truth, probabilities, classCount: 3); // => 0.245Remarks — the default of scaleByHalf is false here and true on
BrierScore.Score, deliberately: the reference's 'auto' reads the input's
shape rather than the caller's intent, and reproducing it as a default per entry point is what keeps
both numbers the reference's. Halving the example above gives 0.1225.
Rows that do not sum to 1 are scored as given, for the reason
LogLoss.MultiClass states.
Applies to — net10.0, netstandard2.0.
See also — BrierScore.Score,
LogLoss.MultiClass, the Python equivalence table.