Wikipedia / Jaccard index
Wikipedia / Jaccard index
The Jaccard index is a statistic used for gauging the similarity and diversity of sample sets. It is defined in general taking the ratio of two sizes (areas or volumes), the intersection size divided by the union size, also called intersection over union (IoU).
The concept was first introduced by Grove Karl Gilbert in 1884 as the “ratio of verification” in contexts of geological prediction evaluation. and now is often called the critical success index in meteorology. It was later developed independently by Paul Jaccard, originally giving the French name (coefficient of community), and independently formulated again by Taffee Tadashi Tanimoto. Thus, it is also called Tanimoto index or Tanimoto coefficient in some fields.
Overview
The Jaccard index measures similarity between finite non-empty sample sets and is defined as the size of the intersection divided by the size of the union of the sample sets:
The Jaccard index is widely used in computer science, ecology, genomics and other sciences where binary or binarized data are used.
Both the exact solution and approximation methods are available for hypothesis testing with the Jaccard index. Jaccard similarity also applies to bags, i.e., multisets. This has a similar formula, but the symbols used represent bag intersection and bag sum (not union). The maximum value is 1/2.
The Jaccard distance, which measures dissimilarity between sample sets, is complementary to the Jaccard index and is obtained by subtracting the Jaccard index from 1 or, equivalently, by dividing the difference of the sizes of the union and the intersection of two sets by the size of the union:
An alternative interpretation of the Jaccard distance is as the ratio of the size of the symmetric difference to the union. Jaccard distance is commonly used to calculate an matrix for clustering and multidimensional scaling of n sample sets. These distance measures are commonly used in cluster analysis for grouping similar observations.
This distance is a metric on the collection of all finite sets.
There is also a version of the Jaccard distance for measures, including probability measures is a measure on a measurable space, then we define the Jaccard index by
and the Jaccard distance by
.
The MinHash min-wise independent permutations locality sensitive hashing scheme may be used to efficiently compute an accurate estimate of the Jaccard similarity index of pairs of sets, where each set is represented by a constant-sized signature derived from the minimum values of a hash function.
The Jaccard index is particularly useful for analyzing large-scale and sparse datasets in modern data mining applications.
Similarity of asymmetric binary attributes
Given two objects, A and B, each with n binary attributes, the Jaccard index is a useful measure of the overlap that A and B share with their attributes. Each attribute of A and B can either be 0 or 1. The total number of each combination of attributes for both A and B are specified as follows:
represents the total number of attributes where A and B both have a value of 1.
represents the total number of attributes where the attribute of A is 0 and the attribute of B is 1.
represents the total number of attributes where the attribute of A is 1 and the attribute of B is 0.
represents the total number of attributes where A and B both have a value of 0.
Each attribute must fall into one of these four categories, meaning that
The Jaccard similarity index, J, is given as
The Jaccard distance, dJ, is given as
Statistical inference can be made based on the Jaccard similarity index, and consequently related metrics. Given two sample sets A and B with n attributes, a statistical test can be conducted to see if an overlap is statistically significant. The exact solution is available, although computation can be costly as n increases. Estimation methods are available either by approximating a multinomial distribution or by bootstrapping.
Difference with the simple matching index (SMC)
When used for binary attributes, the Jaccard index is very similar to the simple matching coefficient in its numerator and denominator, whereas the Jaccard index does not. Thus, the SMC counts both mutual presences (when an attribute is present in both sets) and mutual absence (when an attribute is absent in both sets) as matches and compares it to the total number of attributes in the universe, whereas the Jaccard index only counts mutual presence as matches and compares it to the number of attributes that have been chosen by at least one of the two sets.
In market basket analysis is typically large, making the Jaccard index a more appropriate measure of similarity in that context. For example, consider a supermarket with 1000 products and two customers. The basket of the first customer contains salt and pepper and the basket of the second contains salt and sugar. In this scenario, the similarity between the two baskets as measured by the Jaccard index would be 1/3, but the similarity becomes 0.998 using the SMC.
In other contexts, where 0 and 1 carry equivalent information (symmetry), the SMC is a better measure of similarity. For example, vectors of demographic variables stored in dummy variables, such as gender, would be better compared with the SMC than with the Jaccard index since the impact of gender on similarity should be equal, independently of whether male is defined as a 0 and female as a 1 or the other way around. However, when we have symmetric dummy variables, one could replicate the behaviour of the SMC by splitting the dummies into two binary attributes (in this case, male and female), thus transforming them into asymmetric attributes, allowing the use of the Jaccard index without introducing any bias. The SMC remains, however, more computationally efficient in the case of symmetric dummy variables since it does not require adding extra dimensions.
The Jaccard index is commonly used for asymmetric binary or presence–absence data, where the presence of an attribute is considered more informative than its absence. In such data, shared absences are treated as uninformative and are excluded from the calculation. This makes the measure particularly suitable for sparse binary data in which the occurrence of a feature is more meaningful than its non-occurrence. For symmetric binary variables, however, measures such as the simple matching coefficient may be preferred because they count both shared presences and shared absences. The distinction between similarity measures that include or exclude joint absences has been widely discussed in numerical taxonomy and classification literature. The Jaccard index is defined as
where only B is 1.
Weighted Jaccard similarity and distance
, then their Jaccard similarity index (also known then as Ruzicka similarity) is defined as
and Jaccard distance (also known then as Soergel distance)
, then we can define
are pointwise operators. Then Jaccard distance is
are the characteristic functions of the corresponding set.
represents the number of dimensions. In data science is the number of non-zero attributes. To further scale processing time, techniques such as MinHashing and locality sensitive hashing are used to approximate the index using compact signatures. These algorithmic enhancements ensure that similarity measures remain scalable and efficient, despite an increase in data volume and dimensionality.
Probability Jaccard similarity and distance
The weighted Jaccard similarity described above generalizes the Jaccard Index to positive vectors, where a set corresponds to a binary vector given by the indicator function. However, it does not generalize the Jaccard Index to probability distributions, where a set corresponds to a uniform probability distribution, i.e.
then
Instead, a generalization that is continuous between probability distributions and their corresponding support sets is
which is called the "Probability" Jaccard. It has the following bounds against the Weighted Jaccard on probability vectors.
Here the upper bound is the (weighted) Sørensen–Dice coefficient, is a metric over probability distributions, and a pseudo-metric over non-negative vectors.
The Probability Jaccard Index has a geometric interpretation as the area of an intersection of simplices dimensions that sum to 1. To derive the Probability Jaccard Index geometrically, represent a probability distribution as the unit simplex divided into sub simplices according to the mass of each item. If you overlay two distributions represented in this way on top of each other, and intersect the simplices corresponding to each item, the area that remains is equal to the Probability Jaccard Index of the distributions.
Optimality of the Probability Jaccard Index
is the Total Variation distance. In a fairly strong sense described below, the Probability Jaccard Index is an optimal way to align these random variables.
.
than the increased pair. This theorem is true for the Jaccard Index of sets (if interpreted as uniform distributions) and the probability Jaccard, but not of the weighted Jaccard. (The theorem uses the word "sampling method" to describe a joint distribution over all distributions on a space, because it derives from the use of weighted minhashing algorithms that achieve this as their collision probability.)
This theorem has a visual proof on three element distributions using the simplex representation.
Tanimoto similarity and distance
Various forms of functions described as Tanimoto similarity and Tanimoto distance occur in the literature and on the Internet. Most of these are synonyms for Jaccard similarity and Jaccard distance, but some are mathematically different. Many sources cite an IBM Technical Report as the seminal reference.
In "A Computer Program for Classifying Plants", published in October 1960, a method of classification based on a similarity ratio, and a derived distance function, is given. It seems that this is the most authoritative source for the meaning of the terms "Tanimoto similarity" and "Tanimoto Distance". The similarity ratio is equivalent to Jaccard similarity, but the distance function is not the same as Jaccard distance.
Tanimoto's definitions of similarity and distance
In that paper, a "similarity ratio" is given over bitmaps, where each bit of a fixed-size array represents the presence or absence of a characteristic in the plant being modelled. The definition of the ratio is the number of common bits, divided by the number of bits set (i.e. nonzero) in either sample.
Presented in mathematical terms, if samples X and Y is the ith bit of X are bitwise and, or is
If each sample is modelled instead as a set of attributes, this value is equal to the Jaccard index of the two sets. Jaccard is not cited in the paper, and it seems likely that the authors were not aware of it.
Tanimoto goes on to define a "distance" based on this ratio, defined for bitmaps with non-zero similarity:
This coefficient is, deliberately, not a distance metric. It is chosen to allow the possibility of two specimens, which are quite different from each other, to both be similar to a third. It is easy to construct an example which disproves the property of triangle inequality.
Other definitions of Tanimoto distance
. This function is a proper distance metric. In application, Tanimoto distance can be harmfully confused with Jaccard distance as a proper distance metric.
If Jaccard or Tanimoto similarity is expressed over a bit vector, then it can be written as
where the same calculation is expressed in terms of vector scalar product and magnitude. This representation relies on the fact that, for a bit vector (where the value of each dimension is either 0 or 1) then
and
does not preserve triangle inequality is.
is in fact a distance metric over vectors or multisets in general, whereas its use in similarity search or clustering algorithms may fail to produce correct results.
Lipkus such that, for any vector A Under these circumstances, the function is a proper distance metric, and so a set of vectors governed by such a weighting vector forms a metric space under this function.
Jaccard index in binary classification confusion matrices
In confusion matrices employed for binary classification, the Jaccard index can be framed in the following formula:
where TP are the true positives, FP the false positives and FN the false negatives.
The binary classification formula of the Jaccard Index measures how the predicted positive results match with the actual positive results. It shows how much overlap of what a model predicts are true positive cases to real positive cases. When the Jaccard index is higher it means that the prediction is closer to the actual result.
The Jaccard index is an overlap metric that can be defined with the elements in a confusion matrix. The true positives represent the cases that are predicted positive and are actually positive, creating an overlap of the two groups. The false positives are cases that were predicted positive but are actually not. Similarly, false negatives are cases that were predicted negative but in reality are actually positive. The Jaccard index compares the true positives to the set of relevant information.Jaccard index is useful when trying to compare predicted results against actual results. Using binary classification alongside with Jaccard index helps explain how reliable a prediction model is. It is used in many fields, and commonly used in medicine for lab testing.
Application to computer science and graph theory
In computer science, the Jaccard Index can be used to measure similarity between vertices in a graph by comparing their adjacency sets. Given two vertices, their similarity is calculated by taking the size of the intersection of their neighborhoods divided by the size of their union. This measure is widely applied in Link prediction, community detection, and graph classification, where it serves as a guide to estimate the likelihood of an edge forming between two nodes in networks.
The computation of the Jaccard similarity between two vertices can be expressed using their adjacency sets, as shown below.
Above shows an implementation based on set operations over adjacency lists. In practice, graph representations like adjacency lists are used to improve the efficiency of intersection and union math. For large graphs, computing similarity across all pairs of vertices may be computationally expensive. Programmers may use approximations to avoid taking on the entire cost of this computation.
See also
Sørensen–Dice coefficient: Sørensen–Dice coefficient)
Mutual information, a normalized metricated variant of which is an entropic Jaccard distance.
References
Further reading
External links
Introduction to Data Mining lecture notes from Tan, Steinbach, Kumar
Kaggle Dstl Satellite Imagery Feature Detection - Evaluation