# Proof of calculating Minhash

I'm reading about MinHash technique to estimate the similarity between 2 sets: Given set A and B, h is the hash function and $h_\min(S)$ is the minimum hash of set S, i.e. $h_\min(S) = \min(h(s))$ for s in S. We have the equation: $$p(h_\min(A) = h_\min(B)) = \frac{|A \cap B|}{|A \cup B|}$$ Which means the probability that minimum hash of A equals to minimum hash of B is the Jaccard similarity of $A$ and $B$.

I am trying to prove above equation and come up with a proof, which is: for $a \in A$ and $b \in B$ such that $h(a) = h_\min(A)$ and $h(b) = h_\min(B)$. So, if $h_\min(A) = h_\min(B)$ then $h(a) = h(b)$. Assume that hash function h can hash keys to distinct hash value, so $h(a) = h(b)$ if and only if $a = b$, which is $\frac{|A \cap B|}{|A \cup B|}$. However, my proof is not complete since hash function can return the same value for different keys. So, I'm asking for your help to find a proof which can be applied regardless the hash function. Thanks.

L

-

There is a remarkable connection between minhashing and Jaccard similarity of the sets that are minhashed.

• The probability that the minhash function for a random permutation of rows produces the same value for two sets equals the Jaccard similarity of those sets.

To see why, we need to picture the columns for those two sets. If we restrict ourselves to the columns for sets S1 and S2, then rows can be divided into three classes:

1. Type X rows have 1 in both columns.
2. Type Y rows have 1 in one of the columns and 0 in the other.
3. Type Z rows have 0 in both columns.

Since the matrix is sparse, most rows are of type Z. However, it is the ratio of the numbers of type X and type Y rows that determine both SIM(S1, S2) and the probability that h(S1) = h(S2). Let there be x rows of type X and y rows of type Y . Then SIM(S1, S2) = x/(x + y). The reason is that x is the size of S1 ∩ S2 and x + y is the size of S1 ∪ S2.

Now, consider the probability that h(S1) = h(S2). If we imagine the rows permuted randomly, and we proceed from the top, the probability that we shall meet a type X row before we meet a type Y row is x/(x + y). But if the first row from the top other than type Z rows is a type X row, then surely h(S1) = h(S2). On the other hand, if the first row other than a type Z row that we meet is a type Y row, then the set with a 1 gets that row as its minhash value. However the set with a 0 in that row surely gets some row further down the permuted list. Thus, we know h(S1) 6= h(S2) if we first meet a type Y row. We conclude the probability that h(S1) = h(S2) is x/(x + y), which is also the Jaccard similarity of S1 and S2. ( from Mining of Massive Datasets book )

-
You shouldn't just blatantly plagiarize answers from well known texts. – Shawn O'Hare Feb 24 '15 at 16:58