← Amazon Interview Insights

Amazon·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026Remote

Summary

Amazon ML Engineer loop, heavy on the fundamentals. The whole session was basically one long logistic regression deep dive and I was not as prepared for the math-first approach as I thought I was.

Questions Asked (10)

Q1

Walk me through logistic regression from scratch, including how you derive the loss function and the gradients.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

I started okay with the sigmoid and the likelihood setup, but when they pushed me to actually derive the gradient step by step I got a bit tangled in the chain rule notation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing logistic regression as a probabilistic binary classifier that models P(y=1|x) using the sigmoid function. Then derive the loss via maximum likelihood estimation, leading to cross-entropy, and compute gradients with respect to weights and bias. Finally, connect the gradients to gradient descent and mention practical considerations like regularization and numerical stability.

Pro tip: Emphasize the probabilistic interpretation and the convexity of the loss function, which guarantees convergence to the global minimum. Also, briefly mention how L2 regularization can be added and its effect on the gradient.

1. Model Definition

Define the logistic regression model: z = w^T x + b, and output probability p = σ(z) = 1/(1+e^{-z}). Explain that it models the log-odds as a linear function.

2. Likelihood and Loss Derivation

Write the likelihood for N independent samples: L(w,b) = ∏ p_i^{y_i} (1-p_i)^{1-y_i}. Take negative log-likelihood to get the cross-entropy loss: J(w,b) = -∑ [y_i log(p_i) + (1-y_i) log(1-p_i)].

3. Gradient Computation

Compute gradients: ∂J/∂w = ∑ (p_i - y_i) x_i, and ∂J/∂b = ∑ (p_i - y_i). Show that the gradient has a simple form due to the derivative of the sigmoid.

4. Optimization

Describe using gradient descent (or variants like SGD, Adam) to update weights: w := w - α ∂J/∂w, b := b - α ∂J/∂b. Mention that the loss is convex, ensuring convergence to global minimum.

5. Extensions and Practicalities

Briefly discuss regularization (L1/L2), handling imbalanced data, and numerical stability (e.g., using log-sum-exp trick). Mention evaluation metrics like accuracy, precision, recall, AUC-ROC.

Key Points to Mention

  • Sigmoid function and its derivative: σ'(z) = σ(z)(1-σ(z))
  • Maximum likelihood estimation and cross-entropy loss
  • Gradient derivation: ∂J/∂w = ∑ (p_i - y_i) x_i
  • Convexity of the loss function and convergence guarantees
  • Regularization (L2) and its effect on gradients
  • Practical considerations: feature scaling, class imbalance, and numerical stability

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

Q2

What is the logit link function and why does logistic regression use it?

Technical Trade-offs
Author's notes

This was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the logit link function mathematically as the log-odds, then explain its role in logistic regression: to map the linear combination of inputs to a probability between 0 and 1. Emphasize why this is necessary—linear models output unbounded values, but probabilities are bounded—and connect it to the logistic function's properties and maximum likelihood estimation.

Pro tip: Mention that the logit link is the canonical link for the Bernoulli distribution in generalized linear models, which simplifies the math and ensures convexity of the loss function, leading to efficient optimization.

1. Define the logit function

State that the logit function is the inverse of the logistic function: logit(p) = log(p/(1-p)), which takes a probability p in (0,1) and outputs a real number.

2. Explain the need for a link function

Describe that logistic regression models the probability of a binary outcome, but a linear model can output any real number, so we need a function to map the linear predictor to the [0,1] range.

3. Connect to logistic regression

Show that logistic regression assumes log-odds is a linear combination of features: log(p/(1-p)) = β0 + β1x1 + ... + βnxn, and solving for p gives the sigmoid function.

4. Discuss properties and benefits

Highlight that the logit link ensures outputs are valid probabilities, provides interpretability (coefficients represent log-odds ratios), and leads to a convex likelihood for efficient optimization.

5. Mention alternatives and context

Briefly note that other link functions (e.g., probit) exist, but logit is preferred for its mathematical convenience and interpretability in many applications.

Key Points to Mention

  • Logit function: log(p/(1-p)), the log-odds.
  • Inverse relationship with sigmoid function: p = 1/(1+e^{-z}).
  • Linear model outputs unbounded values; probabilities must be between 0 and 1.
  • Log-odds linearity assumption in logistic regression.
  • Maximum likelihood estimation and convex loss function.
  • Canonical link for Bernoulli distribution in GLMs.

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

Q3

How do you choose a decision threshold, and when would you move it away from 0.5?

Technical Trade-offsProduct Analytics & Metrics
Author's notes

I fumbled this slightly because I jumped straight to precision-recall tradeoffs without first acknowledging that 0.5 is only optimal under equal misclassification costs.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that the decision threshold is a business decision, not just a model parameter, and should be chosen to optimize a business metric like expected cost or profit. Then describe a systematic process: define the cost matrix, evaluate model performance across thresholds, and select the threshold that minimizes cost or maximizes the metric. Finally, discuss when to move away from 0.5, such as when classes are imbalanced or when false positives and false negatives have asymmetric costs.

Pro tip: Tie the threshold to a concrete business metric (e.g., expected profit per user) and mention that you would validate the chosen threshold on a holdout set and monitor it post-deployment, as the optimal threshold can drift with data distribution changes.

1. Define the business objective and cost matrix

Identify the key business metric (e.g., profit, cost, F1) and quantify the costs/benefits of true positives, false positives, true negatives, and false negatives. This translates the problem into an optimization target.

2. Evaluate model performance across thresholds

Use the validation set to compute the chosen metric (or expected cost) for a range of thresholds, typically by plotting a threshold vs. metric curve or using ROC/PR curves.

3. Select the optimal threshold

Choose the threshold that optimizes the business metric, such as minimizing expected cost or maximizing profit. This may not be 0.5, especially with imbalanced data or asymmetric costs.

4. Validate and monitor

Validate the threshold on a holdout set and set up monitoring to detect drift. Re-evaluate the threshold periodically or when the data distribution or business costs change.

Key Points to Mention

  • The default 0.5 threshold assumes equal misclassification costs and balanced classes, which is rarely true in practice.
  • Moving the threshold changes the trade-off between precision and recall (or false positive and false negative rates).
  • Cost-sensitive learning: use a cost matrix to compute expected cost at each threshold.
  • Class imbalance: with imbalanced data, the optimal threshold often shifts away from 0.5 to better detect the minority class.
  • Business impact: the threshold should align with business KPIs, such as maximizing profit or minimizing churn.
  • Threshold optimization techniques: use ROC curves, precision-recall curves, or direct optimization of the business metric.

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

Q4

What does it mean for a classifier to be well-calibrated, and how would you check it?

Technical Trade-offsProduct Analytics & Metrics
Author's notes

Talked about reliability diagrams and Brier score.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Define calibration as the alignment between predicted probabilities and observed frequencies, then explain how to check it using reliability diagrams and metrics like ECE. Emphasize the importance of calibration in decision-making, especially when probabilities inform business actions, and discuss trade-offs with discrimination metrics.

Pro tip: Mention that calibration should be evaluated on a held-out set and that it can be improved post-hoc with methods like Platt scaling or isotonic regression without affecting ranking, which is crucial for Amazon's customer-obsessed decisions.

1. Define Calibration

Explain that a well-calibrated classifier produces predicted probabilities that reflect true likelihoods (e.g., among predictions with 0.8 confidence, 80% should be correct).

2. Explain Why It Matters

Discuss how calibration impacts decision-making, especially when probabilities are used to set thresholds, allocate resources, or estimate risk, and how it complements discrimination metrics like AUC.

3. Describe Checking Methods

Outline visual and quantitative approaches: reliability diagrams (calibration curves) and metrics like Expected Calibration Error (ECE), Maximum Calibration Error (MCE), or Brier score.

4. Discuss Improvements

Mention post-hoc calibration techniques (Platt scaling, isotonic regression, temperature scaling) and the importance of using a separate calibration set.

5. Connect to Business Impact

Relate calibration to Amazon's context, such as setting thresholds for fraud detection or recommendation confidence, where miscalibration can lead to suboptimal actions.

Key Points to Mention

  • Definition: predicted probabilities match observed frequencies.
  • Reliability diagram (calibration curve) as a visual tool.
  • Expected Calibration Error (ECE) and Brier score as quantitative metrics.
  • Calibration vs. discrimination (e.g., AUC) and the trade-off.
  • Post-hoc calibration methods: Platt scaling, isotonic regression, temperature scaling.
  • Importance of evaluating calibration on a held-out set and its impact on decision-making.

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

Q5

Compare L1 and L2 regularization for logistic regression. When would you prefer one over the other?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

L1 sparsity vs L2 weight shrinkage, pretty standard.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining L1 and L2 regularization mathematically and their effects on coefficients. Then compare their properties (sparsity, robustness, computational aspects) and discuss when each is preferred based on problem characteristics. Finally, relate to logistic regression specifics and practical considerations like feature selection and multicollinearity.

Pro tip: Mention that L1 is like a Laplace prior and L2 like a Gaussian prior, and that Elastic Net combines both—showing Bayesian understanding and practical awareness. Also, note that L1 can be solved via coordinate descent or LARS, while L2 has closed-form solutions in some cases.

1. Define L1 and L2

Explain that L1 adds the sum of absolute weights to the loss, while L2 adds the sum of squared weights. Mention the regularization parameter lambda controls the strength.

2. Compare effects on coefficients

L1 drives some coefficients exactly to zero, producing sparse models and performing feature selection. L2 shrinks coefficients smoothly but rarely to zero, handling multicollinearity by distributing weight among correlated features.

3. Discuss computational and optimization aspects

L1 is non-differentiable at zero, requiring methods like coordinate descent or LARS; L2 is differentiable and can be optimized with gradient descent. L2 has a closed-form solution in linear regression, but logistic regression requires iterative methods.

4. When to prefer L1 vs L2

Prefer L1 when you need a sparse model and automatic feature selection, especially with high-dimensional data where only a few features matter. Prefer L2 when you have many small/medium effects, correlated features, or when interpretability of all features is desired.

5. Mention Elastic Net and practical tips

Elastic Net combines L1 and L2, useful when there are correlated features and you still want some sparsity. Also note that scaling features is important for both, and cross-validation should be used to tune lambda.

Key Points to Mention

  • L1 regularization (Lasso) adds penalty equal to absolute value of coefficients; L2 (Ridge) adds penalty equal to square of coefficients.
  • L1 leads to sparse solutions (feature selection), L2 leads to small but non-zero coefficients (weight shrinkage).
  • L1 is robust to outliers in features? Actually, L2 is more robust to outliers in the target? Clarify: L1 is more robust to outliers in the data? Better: L1 is more robust to outliers in the sense that it is less sensitive to extreme values? Actually, L1 loss is robust, but regularization? Stick to standard: L1 regularization can be more robust to irrelevant features due to sparsity.
  • L2 handles multicollinearity better by distributing coefficients among correlated features.
  • Computational: L1 requires special optimization (e.g., coordinate descent), L2 is easier to optimize (gradient-based).
  • Use cross-validation to tune the regularization parameter; feature scaling is essential.
  • Elastic Net combines both and can be preferred when there are correlated features and you want some sparsity.

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

Q6

How does feature scaling affect logistic regression, and what happens when you add interaction terms?

Technical Trade-offsData Modeling
Author's notes

Scaling question is easy but I've seen people forget it matters for gradient descent convergence and for comparing regularized coefficients.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that logistic regression is not scale-invariant, so feature scaling affects optimization and regularization. Then discuss how interaction terms change the feature space and the implications for scaling, model complexity, and interpretability.

Pro tip: Mention that scaling should be applied after creating interaction terms to avoid distorting their relative scales, and that regularization strength must be tuned accordingly.

1. Explain the role of scaling in logistic regression

Describe how logistic regression uses gradient-based optimization and regularization, both of which are sensitive to feature scales. Unscaled features can lead to slow convergence and biased regularization.

2. Discuss the impact of interaction terms

Interaction terms are products of original features, which can have vastly different scales. This exacerbates scaling issues and increases model complexity, risking overfitting.

3. Address scaling strategies for interaction terms

Recommend scaling features before creating interactions, or scaling the interaction terms themselves. Explain the trade-offs and the importance of consistent scaling in training and inference.

4. Cover regularization and model interpretation

Explain how scaling affects regularization penalties on coefficients, and how interaction terms complicate interpretation. Suggest using domain knowledge to select meaningful interactions.

5. Summarize best practices

Conclude with practical recommendations: always scale features, create interactions after scaling, tune regularization, and validate with cross-validation.

Key Points to Mention

  • Logistic regression is not scale-invariant due to gradient descent and regularization.
  • Feature scaling speeds up convergence and ensures fair regularization.
  • Interaction terms are products of features and can have different scales.
  • Scaling before creating interactions is generally recommended.
  • Regularization strength (e.g., L1/L2) must be adjusted when adding interactions.
  • Interaction terms increase model complexity and risk of overfitting.

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

Q7

Your training data has severe class imbalance. How do you handle it in the context of logistic regression?

Technical Trade-offsData ModelingProduct Analytics & Metrics
Author's notes

Went through resampling, class weights in the loss, and threshold adjustment.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging that class imbalance is common in real-world data and can bias logistic regression toward the majority class. Then, systematically discuss methods to handle it, including resampling, class weighting, threshold tuning, and evaluation metrics, while emphasizing the trade-offs and business context.

Pro tip: At Amazon, always tie your approach to business impact—e.g., how the cost of false negatives vs. false positives influences your choice of handling imbalance. Mention that you validate with appropriate metrics like AUC-PR or F1, not just accuracy.

1. Assess the imbalance and its impact

Quantify the class distribution and evaluate how it affects model performance and business metrics. Determine if the imbalance is severe enough to warrant intervention.

2. Choose handling techniques

Select from resampling (oversampling, undersampling, SMOTE), class weighting, or algorithmic adjustments. Consider the pros and cons of each in terms of data loss, overfitting, and computational cost.

3. Adjust decision threshold

After training, tune the probability threshold to optimize for the desired metric (e.g., recall, precision, F1) based on business costs.

4. Evaluate with appropriate metrics

Use metrics robust to imbalance such as AUC-ROC, AUC-PR, F1-score, or Matthews correlation coefficient. Avoid accuracy as a sole metric.

5. Iterate and validate

Continuously monitor performance and iterate on the approach, possibly combining methods, and validate on a hold-out set or through cross-validation.

Key Points to Mention

  • Class weighting in logistic regression (e.g., class_weight='balanced' in scikit-learn)
  • Resampling techniques: random oversampling, undersampling, SMOTE, and their trade-offs
  • Threshold tuning to balance precision and recall based on business costs
  • Evaluation metrics: AUC-PR, F1-score, recall, precision, and why accuracy is misleading
  • Potential for combining methods (e.g., SMOTE with class weights) and validating with cross-validation
  • Business context: aligning the solution with the cost of false positives vs. false negatives

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

Q8

What evaluation metrics make sense when classes are imbalanced, and why is accuracy a bad default?

Product Analytics & MetricsTechnical Trade-offs
Author's notes

Standard stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining why accuracy is misleading with imbalanced classes, using a concrete example like fraud detection. Then present a hierarchy of metrics: first threshold-independent (ROC-AUC, PR-AUC), then threshold-dependent (precision, recall, F1, balanced accuracy), and finally business-aligned metrics. Emphasize that the choice depends on the cost of false positives vs. false negatives and the specific problem.

Pro tip: Mention that PR-AUC is often more informative than ROC-AUC for highly imbalanced data because it focuses on the minority class, and relate metrics to business impact (e.g., cost savings) to show product thinking.

1. Explain why accuracy fails

Illustrate with an example: if 99% of samples are negative, a model predicting all negative gets 99% accuracy but is useless. Accuracy assumes equal misclassification costs and balanced classes.

2. Introduce threshold-independent metrics

Discuss ROC-AUC and PR-AUC. ROC-AUC can be optimistic under imbalance; PR-AUC is more sensitive to minority class performance and is preferred when the positive class is rare.

3. Cover threshold-dependent metrics

Explain precision, recall, F1-score, and balanced accuracy. These require choosing a threshold and should be selected based on whether false positives or false negatives are more costly.

4. Align with business objectives

Map metrics to business costs: e.g., in fraud detection, recall might be prioritized to catch fraud, while in spam filtering, precision might be more important to avoid false positives.

5. Recommend a combined approach

Suggest using multiple metrics (e.g., PR-AUC for model selection, precision-recall curve for threshold tuning) and validating with a hold-out set that reflects the real-world imbalance.

Key Points to Mention

  • Accuracy paradox: high accuracy can be achieved by predicting the majority class only.
  • Precision-Recall AUC (PR-AUC) is more informative than ROC-AUC for highly imbalanced datasets.
  • F1-score balances precision and recall, but assumes equal importance; consider F-beta for different weights.
  • Balanced accuracy accounts for class imbalance by averaging recall across classes.
  • Cost-sensitive metrics: assign costs to false positives and false negatives to optimize business value.
  • Threshold tuning: use precision-recall curves to select an operating point that meets business constraints.

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

Q9

How do you interpret the coefficients of a logistic regression model, and what are odds ratios?

Technical Trade-offsData Modeling
Author's notes

Exponentiated coefficients as multiplicative changes in odds.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that logistic regression models the log-odds of the positive class as a linear combination of features. Then describe how each coefficient represents the change in log-odds per unit increase in the feature, and how exponentiating gives the odds ratio. Finally, discuss interpretation in terms of odds and probabilities, and mention common pitfalls like non-linearity and confounding.

Pro tip: Emphasize that odds ratios are multiplicative and that a coefficient of 0 means no effect (OR=1), and always clarify the direction of the effect (positive/negative) and the baseline category for categorical variables. Also, mention that for rare outcomes, odds ratios approximate risk ratios, but for common outcomes, they diverge.

1. Define the logistic regression model

Explain that logistic regression predicts the probability of a binary outcome by modeling the log-odds as a linear function: log(p/(1-p)) = β0 + β1X1 + ... + βnXn.

2. Interpret a single coefficient

For a one-unit increase in feature Xi, the log-odds changes by βi, holding other features constant. This means the odds are multiplied by exp(βi).

3. Define odds ratio

The odds ratio (OR) for feature Xi is exp(βi). It represents the multiplicative change in odds for a one-unit increase in Xi. OR > 1 indicates increased odds, OR < 1 indicates decreased odds, and OR = 1 indicates no effect.

4. Relate odds to probability

While odds are not probabilities, you can convert: p = odds/(1+odds). For a given set of feature values, you can compute the predicted probability. Note that the effect of a feature on probability is not constant; it depends on the values of other features.

5. Discuss practical considerations

Mention that interpretation assumes linearity in log-odds, independence of observations, and no perfect multicollinearity. Also, for categorical variables, the odds ratio is relative to the reference category.

Key Points to Mention

  • Log-odds and odds ratio relationship: coefficient β = log(OR), OR = exp(β).
  • Interpretation of OR: e.g., OR = 1.5 means 50% increase in odds for a one-unit increase in the feature.
  • For categorical features, OR compares each level to the reference level.
  • Odds ratio vs. risk ratio: OR overestimates risk when outcome is common.
  • Confidence intervals for coefficients/odds ratios to assess significance.
  • The effect on probability is non-linear and depends on other features.

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

Q10

What are the common failure modes of logistic regression in production?

Technical Trade-offsRoot Cause AnalysisSystem Design
Author's notes

I listed separability causing coefficient explosion, feature collinearity inflating variance, distribution shift breaking calibration, and the model just not being expressive enough for nonlinear boundaries.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Structure your answer around the ML lifecycle: data, training, deployment, and monitoring. For each stage, identify common failure modes of logistic regression and explain how they manifest in production, emphasizing root causes and mitigation strategies. Conclude by discussing trade-offs and the importance of monitoring and retraining.

Pro tip: Frame failure modes in terms of business impact and tie them to Amazon's leadership principles, such as Customer Obsession and Dive Deep. Mention that logistic regression's simplicity is both a strength and a weakness—its interpretability can be misleading if assumptions are violated.

1. Data-related failures

Discuss issues like multicollinearity, missing values, outliers, and feature drift that violate logistic regression assumptions and degrade performance.

2. Model training failures

Cover problems such as overfitting/underfitting, class imbalance, and improper regularization that lead to poor generalization.

3. Deployment and serving failures

Address latency issues, scalability bottlenecks, and integration errors when deploying logistic regression models in production.

4. Monitoring and maintenance failures

Explain how lack of monitoring for data drift, concept drift, and performance degradation can cause silent failures.

5. Mitigation and trade-offs

Summarize strategies to detect and mitigate these failures, and discuss trade-offs between simplicity, interpretability, and performance.

Key Points to Mention

  • Multicollinearity leading to unstable coefficient estimates
  • Class imbalance causing biased predictions toward majority class
  • Feature scaling issues affecting convergence and regularization
  • Data drift and concept drift degrading model performance over time
  • Overfitting due to too many features or insufficient regularization
  • Latency and throughput challenges when serving high-dimensional models

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