Count shared elements only once
For finite unweighted sets, the union equals the sum of both sizes minus the intersection counted twice.[1]
Let A be the actual-positive set and B the predicted-positive set. A contains TP and FN, while B contains TP and FP. Adding both sizes counts TP twice, but the union must contain it only once. True negatives TN lie outside both positive sets.[1]
Binary Jaccard index for a specified positive class on one unweighted test set.[1]
With a nonempty union, J=1 means identical sets. J=0 means no shared positive elements, although at least one set is nonempty. Two empty sets produce 0/0. Whether software returns 0, 1 or a warning is an additional evaluation convention. The calculator marks this quotient as undefined.[1]
Two examples: cases and grid masks
Positive predictions from a binary filter
- Given
- A specified positive class has TP=30, FP=10 and FN=20. All counts come from the same test set.
- Find
- Determine intersection and union, then calculate the Jaccard index.
The actual-positive set has 50 cases and the predicted-positive set 40.
Subtract the 30 shared cases once when adding the set sizes.
Divide intersection by union.
Result: Jaccard is 0.5, or 50%. This is overlap within the positive union, not the share of all correctly classified cases.
Check: Precision is 30/40=0.75 and recall is 30/50=0.60. Different denominators explain why the scores differ.
Two rectangular masks on the same grid
- Given
- Reference mask A contains a 5×10-cell rectangle. Predicted mask B contains a 4×10-cell rectangle, horizontally offset so that two columns of ten cells overlap.
- Find
- Calculate IoU from cell counts without confusing it with contour distance.
The intersection contains 2×10=20 cells.
The union counts shared cells once.
The quotient is two sevenths.
Result: IoU is about 28.57%. For this positive mask class, TP=20, FP=20 and FN=30. These sets differ from the first example.
Check: TP+FP+FN=20+20+30=70 confirms the union. Background cells outside both masks do not alter this class-specific Jaccard score.
Intersection in an original grid model
Free with a Quanta account. Your download stays ready after registration.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Convert to F1 before averaging
For the same positive class and defined count-based scores, F1 converts directly to Jaccard. Both use TP and FP+FN, but weight the shared part differently. Conversion is nonlinear, so it generally cannot be applied only after averaging into a macro score.[1][2]
Micro Jaccard aggregates appropriate counts before division. Macro Jaccard averages previously calculated class scores equally; weighted averaging adds specified weights. Multilabel data can also be averaged per sample. These evaluations answer different questions. Report the averaging method, included classes and zero-case convention alongside the number.[1]
What a high IoU does not establish
Jaccard measures overlap. It does not directly measure distance between contours, positional errors of individual points or decision costs. For a specified positive class, true-negative background cases do not enter. The formula therefore supplies no universal threshold for a good prediction. For masks, also specify whether the measure counts cells, continuous areas or weights; do not change that definition within a calculation.[1]
Five exercises with complete solutions
Calculate · Foundation
For one class, TP=12, FP=3 and FN=5. Find Jaccard.
Show hint
Add the three counts in the denominator.
Learning goal: Calculate Jaccard from a positive union.
Show solution and calculation
The union contains 12+3+5=20 cases and the intersection 12.
Therefore J=12/20=0.6.
True-negative background counts are not required.
Rearrange · Application
For one class, J=0.75, TP=30 and FN=4. How many FP are there?
Show hint
Rearrange J=TP/(TP+FP+FN) for FP.
Learning goal: Recover a missing error count from Jaccard.
Show solution and calculation
The union must contain 30/0.75=40 cases.
Subtracting TP and FN leaves FP=40−30−4=6.
Substitution gives 30/(30+6+4)=0.75.
Interpret · Application
TP=12, FP=3 and FN=5 remain unchanged. Add 1000 cases that are actually negative and predicted negative. Does Jaccard increase?
Show hint
Check whether those cases belong to either positive set.
Learning goal: Explain the role of true negatives.
Show solution and calculation
No.
Additional TN are outside both positive sets.
Intersection and union remain 12 and 20, so J stays 0.6.
Overall accuracy can nevertheless change.
Error analysis · Application
Two sets have sizes 20 and 15, with intersection size 10. A solution gives J=10/35. Correct it.
Show hint
The sum of set sizes counts shared elements twice.
Learning goal: Correct an intersection counted twice in the denominator.
Show solution and calculation
The union is 20+15−10=25, not 35.
Hence J=10/25=0.4.
Subtracting removes one duplicate copy of the ten shared elements, leaving them in the union once.
Transfer · Challenge
Two independently evaluated labels in a multilabel problem have defined Jaccard values of 1 and 0, each with a nonempty union. Compare macro F1 with converting macro Jaccard using 2J/(1+J).
Show hint
Convert each label’s score before averaging.
Learning goal: Distinguish nonlinear conversion from macro averaging.
Check your understanding with the formula’s reference test.
7 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Sources for this explanation
Quanta · Updated November 1, 2026
- scikit-learn documentation: jaccard_score, set definition, averaging and undefined empty case
- scikit-learn documentation: f1_score and count formula
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Added a set model, classification and mask examples, and exercises on unions, zero cases and averaging.
Cite this reference page
Quanta. Jaccard index (intersection over union). Updated November 1, 2026. https://quanta-study.de/en/formula-sheet/jaccard-index-klassifikation
When citing a specific scientific statement, also cite the specialist source linked to that statement.