Skip to content

Add IPS-weighted RBP (#1155) - #1182

Open
vvineis wants to merge 1 commit into
lenskit:mainfrom
vvineis:ips-weighted-rbp
Open

Add IPS-weighted RBP (#1155)#1182
vvineis wants to merge 1 commit into
lenskit:mainfrom
vvineis:ips-weighted-rbp

Conversation

@vvineis

@vvineis vvineis commented Aug 6, 2026

Copy link
Copy Markdown

Adds IPS-weighted RBP (#1155), following Yang et al., "Unbiased Offline Recommender Evaluation for Missing-Not-At-Random Implicit Feedback" (RecSys 2018).

The metric is IPSRBP. It uses the paper's self-normalized estimator (SNIPS, their eqn. 9) by default; self_normalized=False drops the denominator and gives the plain IPS numerator. Propensities come from a PropensityModel passed to the constructor: PopularityPropensity implements their eqn. 15, UniformPropensity is the missing-at-random baseline, and FieldPropensity reads them off a field if you estimated them yourself. There's also estimate_power_law_gamma, which fits the exponent from a set of recommendations the way they do in section 4.3.

I put the propensities in a separate object rather than as arguments on the metric, partly to follow MeanPopRank and ListGini taking a Dataset, and partly because it mirrors RankWeight. IPS-corrected Recall or DCG should then just be a matter of reusing it.

A few choices:

  • gamma is the paper's exponent, so the (gamma+1)/2 of eqn. 15 happens inside the propensity model and values from their Table 2 can be used as-is. It has no default, since it depends on the dataset and on whatever produced the log.
  • The paper only pins propensities up to a constant. I normalize by the most popular item, so P lands in (0, 1] and weights are at least 1. It makes no difference under SNIPS, but the unnormalized form needs a fixed scale.

Tests

Two identities tie the metric to the existing one, both checked with Hypothesis over random lists, cutoffs and patience values:

  • uniform propensities with self_normalized=False is exactly RBP
  • uniform propensities with SNIPS is exactly the paper's average-over-all evaluator (eqn. 6), which for RBP works out to RBP / |S*_u|

I also checked both per user on ml-latest-small and they hold to machine precision.

There's also a small simulated MNAR log where the true reward of eqn. 1 is known: the uncorrected evaluator overstates a popularity-chasing recommender and the correction pulls it back, while on a missing-at-random log the correction leaves the score alone.

One thing I didn't do

The docstrings cite yangUnbiasedOfflineRecommender2018, which isn't in docs/lenskit.bib yet.

@inproceedings{yang2018unbiased,
title={Unbiased offline recommender evaluation for missing-not-at-random implicit feedback},
author={Yang, Longqi and Cui, Yin and Xuan, Yuan and Wang, Chenyang and Belongie, Serge and Estrin, Deborah},
booktitle={Proceedings of the 12th ACM conference on recommender systems},
pages={279--287},
year={2018}
}

@mdekstrand mdekstrand self-assigned this Aug 6, 2026
@mdekstrand mdekstrand linked an issue Aug 6, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.77465% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.63%. Comparing base (024fc7b) to head (de8fb82).

Files with missing lines Patch % Lines
src/lenskit/metrics/ranking/_propensity.py 94.68% 5 Missing ⚠️
src/lenskit/metrics/ranking/_ips.py 97.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1182      +/-   ##
==========================================
+ Coverage   89.58%   89.63%   +0.05%     
==========================================
  Files         262      264       +2     
  Lines       17405    17547     +142     
==========================================
+ Hits        15593    15729     +136     
- Misses       1812     1818       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mdekstrand mdekstrand added this to the 2026.4 milestone Aug 6, 2026
@mdekstrand

Copy link
Copy Markdown
Member

Will provide a more detailed review tomorrow or Monday, but I just cut the 2026.3 release, so this will be targeted for 2026.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add IPS-weighted RBP

2 participants