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
November 29, 20260
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
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- 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 PrepSample 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 , L1 (lasso) adds . Their gradients behave differently near zero, which is the whole story....