Add epsilon to MTER progress postfix to prevent ZeroDivisionError - #723
Merged
Merged
Conversation
When every sampled BPR pair is skipped (e.g. on very small datasets where all sampled pairs have equal ratings), n_bpr_samples - skipped is 0 and computing the "correct" percentage raises ZeroDivisionError. Add + 1e-8 to the denominator, consistent with the other BPR-based models fixed in PreferredAI#677 and PreferredAI#686. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MTER.fitcan still raiseZeroDivisionErrorwhen every sampled BPR pair is skipped, because the "correct" percentage in the progress postfix divides byn_bpr_samples - skipped.#677 and #686 added
+ 1e-8to this denominator in BPR, WBPR, Companion, ComparERSub and LRPPM, butcornac/models/mter/recom_mter.pyxwas not included. This PR applies the same one-line change to MTER.Note that the postfix is computed even with
verbose=False(only the bar display is disabled), so the error also happens in non-verbose runs.Reproduction (2 users x 2 items, all rated 5.0, so every sampled pair is skipped):
Before this change:
After this change,
fitcompletes.Testing (Windows, Python 3.12, MSVC build via
python setup.py build_ext --inplace):master, passes with this change.flake8 . --select=E9,F63,F7,F82(same as CI): 0.pytest tests/cornac/models tests/cornac/data tests/cornac/eval_methods: 139 passed.Related Issues
Follow-up to #675 (fixed for BPR in #677 and for other BPR-based models in #686).
Checklist:
README.md(if you are adding a new model). (N/A)examples/README.md(if you are adding a new example). (N/A)datasets/README.md(if you are adding a new dataset). (N/A)🤖 Generated with Claude Code