Design Ad Click Prediction
You'll learn to
- -Explain why calibration matters more for ad prediction than for most models
- -Describe how negative downsampling inflates predictions and how to correct it
- -Use normalized entropy as a metric and read it
- -List the features, data challenges, and serving constraints of a CTR model
Online ads run on a prediction: how likely is this person to click this ad right now? Every ad impression involves a model call, and the answer feeds an auction worth billions of dollars. Click prediction is also an unusually good teacher, because it forces you to deal with extreme imbalance, delayed feedback, and probabilities that must be right and not merely well ordered.
An Analogy: Pricing by Odds
An auction for an ad slot works a little like betting. The platform multiplies what an advertiser will pay per click by the chance of a click, and the ad with the highest result wins the slot. If your click estimate is twice what it should be, every ad looks twice as valuable, the wrong ads win, and the prices are wrong. That is why the number itself must be right.
The Task
For every (user, ad, context) combination, predict the probability of a click, and sometimes of a later conversion. Typical click rates are one or two percent or less, so the data is extremely imbalanced. The model is scored by an auction on hundreds of candidate ads per request, in a few milliseconds each.
Data and Features
- -User features: demographics, interests, history of clicks and purchases.
- -Ad features: the advertiser, creative, category, text and image embeddings, past performance.
- -Context: device, time, page, position of the slot.
- -Cross features: the combination of a user's interests with the ad category. These are often where the signal is.
- -High-cardinality IDs: millions of user, ad, and advertiser IDs. Use hashing or learned embeddings.
A 2014 paper from Facebook's ads team, "Practical Lessons from Predicting Clicks on Ads at Facebook", is a classic. It combines gradient boosted trees, which build useful feature combinations, with logistic regression, and reports that the combination beats either alone by more than 3%. It also stresses that the most important thing is having the right features, in particular historical information about the user and the ad, ahead of fine-tuning the model. The paper evaluates with normalized entropy and calibration, two ideas this chapter covers.
Negative Downsampling
Training on billions of impressions where 98% are non-clicks is wasteful. A common trick is to keep all clicks and only a fraction of non-clicks, say 10%. Training gets cheaper, but the model now sees clicks as ten times more common than they are, so its probabilities come out too high. The correction is a short formula: with keep rate w, the true probability is the model's probability p divided by p + (1 − p) ÷ w. The code applies it, and then computes normalized entropy. Press Run, and compare the three average click chances in the middle.
The model trained on downsampled data says an ad with a true click chance of 0.005 will be clicked with probability 0.048, nearly ten times too high. Averaged over the five ads, the true click chance is 0.031, the uncorrected model says 0.214, and after the correction it is back to 0.031. Without the correction, auction prices would be off by a large factor, even though the ranking of ads would be unchanged. Normalized entropy divides the model's log loss by the log loss of always predicting the average rate, so below 1.0 means the model beats that baseline. Here it is 0.37.
Use the demo below to see the inflation and the fix. Choose how much of the non-clicks you keep and an ad's true click chance, and compare what the model learns with the corrected score.
Downsampling Non-Clicks Inflates the Click Chance
Keep only a share of the non-clicks when training and the model learns that clicks are far more common than they are. Choose how much you keep and an ad's true click chance, then see what the model learns and what the correction restores.
True click chance
2.0%
What the model learns
16.9%
8.5x too high
After the correction
2.0%
matches the truth
Keeping 10% of the non-clicks makes a 2.0% ad look like 16.9%, 8.5 times too high. An auction that multiplies bid by this score would overpay by that factor, which is why the score must be corrected before it is used.
Other Challenges
- -Delayed feedback: a click arrives in seconds, but a purchase can take days. Use windows, wait for labels to mature, or model the delay.
- -Freshness: new ads and trends appear constantly, so models retrain often, sometimes hourly or online.
- -Position bias: top slots get more clicks. Train with position as a feature, then set it to a fixed value when scoring.
- -Exploration: new ads have no history. Reserve some impressions so they can be learned.
- -Latency: hundreds of candidate ads, a few milliseconds each. Keep features precomputed and the model compact.
Evaluation
- -Offline: log loss or normalized entropy, calibration overall and by segment, and AUC for ranking.
- -Online: A/B test on revenue and advertiser value, with guardrails on user experience, such as hides and complaints.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!