Metrics jaccardscore score - 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 Jaccard similarity coefficient — sklearn.metrics.jaccard_score.
public static double Score(ReadOnlySpan<int> yTrue, ReadOnlySpan<int> yPred, Averaging average = Averaging.Binary, int posLabel = 1, ZeroDivision zeroDivision = ZeroDivision.Zero, ReadOnlySpan<int> labels = default, ReadOnlySpan<double> sampleWeight = default)Parameters — yTrue and yPred are the labels to count a matrix from. average decides how the per-class coefficients are reduced. posLabel is the class
reported under Averaging.Binary. zeroDivision is the answer for a class neither side carries.
labels fixes the label set and its order; omit it for the sorted union of both inputs.
sampleWeight is one weight per sample.
Returns — double in [0, 1], never above Precision.Score or
Recall.Score on the same class.
Exceptions — ArgumentException when the inputs disagree in length or the weights do not match, hold a non-finite value or are zero throughout; when average is Averaging.Binary and
posLabel occurs in neither input, which is the refusal Precision.Score already makes; and
when average is Averaging.Weighted and the class supports sum to zero without all being
zero, which only a negative weight reaches and which jaccard_score refuses in the same words.
UndefinedMetricException when a class is empty on both sides and zeroDivision is
ZeroDivision.Throw.
Example — four samples over three classes.
using Lodestar.Metrics;
int[] truth = [0, 1, 2, 1];
int[] predicted = [0, 2, 2, 1];
double macro = JaccardScore.Score(truth, predicted, Averaging.Macro); // => 0.6666…Averaging.Micro gives 0.6 and Averaging.Weighted 0.625 on the same input — the three
disagree because one class is scored perfectly and two are half right.
Applies to — net10.0, netstandard2.0.
See also — JaccardScore.PerClass,
Precision.Score, Recall.Score, the
Python equivalence table.