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

Replace pandas.Series.map() in SAR #1023

Conversation

zegerius
Copy link
Contributor

Description

pandas' map() implementation is notoriously slow (see related issue for statistics). By replacing this with a stdlib implementation, we see significant improvements.

With a makeshift benchmark on the test suite (n=10) using pytest -s tests/unit/test_sar_singlenode.py --durations=0 shows an improvement.

new impl    | pandas impl | diff
------------+-------------+-----------------------------------------------------------------
0.93s setup | 0.95s setup | -3%     tests/unit/test_sar_singlenode.py::test_sar_item_similarity[1-cooccurrence-count]
0.54s call  | 0.61s call  | -11%    tests/unit/test_sar_singlenode.py::test_sar_item_similarity[1-lift-lift]
0.48s call  | 0.51s call  | -6%     tests/unit/test_sar_singlenode.py::test_sar_item_similarity[3-jaccard-jac]
0.46s call  | 0.46s call  | 0       tests/unit/test_sar_singlenode.py::test_sar_item_similarity[3-lift-lift]
0.45s call  | 0.45s call  | 0       tests/unit/test_sar_singlenode.py::test_sar_item_similarity[1-jaccard-jac]
0.40s call  | 0.41s call  | -2%     tests/unit/test_sar_singlenode.py::test_sar_item_similarity[3-cooccurrence-count]
0.37s call  | 0.38s call  | -3%     tests/unit/test_sar_singlenode.py::test_sar_item_similarity[1-cooccurrence-count]
0.27s call  | 0.34s call  | -23%    tests/unit/test_sar_singlenode.py::test_recommend_k_items[3-cooccurrence-count]
0.26s call  | 0.27s call  | -4%     tests/unit/test_sar_singlenode.py::test_recommend_k_items[3-jaccard-jac]
0.26s call  | 0.26s call  | 0       tests/unit/test_sar_singlenode.py::test_user_affinity
0.25s call  | 0.25s call  | 0       tests/unit/test_sar_singlenode.py::test_recommend_k_items[3-lift-lift]
0.03s call  | 0.03s call  | 0       tests/unit/test_sar_singlenode.py::test_get_item_based_topk
0.02s call  | 0.02s call  | 0       tests/unit/test_sar_singlenode.py::test_get_normalized_scores
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_fit[lift-True]
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_predict[lift-True]
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_predict[jaccard-False]
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_predict_all_items
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_get_popularity_based_topk
0.01s call  | 0.01s call  | 0       tests/unit/test_sar_singlenode.py::test_fit[jaccard-False]

This PR also solves some trailing spaces (thanks VSC).

Related Issues

#1022

Checklist:

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

Copy link
Collaborator

@yueguoguo yueguoguo left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @zegerius for the improvement!

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.

this is awesome! thanks

@miguelgfierro miguelgfierro merged commit 1802957 into recommenders-team:staging Jan 1, 2020
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.

3 participants