Skip to content

Metrics jaccardscore score

github-actions[bot] edited this page Aug 26, 2026 · 24 revisions

Development build. This page describes main, not a released package. The latest published Lodestar.Metrics is 0.3.0 — read its documentation.

JaccardScore.Score

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)

ParametersyTrue 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.

Returnsdouble in [0, 1], never above Precision.Score or Recall.Score on the same class.

ExceptionsArgumentException when the inputs disagree in length or the weights do not match — and when average is Averaging.Binary and posLabel occurs in neither input, which is the refusal Precision.Score already makes. 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 alsoJaccardScore.PerClass, Precision.Score, Recall.Score, the Python equivalence table.

Lodestar

Project

Clone this wiki locally