Skip to content

Commit 9e16f46

Browse files
Shxiaoclaude
andauthored
Add epsilon to MTER progress postfix to prevent ZeroDivisionError (#723)
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 #677 and #686. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 86da29c commit 9e16f46

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎cornac/models/mter/recom_mter.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class MTER(Recommender):
419419
progress.set_postfix({
420420
"loss": "%.2f" % (loss / 3 / self.n_element_samples),
421421
"bpr_loss": "%.2f" % (bpr_loss / self.n_bpr_samples),
422-
"correct": "%.2f%%" % (100.0 * correct / (self.n_bpr_samples - skipped)),
422+
"correct": "%.2f%%" % (100.0 * correct / (self.n_bpr_samples - skipped + 1e-8)),
423423
"skipped": "%.2f%%" % (100.0 * skipped / self.n_bpr_samples)
424424
})
425425

0 commit comments

Comments
 (0)