Contrast L1 and L2 Regularization for a Sparse Product Classifier

Last updated: November 29, 2026

Quick Overview

Explain the difference between L1 and L2 regularization, why L1 produces sparse weights, and which you would use for a logistic regression that classifies products into hazmat or non-hazmat from 200,000 text features.

Amazon
Machine Learning
Machine Learning Engineer
Amazon
November 29, 2026
Machine Learning Engineer
Phone Screen
Machine Learning
Easy

0

0

0 solved


Explain the difference between L1 and L2 regularization, why L1 produces sparse weights, and which you would use for a logistic regression that classifies products into hazmat or non-hazmat from 200,000 text features.

Hazardous materials classification matters for Amazon fulfillment and shipping compliance. This question checks a foundational concept and whether the candidate can connect it to a practical sparse, high-dimensional text problem.

What the Interviewer Expects
  • Writes both penalized objectives correctly
  • Explains sparsity geometrically or through the subgradient at zero
  • Explains L2 shrinkage and its behavior with correlated features
  • Mentions elastic net as a combination
  • Recommends choosing the penalty strength by validation
Key Topics to Cover
L1 regularization
L2 regularization
sparsity
elastic net
high-dimensional text
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • Why does L1 pick one of two correlated features arbitrarily?
  • How does the Bayesian view relate L1 and L2 to priors?
  • Should the intercept be regularized?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Ask the number of examples (perhaps 500,000 labeled products), whether interpretability matters for compliance auditors, and the serving constraints....

Approach

Both add a penalty to the log loss. L2 (ridge) adds λ∑jwj2\lambda \sum_j w_j^2, L1 (lasso) adds λ∑j∣wj∣\lambda \sum_j |w_j|. Their gradients behave differently near zero, which is the whole story....


Submit Your Answer
Markdown supported