Class Imbalance interview question

Preprocessing & Feature EngineeringClass ImbalanceCalibrationmedium

A retailer's click model has 200M impressions, 2M of them clicks. To cut training cost, you keep every click and 1 in 10 non-clicks, and give each kept non-click a weight of 10 in the log loss. Which statement about the resulting training set and model is correct?

  1. A21.8M rows, about 9× fewer; the click share rises to 2M / 21.8M ≈ 9.2% even with the weights, so the predicted probabilities must still be scaled down with a prior correction.
  2. BThere is no speed gain: a weight of 10 makes every kept non-click count as 10 rows, so the optimizer still processes 200M effective rows per epoch and training time is unchanged.
  3. C21.8M rows, about 9× fewer; the weight of 10 belongs on the clicks instead, because the rare class is the one that must be upweighted to keep the predicted click rate at 1%.
  4. D21.8M rows, about 9× fewer; the weighted click share is 2M / (2M + 10 × 19.8M) = 1%, so the predicted probabilities stay calibrated to the true click rate with no correction.
Show the answer and explanation

Correct answer: D, 21.8M rows, about 9× fewer; the weighted click share is 2M / (2M + 10 × 19.8M) = 1%, so the predicted probabilities stay calibrated to the true click rate with no correction.

Explanation Class Imbalance

This is the downsample-and-upweight recipe for very large, imbalanced logs:

  1. Downsample the majority class: keeping 1 in 10 of the 198M non-clicks leaves 19.8M. Training rows drop from 200M to 2M + 19.8M = 21.8M, about 9× fewer, and the majority class itself shrinks 10×.
  2. Upweight each kept majority row by the same factor, 10, in the loss.

Each kept non-click now stands in for itself and nine dropped ones, so the weighted log loss is an unbiased estimate of the loss on the full data. The weighted click share is 2M / (2M + 10 × 19.8M) = 2M / 200M = 1%, the true base rate, so the probabilities need no prior correction.

SetupRowsEffective click share
Full data200M1%
Downsample only21.8M2 / 21.8 ≈ 9.2% (probabilities inflated)
Downsample + weight 10 on kept non-clicks21.8M1%
Downsample + weight 10 on clicks21.8M20 / 39.8 ≈ 50%

Why the other statements fail: the ≈ 9.2% share describes unweighted downsampling, which does need a prior correction; the weights undo exactly that shift. A weight scales a row's contribution to the loss and gradient, but the optimizer still reads only 21.8M rows, so the speed-up is real. Upweighting the clicks instead would push the effective click share to about 50% and inflate the predictions even more.

The cost is higher gradient variance from the weighted rows, so keep the factor moderate and still check calibration on an untouched validation set.

Interview tip: "downsample for speed, upweight for calibration", and evaluate and tune thresholds on data at the real 1% click rate.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Preprocessing & Feature Engineering questions

  1. A bank vectorizes 2 million support tickets with TF-IDF over a 500,000-term vocabulary; the sparse matrix has about 100 non-zeros per row (≈ 2.4 GB in CSR…
  2. A retailer's store_id has 1,000 levels. Instead of one-hot encoding, a colleague proposes binary encoding: give each store an integer code and write that code…
  3. Your features include age (years), income (TRY) and num_logins (count), on very different scales. For which group of models is feature scaling generally…
  4. A gradient-boosted house-price model for Istanbul uses raw latitude and longitude as features. Prices are highest around a few prime districts and along the…
  5. How do MCAR, MAR and MNAR differ in what the probability of a value being missing depends on?