![]() |
VOOZH | about |
Jaccard Similarity also called as Jaccard Index or Jaccard Coefficient is a simple measure to represent the similarity between data samples. The similarity is computed as the ratio of the length of the intersection within data samples to the length of the union of the data samples.
It is represented as -
J(A, B) = |A Ո B| / |A U B|
It is used to find the similarity or overlap between the two binary vectors or numeric vectors or strings. It can be represented as J. There is also a closely related term associated with Jaccard Similarity which is called Jaccard Dissimilarity or Jaccard Distance. Jaccard Distance is a measure of dissimilarity between data samples and can be represented as (1 – J) where J is Jaccard Similarity.
👁 ImageJaccard Similarity is used in multiple data science and machine learning applications. Some of the frequent use cases encountered in real life include :
Jaccard Similarity value ranges from 0 to 1. The higher the number, the more similar are the datasets with each other. Although it is easy to interpret but is extremely sensitive to smaller sample datasets and can give erroneous results hence one needs to be careful while comprehending results.
Jaccard Similarity (J) = ( count of common elements in both sets) / ( count of elements in first set + count of elements in second set - count of common elements in both sets)
Where (count of elements in first set + count of elements in the second set - count of common elements in both sets) = count of total unique elements in both the sets.
Considering A and B as two sets, it can be represented in symbolic form as
J(A, B) = |A Ո B| / |A U B| = |A Ո B| / |A| + |B| - |A Ո B|
Example:
In this example, we will be considering A and B be two sets respectively where Set A = { 5, 10, 15, 20, 25, 30, 35,40, 45, 50} and Set B = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100),A Ո B = { 10, 20, 30, 40, 50 } i.e., |A Ո B| = 5,A U B = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100 } i.e., |A U B| = 15,Therefore, J(A, B) = |A Ո B| / |A U B| = 5 / 15 = 0.33333 and stating it in R programming language.
Output
👁 ImageConsidering A and B as two binary vectors,
Jaccard Similarity (J) = (number of observations which are 1 in both the vectors) / (number of observations which are 1 in both the vectors + number of observations which are 0 for A and 1 for B + number of observations which are 1 for A and 0 for B)
The symbolic form becomes
J(A, B) = a_11 / (a_11 + b_01 + c_10)
Where a_11 = observations being 1 in both vectors
Example:
Consider a grocery store selling multiple products wherein the shop owner is interested in finding out the similarity between two customers on the basis of purchases made. Here 1 indicates the product that has been purchased by the two customers and 0 indicates that the product was not purchased by those two customers.
Product1 | Product2 | Product3 | Product4 | Product5 | Product6 | Product7 | Product8 | Product9 | Product10 | |
|---|---|---|---|---|---|---|---|---|---|---|
Customer1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 |
Customer2 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
Output
👁 ImageJaccard Similarity (J) = (number of matching strings present in both sets) / (number of strings in either of the set)
Considering A and B as two sets, it can be represented in symbolic form as
J(A, B) = |A Ո B| / |A U B|
Example :
Let A and B be two sets of strings where
Set A = { ‘John’, ‘is’, ’going’,’ to’, ’the’, ’market’, ’today’, ’to’, ’buy’, ’cake’} and
Set B = {‘Tim’, ‘is’, ‘at’, ’the’,’ shop’, ’already’, ’for’, ‘buying’, ‘two’, ‘cakes’}
Find Jaccard Similarity between the two sets.
Output
👁 Image