- Introduced by
- Paul Jaccard
- Year
- 1901
- Type
- Similarity metric
- Family
- Multi-label Metric
What does it do?
The Jaccard index measures the similarity between a predicted set and a true set as the ratio of their intersection to their union.
It is used in multi-label classification, image segmentation and other set-comparison tasks where partial overlap should count toward the score.
The intuition behind the method
The Jaccard index answers the question: what fraction of all labels that appear in either set are present in both? If a sample has true labels {A, B, C} and the model predicts {A, B, D}, the intersection is {A, B} (size 2) and the union is {A, B, C, D} (size 4), so Jaccard = 2/4 = 0.5. A value of 1.0 means the predicted set matches the true set exactly, and a value of 0 means the two sets share no labels. Because a correct label adds to the numerator and any wrong label (missed or extra) adds to the denominator, the score gives partial credit for partly correct predictions.
History
Paul Jaccard introduced the coefficient in 1901 in a comparative study of the distribution of flora in the Alps and Jura. The bibliographic details of this 1901 publication have not been confirmed against a bibliographic database. Tsoumakas and Katakis (2007) is a general overview of multi-label classification and a useful background reference for the setting in which the Jaccard index is applied to label sets.
When to use it
Choose the Jaccard index when the output for each sample is a set of labels or a set of pixels, and you want a score that reflects overlap between the predicted and true sets. Typical cases are multi-label classification, document tagging, image segmentation (intersection over union of pixel sets), and recommendation overlap. The unweighted Jaccard index gives each missed label and each extra label equal weight in the union, so it is inappropriate as the main metric when false positives and false negatives have different costs. In that case, report precision and recall separately or use a weighted variant. If you need label-by-label error rates, use Hamming loss instead, and if you need exact whole-set matches, use subset accuracy. When reporting a dataset-level number, state how per-sample scores were aggregated (for example, a mean over samples).
Limitations and considerations
- Both missed labels and extra labels reduce the score, and the unweighted formula gives them equal weight, with no way to weight them differently.
- When the true set is small, a single extra predicted label can lower the score substantially, because it enlarges the union relative to the intersection.
- The same number of label errors produces different scores depending on how many labels each set contains, so scores are not directly comparable across samples with different set sizes.
- The score is undefined when both the true and predicted sets are empty (zero divided by zero), and implementations differ in how they handle this case. Report which convention was used (for example, score 1, score 0, or exclude the sample) together with the results.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The formula is symmetric in the true and predicted sets, so it does not favour one over the other.
- The value has a direct reading: it is the share of the combined label set that the prediction gets right.
- A partly correct prediction receives a score above zero, since each shared label contributes to the numerator.
- It applies directly to set-valued outputs without first converting them to a single class label.
Applications
- Image segmentation, where the Jaccard index (intersection over union) compares predicted and reference pixel regions.
- Document tagging, where it measures the overlap between predicted and true topic labels.
- Multi-label text classification, where it evaluates how closely predicted label sets match the true sets.
- Recommender systems, where it measures the overlap between recommended items and items that are actually relevant.
How it works
How it works
For each sample, let Y be the set of true labels and Ŷ the set of predicted labels. When the score is reported for a dataset, the per-sample values are usually averaged over all samples (example-based averaging).
Formula
Y = \text{true label set},\quad \hat{Y} = \text{predicted label set}Jaccard = |Y ∩ Ŷ| / |Y ∪ Ŷ|, where |·| is the number of elements in a set. The numerator counts labels that are both true and predicted. The denominator counts every distinct label that is true or predicted, so each missed label and each extra label enlarges the denominator. The corresponding Jaccard loss is 1 − Jaccard.
Formula
J(Y,\hat{Y}) = \frac{|Y \cap \hat{Y}|}{|Y \cup \hat{Y}|}Jaccard ranges from 0 to 1. A value of 1 means the predicted set equals the true set. A value of 0 means the two sets have no label in common. Higher values indicate closer agreement. The value is only meaningful relative to a baseline on the same data.
Formula
0 \le J \le 1;\quad J=1 \iff Y=\hat{Y};\quad J=0 \iff Y\cap\hat{Y}=\emptysetCommon pitfalls
- Using Jaccard without considering the relative cost of false positives and false negatives; if those costs differ, use a weighted variant or report precision and recall separately.
- Comparing Jaccard scores across datasets with different average label set sizes, since the score depends on set cardinality.
- Treating Jaccard and Hamming loss as interchangeable; they answer different questions, so the choice should follow whether the evaluation is set-level or label-level.
- Expecting Jaccard to be 0 when some labels are correct; the score is 0 only when the true and predicted sets share no label, and any single shared label makes it positive.
- Reporting an average over samples where some samples have empty true and predicted sets without stating how those samples were scored.
Frequently asked questions
How does Jaccard differ from Hamming loss?
Hamming loss averages label-by-label errors, asking how many labels are wrong out of all labels. Jaccard compares whole predicted and true label sets, asking what fraction of the combined label set is correct. A missed label and an extra label both reduce the Jaccard score, which is why it is often stricter at the set level, while Hamming loss scores each label independently.
Is Jaccard the same as IoU (Intersection over Union)?
Yes. The Jaccard index and intersection over union are the same quantity: |intersection| divided by |union|. IoU is the more common name in computer vision, especially for image segmentation, while Jaccard is more common in statistics and multi-label learning.
What is a good Jaccard score?
There is no universal threshold. What counts as good depends on the task, the number of possible labels, and the typical size of the label sets. On hard problems with many possible labels, scores can be low even for useful models. Compare the score with a simple baseline, such as always predicting the most frequent labels, computed on the same dataset with the same label-set size distribution. Scores are not comparable across datasets with different label cardinality.
Related methods
Sources
Jaccard, P. (1901). Etude comparative de la distribution florale dans une portion des Alpes et des Jura. Bulletin de la Société Vaudoise des Sciences Naturelles, 37, 547-579.
Open publication referenceTsoumakas, G., & Katakis, I. (2007). Multi-label classification: An overview. International Journal of Data Warehousing and Mining, 3(3), 1-13.
Open DOI reference