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

SAR item similarity dtype correction #1751

Merged

Conversation

simonzhaoms
Copy link
Contributor

@simonzhaoms simonzhaoms commented Jun 17, 2022

Description

In sar_singlenode.py, item similarity matrix is converted to the same dtype as col_rating:
https://github.com/microsoft/recommenders/blob/d4181cf1d1df6e71f7e6b202b0875bb3bd54150c/recommenders/models/sar/sar_singlenode.py#L278-L280

When the dtype of col_rating is int, all numbers will be rounded off to the nearest integer which is not expected:

>>> import pandas as pd
>>> import numpy as np
>>> header = {
...     "col_user": "UserId",
...     "col_item": "MovieId",
...     "col_rating": "Rating",
... }
>>> ratings_dict = {
...     header["col_user"]: [1, 1, 2, 3, 3],
...     header["col_item"]: [1, 2, 1, 1, 3],
...     header["col_rating"]: [1, 2, 1, 1, 2],
... }
>>> df = pd.DataFrame(ratings_dict)
>>> df[header["col_rating"]].dtype
dtype('int64')
>>> from recommenders.models.sar import SAR
>>> model = SAR(**header, similarity_type="jaccard")
>>> model.fit(df)
>>> print(model.item_similarity)
[[1 0 0]
 [0 1 0]
 [0 0 1]]

The correct item similarity should be

[[1.         0.33333333 0.33333333]
 [0.33333333 1.         0.        ]
 [0.33333333 0.         1.        ]]

Related Issues

Checklist:

  • I have followed the contribution guidelines and code style for this project.
  • I have added tests covering my contributions.
  • I have updated the documentation accordingly.
  • This PR is being made to staging branch and not to main branch.

@simonzhaoms simonzhaoms marked this pull request as ready for review June 17, 2022 09:20
Copy link
Collaborator

@miguelgfierro miguelgfierro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@miguelgfierro miguelgfierro merged commit d88b3f1 into staging Jun 17, 2022
@miguelgfierro miguelgfierro deleted the simonz/202206171156/sar-item-similarity-dtype-correction branch June 17, 2022 10:10
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.

None yet

2 participants