Tversky Index Calculator
Compute the Tversky index and Tversky loss from TP, FP and FN with tunable α and β weights — and see the same prediction scored as Dice and Jaccard/IoU side by side. Runs entirely in your browser, nothing uploaded.
How it works
The Tversky index scores how well a predicted set P matches a ground-truth set G. In classification and segmentation terms it is built from three counts:
- TP = |P ∩ G| — true positives, the correct overlap.
- FP = |P ∖ G| — false positives, predicted but not in truth.
- FN = |G ∖ P| — false negatives, truth positives the model missed.
The index, introduced by Amos Tversky in “Features of Similarity” (1977) and cast in this TP/FP/FN form for segmentation by Salehi et al. (2017), is:
TI(α, β) = TP / (TP + α·FP + β·FN)
The weight α scales the false-positive term and β scales the false-negative term. That single asymmetry is the whole point: Dice and Jaccard treat the two error types identically, but on imbalanced data — a small tumour, a thin road, a rare defect — a missed positive usually costs far more than a false alarm. Raising β makes those misses drag the score down, which is exactly the training signal you want.
Two familiar metrics are special cases of this one formula:
- α = β = 0.5 → Dice / F1: TP / (TP + 0.5·FP + 0.5·FN) = 2·TP / (2·TP + FP + FN)
- α = β = 1 → Jaccard / IoU: TP / (TP + FP + FN)
The calculator computes both special cases on your exact counts and shows them next to your weighting, so the relationship is visible rather than asserted. The Tversky loss is simply 1 − TI(α, β) — the quantity a network minimises. Salehi et al. adopt the α + β = 1 convention so the two weights trade off directly; the tool flags when your inputs meet it. In Two sets mode, TP/FP/FN are derived by set intersection and difference on the two lists you paste (duplicates collapse to membership), then the identical formula applies. All arithmetic is exact floating point and runs in your browser.
Worked examples
Frequently asked questions
Sources & references
- Tversky, A. (1977). Features of Similarity. Psychological Review, 84(4), 327–352.
- Salehi, Erdogmus & Gholipour (2017). Tversky loss function for image segmentation (arXiv:1706.05721).
- Tversky index — definition and relationship to Dice and Jaccard (Wikipedia).
The formula and the Dice/Jaccard special cases were last cross-checked against the primary sources on 2026-07-13. The identity checks (α=β=0.5 → Dice, α=β=1 → Jaccard) are enforced by the calculator's own comparison functions.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.