KatInterview

Rescuing a Rare-Event Image Flagger That Predicts Only "Safe"

Machine LearningModel answer
HardModel answerMachine Learningimbalanced-datalogistic-regressioncategorical-encoding

Last updated

A logistic regression flagger for rare harmful uploads shows high accuracy but no detections, sparse ID features, and uneven regional quality. Lay out a plan to diagnose and repair it.

Scenario

Your team is building a trust-and-safety classifier that decides whether an uploaded image breaks content policy. The training set holds 1 million labeled images. The label is_violation is 1 for a violation and 0 for a safe image, and only 0.5% of images are violations.

The first version is a logistic regression trained on:

  • raw pixel intensities, and
  • a few metadata fields, such as upload_location and device_id.

Observed problems

  1. Reported accuracy is 99.5%, yet the model flags no violating images.
  2. device_id has thousands of distinct values, so the encoded feature matrix is extremely sparse.
  3. Stakeholders report that quality is clearly worse for uploads from certain regions.

What to deliver

Describe a complete plan to diagnose and improve the model. Cover:

  1. How you would resolve the zero-recall behavior and which evaluation metrics you would adopt instead of accuracy.
  2. How you would treat high-cardinality categorical features such as device_id.
  3. How you would investigate and reduce the performance gap across regions, including how you would tell a proxy-feature effect from a genuine data problem.
  4. How you would scale and transform the features so that logistic regression trains stably and converges.

Explain your reasoning and trade-offs, and say what you would check first.

Hints

Hint 1

Compute what a model that always answers 'safe' would score on accuracy, then think about a metric that does not depend on a threshold (for example, average precision) to find out whether the model ranks positives well at all.

Hint 2

A device seen three times with one violation should not be trusted as a 33% risk. Think about shrinkage toward the global rate, computing encodings without using a row's own label, and whether the feature is just a stand-in for region.

Hint 3

Before mitigating the regional gap, slice the evaluation by region with confidence intervals, then retrain without the suspect features and with content-only features to separate proxy effects from data coverage or label-quality issues.

Hint 4

Raw pixels are a poor input for a linear model: they are highly correlated and carry no semantic structure. Consider pretrained image embeddings, scaling fitted on training data only, regularization, and an appropriate solver.