19/31
Part 5 of 6 · Position bias and IPSLearn and do

Inverse propensity scoring divides each click by its chance of being seen

If you know how often each position gets a look, you can correct for it.

def ips_relevance(
    clicks: np.ndarray, positions: np.ndarray, propensity: np.ndarray
) -> float:
    """The click rate, with each click divided by its chance of being seen."""
    clicks = np.asarray(clicks, dtype=float)
    # per impression
    p = np.asarray(propensity)[np.asarray(positions)]
    return float(np.mean(clicks / p))

rng = np.random.default_rng(0)
propensity = np.array([1.0, 0.6, 0.35, 0.2])
positions = rng.integers(0, 4, size=200_000)
clicks = (rng.random(positions.size) < propensity[positions] * 0.3).astype(float)
print(round(clicks.mean(), 4))
print(round(ips_relevance(clicks, positions, propensity), 4))
Predict

200,000 impressions, and the raw click rate is 0.1617. Every click was drawn at 0.3 times its chance of a look. What does IPS estimate?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

Raw click rates by position are 0.30, 0.18, 0.11 and 0.06. What are they after dividing by each position's chance of a look?

Pick one to see what it prints.
Pick an answer above to see the rest