← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026

Summary

Amazon data scientist interview that went heavy on regularization theory. Four questions, all interconnected, and the depth expected was not what I anticipated going in.

Questions Asked (4)

Q1

Write out the objective functions for linear and logistic regression using L0, L1, L2, and L-infinity penalties, in both the constrained form and the penalized form. For each penalty, what coefficient patterns do you expect and how hard is it to optimize?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

This is where I started sweating.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the general objective function for linear regression (squared error) and logistic regression (log-loss), then systematically add each penalty term in both constrained and penalized forms. For each penalty, describe the expected coefficient patterns (e.g., sparsity, shrinkage, grouping) and discuss optimization challenges (convexity, computational complexity, non-differentiability).

Pro tip: Emphasize that L0 is non-convex and NP-hard, L1 induces sparsity and is convex but non-smooth (use proximal methods), L2 is smooth and convex (closed-form for linear), and L∞ promotes grouping and is convex but non-smooth. Also note that in practice, L1 and L2 are most common, and elastic net combines them.

1. Define base objective functions

Write the unregularized objective for linear regression (mean squared error) and logistic regression (negative log-likelihood).

2. Add penalties in penalized form

For each penalty (L0, L1, L2, L∞), add λ times the penalty term to the base objective, resulting in the penalized form.

3. Convert to constrained form

For each penalty, express the equivalent constrained optimization problem where the penalty is replaced by a constraint on the norm (e.g., ||β||_p ≤ t).

4. Analyze coefficient patterns

Describe how each penalty affects the coefficients: L0 gives sparsity (subset selection), L1 gives sparsity and shrinkage, L2 gives shrinkage but no sparsity, L∞ gives grouping and shrinkage.

5. Discuss optimization difficulty

For each penalty, comment on convexity, smoothness, and computational complexity: L0 is non-convex and NP-hard; L1 is convex but non-smooth (use subgradient or proximal methods); L2 is convex and smooth (closed-form for linear); L∞ is convex but non-smooth (can be reformulated as linear constraints).

Key Points to Mention

  • Linear regression objective: (1/2n)||y - Xβ||²; Logistic regression objective: -∑[y_i log(σ(X_iβ)) + (1-y_i) log(1-σ(X_iβ))]
  • Penalized form: base objective + λ * penalty; Constrained form: minimize base objective subject to penalty ≤ t
  • L0 penalty: ||β||_0 = number of non-zero coefficients; leads to best subset selection; non-convex, NP-hard
  • L1 penalty: ||β||_1 = sum |β_j|; leads to sparse solutions; convex but non-differentiable at zero; use LARS or proximal gradient
  • L2 penalty: ||β||_2² = sum β_j²; leads to shrinkage but no sparsity; convex and smooth; closed-form solution for linear regression
  • L∞ penalty: ||β||_∞ = max |β_j|; leads to grouping effect; convex but non-smooth; can be solved via linear programming or quadratic programming with constraints

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

You have a dataset where two groups of predictors are highly collinear and there are a few outliers in both the features and the target. Which regularization penalty would you choose, and how would you think about elastic net mixing?

Technical Trade-offsData Modeling
Author's notes

Probably the best question in the set.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the problem: collinearity among predictors and outliers in both features and target. Then discuss why plain L1 or L2 may be insufficient, and propose elastic net as a balanced solution. Explain how to tune the mixing parameter (l1_ratio) based on the relative importance of sparsity vs. grouping and robustness to outliers.

Pro tip: Emphasize that elastic net's L1 component handles collinearity by selecting one variable from a group, while the L2 component stabilizes the solution; also mention that outliers may require robust preprocessing or a robust loss function, as regularization alone doesn't address outliers.

1. Identify the challenges

Acknowledge that collinearity makes coefficient estimates unstable and outliers can distort the loss function, leading to poor generalization.

2. Evaluate regularization options

Compare L1 (lasso) for sparsity, L2 (ridge) for grouping, and elastic net as a hybrid that can handle both collinearity and feature selection.

3. Choose elastic net and justify

Explain that elastic net is preferable because it combines L1 and L2 penalties, providing both variable selection and coefficient shrinkage, which is beneficial with collinear groups.

4. Tune the mixing parameter

Discuss how to set the l1_ratio (e.g., via cross-validation) to balance sparsity and grouping; consider domain knowledge and the need for interpretability.

5. Address outliers

Mention that regularization alone doesn't solve outliers; consider robust scaling, outlier detection, or using a robust loss function in conjunction with elastic net.

Key Points to Mention

  • Collinearity leads to unstable estimates; elastic net's L2 component encourages grouping of correlated features.
  • L1 component performs feature selection, which can reduce the impact of collinear noise.
  • Elastic net is particularly useful when the number of predictors exceeds the number of observations or when there are groups of correlated predictors.
  • The mixing parameter (l1_ratio) controls the trade-off; tune it via cross-validation, considering the problem's need for sparsity vs. stability.
  • Outliers in features and target can be mitigated by robust preprocessing (e.g., winsorizing, robust scaling) or by using a robust loss function (e.g., Huber loss) with regularization.
  • Regularization does not inherently handle outliers; it's important to address them separately to avoid biased coefficients.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Compare linear regression and logistic regression. Write out the model formulas including the link function and the conditional distribution each assumes, and explain when using linear regression for a classification task is actually a problem.

Technical Trade-offsData Modeling
Author's notes

Felt straightforward but I second-guessed myself on the conditional distribution wording.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining both models with their formulas, link functions, and assumed conditional distributions. Then contrast their outputs and loss functions, and finally explain why linear regression is problematic for classification, covering both practical and theoretical issues.

Pro tip: Mention that logistic regression can be derived from a generalized linear model with a Bernoulli distribution and logit link, and that using linear regression for classification violates key assumptions and can produce nonsensical probabilities.

1. Define Linear Regression

State the model formula: y = Xβ + ε, where ε ~ N(0, σ²). The link function is identity, and the conditional distribution of y given X is Normal.

2. Define Logistic Regression

State the model formula: log(p/(1-p)) = Xβ, where p = P(y=1|X). The link function is logit, and the conditional distribution is Bernoulli.

3. Compare Outputs and Loss Functions

Linear regression predicts continuous values and minimizes squared error; logistic regression predicts probabilities and minimizes log-loss (cross-entropy).

4. Explain Problems with Linear Regression for Classification

Discuss issues: predictions outside [0,1], violation of normality and homoscedasticity assumptions, sensitivity to outliers, and inappropriate loss function leading to poor probability estimates.

5. Summarize When to Use Each

Conclude that linear regression is for continuous outcomes, while logistic regression is for binary classification, and mention extensions like multinomial logistic regression.

Key Points to Mention

  • Linear regression assumes a continuous outcome with normal errors; logistic regression assumes a binary outcome with Bernoulli distribution.
  • Link functions: identity for linear regression, logit for logistic regression.
  • Linear regression can predict probabilities outside [0,1], which is invalid.
  • Logistic regression uses maximum likelihood estimation, while linear regression uses ordinary least squares.
  • Using linear regression for classification violates assumptions of normality and homoscedasticity, leading to inefficient and biased estimates.
  • Logistic regression provides well-calibrated probabilities and is interpretable via odds ratios.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How does feature scaling interact with L1 and L2 regularization, and what goes wrong if you skip it?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Short answer but easy to get sloppy on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that L1 and L2 regularization add a penalty proportional to the magnitude of coefficients, so the scale of features directly affects the penalty. Then discuss how skipping scaling causes the regularization to penalize features unevenly, leading to suboptimal models. Finally, emphasize that scaling ensures fair regularization and better convergence.

Pro tip: Mention that while tree-based models are invariant to feature scaling, linear models with regularization are not, and at Amazon, where both are used, it's crucial to know when scaling matters. Also, note that scaling should be fit on training data only to avoid data leakage.

1. Define feature scaling and regularization

Briefly define feature scaling (e.g., standardization, normalization) and L1/L2 regularization (Lasso/Ridge) as penalties on coefficient magnitudes.

2. Explain the interaction

Describe how the penalty term in the loss function is applied to coefficients, which are estimated on the scaled features. If features are on different scales, the coefficients will be on different scales, so the penalty affects them unequally.

3. Consequences of skipping scaling

Detail what goes wrong: features with larger scales get smaller coefficients (to compensate), so they are penalized less, while features with smaller scales get larger coefficients and are penalized more. This biases the model and can lead to poor performance.

4. Impact on optimization

Mention that unscaled features can cause slow convergence in gradient-based optimization, especially with regularization, as the loss surface becomes elongated.

5. Best practices

Conclude with best practices: always scale features before applying regularization, use pipelines to avoid data leakage, and note that tree-based models are an exception.

Key Points to Mention

  • L1 regularization promotes sparsity, L2 shrinks coefficients; both are sensitive to feature scale.
  • Without scaling, regularization penalizes features unevenly, effectively ignoring some features or over-penalizing others.
  • Coefficient magnitudes are not comparable across features with different scales.
  • Gradient descent convergence is slower without scaling, especially with regularization.
  • Scaling should be fit on training data only and applied to validation/test data to prevent leakage.
  • Tree-based models (e.g., Random Forest, XGBoost) are invariant to feature scaling, but linear models are not.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.