Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for Jaccard bag/multiset semantics #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adds support for Jaccard bag/multiset semantics #5

wants to merge 1 commit into from

Conversation

tcsalameh
Copy link

This commit adds support for calculating Jaccard similarity using
bag/multiset semantics, as described on pgs. 76-77 in chapter 3 of
Mining of Massive Datasets (MMDS).

MMDS uses the example of movie ratings:

If ratings are 1-to-5-stars, put a movie in a customer's set n times
if they rated the movie n-stars. Then, use Jaccard similarity for bags
when measuring the similarity of customers. The Jaccard similarity for
bags B and C is defined by counting an element n times in the
intersection if n is the minimum of the number of times the element
appears in B and C. In the union, we count the element the sum of the
number of times it appears in B and C.

To fit a model using bag semantics, the user:

  • Instantiates an LSH model with the variable repeatedItems set to
    true. This is an optional variable that is false by default.
  • Passes their data into the model as a List or RDD of SparseVectors,
    where the indices of each SparseVector correspond to the distinct
    items in the set, and the values of each correspond to the number of
    times each corresponding item is repeated in the set.

The only difference in running the model and getting output is that the
Jaccard similarity between two sets with bag semantics has a maximum of
0.5 rather than 1.0.

This commit adds support for calculating Jaccard similarity using
bag/multiset semantics, as described on pgs. 76-77 in chapter 3 of
Mining of Massive Datasets (MMDS).

MMDS uses the example of movie ratings:

> If ratings are 1-to-5-stars, put a movie in a customer's set n times
> if they rated the movie n-stars. Then, use Jaccard similarity for bags
> when measuring the similarity of customers. The Jaccard similarity for
> bags B and C is defined by counting an element n times in the
> intersection if n is the minimum of the number of times the element
> appears in B and C. In the union, we count the element the sum of the
> number of times it appears in B and C.

To fit a model using bag semantics, the user:
- Instantiates an LSH model with the variable repeatedItems set to
  true. This is an optional variable that is false by default.
- Passes their data into the model as a List or RDD of SparseVectors,
  where the indices of each SparseVector correspond to the distinct
items in the set, and the values of each correspond to the number of
times each corresponding item is repeated in the set.

The only difference in running the model and getting output is that the
Jaccard similarity between two sets with bag semantics has a maximum of
0.5 rather than 1.0.
@tcsalameh
Copy link
Author

Also: I just added a couple lines in the README about the repeatedItems option, but I'm happy to also add an example if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant