← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Amazon data scientist technical screen, pretty deep on ML fundamentals. The whole session was basically one long gradient descent question that kept branching into regularization and learning rate theory. Felt like a math exam more than a job interview.

Questions Asked (4)

Q1

Write vectorized pseudocode for batch gradient descent to fit a linear regression model with an intercept term using mean squared error. Walk through each variable and step clearly, including inputs, outputs, and the update rule derived from the cost function.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This felt manageable at first but the 'clearly explain each step and variable' part is where I started rambling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the linear regression model with an intercept and the mean squared error cost function. Then derive the gradient update rule using vectorized operations, and present clear pseudocode with well-defined inputs, outputs, and initialization. Walk through each step, explaining the dimensions and roles of variables.

Pro tip: Emphasize vectorization for efficiency and mention that adding a column of ones to the feature matrix simplifies handling the intercept term. Also, briefly discuss convergence criteria and learning rate selection to show practical awareness.

1. Define Model and Cost Function

State the linear regression model with intercept: h(x) = θ0 + θ1*x1 + ... + θn*xn, and the mean squared error cost function J(θ) = (1/(2m)) * sum((h(x_i) - y_i)^2).

2. Derive Gradient Update Rule

Compute the partial derivatives of J(θ) with respect to each parameter, yielding the update rule: θ_j := θ_j - α * (1/m) * sum((h(x_i) - y_i) * x_ij), where x_i0 = 1 for the intercept.

3. Vectorize the Computation

Express the model predictions as X * θ (where X is the design matrix with a column of ones), the error as predictions - y, and the gradient as (1/m) * X^T * error. This avoids explicit loops.

4. Write Pseudocode with Inputs/Outputs

Outline the algorithm: Inputs: X (m x (n+1)), y (m x 1), α, num_iterations. Initialize θ (n+1 x 1) to zeros. For each iteration: compute predictions, error, gradient, and update θ. Output: θ.

5. Explain Variables and Convergence

Clarify each variable's role and dimensions, and mention convergence checks (e.g., gradient norm threshold) and the effect of learning rate α.

Key Points to Mention

  • Design matrix X with a column of ones to incorporate the intercept term.
  • Vectorized gradient computation: gradient = (1/m) * X^T * (X * θ - y).
  • Simultaneous update of all parameters θ_j in each iteration.
  • Learning rate α controls step size; too large may diverge, too small converges slowly.
  • Convergence criteria: fixed number of iterations or gradient norm below a threshold.
  • Computational efficiency of vectorization over loops, especially for large datasets.

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

Q2

Describe at least two stopping criteria for gradient descent and explain when you would prefer one over the other.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Said max iterations and gradient norm below tolerance, which is correct.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining two common stopping criteria: convergence of the gradient norm and early stopping based on validation error. Then compare their trade-offs, explaining when each is preferable based on computational resources, risk of overfitting, and problem characteristics.

Pro tip: Mention that in practice, a combination of criteria (e.g., gradient norm plus a maximum number of iterations) is often used to balance efficiency and robustness, and relate it to Amazon's customer-obsessed, frugal innovation principles.

1. Define the criteria

Clearly state two stopping criteria: (1) gradient norm below a threshold, and (2) early stopping based on validation error. Briefly explain each.

2. Explain when to prefer gradient norm

Discuss scenarios where gradient norm is preferred: convex or well-conditioned problems, when computational resources are abundant, or when you need a precise solution.

3. Explain when to prefer early stopping

Discuss scenarios where early stopping is preferred: large datasets, risk of overfitting, limited computational budget, or when validation performance is the ultimate goal.

4. Compare trade-offs

Highlight the trade-offs: gradient norm ensures convergence but may be slow; early stopping prevents overfitting but may stop prematurely if validation set is noisy.

5. Conclude with practical recommendation

Suggest that often a combination is used, and mention how the choice aligns with business objectives and constraints.

Key Points to Mention

  • Gradient norm threshold: stop when ||∇f|| < ε, ensures proximity to a stationary point.
  • Early stopping: monitor validation error and stop when it stops improving, prevents overfitting.
  • Computational cost: gradient norm may require many iterations; early stopping can save time.
  • Overfitting risk: early stopping is crucial for high-variance models; gradient norm doesn't address overfitting.
  • Problem type: convex vs. non-convex, smooth vs. noisy gradients.
  • Combination of criteria: e.g., stop when either gradient norm is small or validation error increases, with a max iteration cap.

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 learning rate for gradient descent, and what are the tradeoffs between a constant rate versus a time-decayed schedule? How does feature scaling affect convergence?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

The feature scaling part saved me here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the role of the learning rate in gradient descent and how it affects convergence. Then compare constant versus time-decayed schedules, highlighting tradeoffs such as speed, stability, and final accuracy. Finally, discuss how feature scaling impacts convergence and why it's crucial for effective learning.

Pro tip: Mention that adaptive methods like Adam or RMSprop can automatically adjust learning rates, but understanding manual schedules is still important for fine-tuning and diagnosing issues. Also, emphasize that feature scaling ensures all features contribute equally and prevents zigzagging in the loss landscape.

1. Explain the learning rate's role

Describe how the learning rate controls the step size in gradient descent, affecting convergence speed and stability. A too-large rate can cause divergence, while a too-small rate leads to slow convergence.

2. Compare constant vs. time-decayed schedules

Discuss that a constant rate is simple but may oscillate or converge slowly, while a time-decayed schedule (e.g., step decay, exponential decay) can help converge faster initially and settle into a minimum later.

3. Highlight tradeoffs

Explain that constant rates require careful tuning and may not adapt to different phases of training, whereas decayed schedules introduce hyperparameters (decay rate, steps) but can improve final accuracy and stability.

4. Discuss feature scaling's impact

Explain that feature scaling (e.g., standardization, normalization) ensures all features have similar scales, which helps gradient descent converge faster and more reliably by making the loss surface more spherical.

5. Connect to practical considerations

Mention that in practice, techniques like batch normalization, adaptive optimizers, and learning rate schedules are often combined. Also, note that feature scaling is especially important when features have different units or ranges.

Key Points to Mention

  • Learning rate too high causes divergence; too low causes slow convergence.
  • Constant learning rate is simple but may oscillate or get stuck; decayed schedules can improve convergence and final performance.
  • Common decay schedules: step decay, exponential decay, cosine annealing.
  • Feature scaling (e.g., standardization) makes the loss surface more symmetric, reducing zigzagging and speeding up convergence.
  • Adaptive optimizers (Adam, RMSprop) adjust learning rates per parameter, but still benefit from feature scaling.
  • Tradeoffs: constant rate requires less hyperparameter tuning but may not adapt; decayed schedules need more tuning but can yield better results.

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

Q4

Modify the mean squared error cost function to include L2 regularization, excluding the intercept term. Write the new gradient and explain how you would choose the regularization strength.

Technical Trade-offsData Modeling
Author's notes

Wrote the gradient out fine, the intercept exclusion is a small but important detail and I remembered it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by writing the standard MSE cost function, then add the L2 penalty term (λ/2 * sum of squared weights, excluding the intercept). Derive the gradient by differentiating the penalized cost with respect to each parameter, ensuring the intercept gradient remains unregularized. Finally, discuss how to choose λ using cross-validation and the bias-variance trade-off.

Pro tip: Emphasize that excluding the intercept from regularization is crucial because penalizing it would make the model unnecessarily dependent on the mean of the target, especially when features are not centered. Also, mention that the factor of 1/2 in the penalty simplifies the gradient derivation.

1. Write the standard MSE cost function

Define the mean squared error for linear regression: J(w, b) = (1/2m) * sum_{i=1}^m (h_w,b(x^(i)) - y^(i))^2, where h_w,b(x) = w^T x + b. Clarify that m is the number of training examples.

2. Add L2 regularization excluding the intercept

Modify the cost to J_reg(w, b) = J(w, b) + (λ/2) * sum_{j=1}^n w_j^2, where n is the number of features. Note that the intercept b is not included in the penalty term.

3. Derive the gradients

Compute the gradient with respect to w_j: ∂J_reg/∂w_j = (1/m) * sum_{i=1}^m (h_w,b(x^(i)) - y^(i)) * x_j^(i) + λ w_j. For the intercept: ∂J_reg/∂b = (1/m) * sum_{i=1}^m (h_w,b(x^(i)) - y^(i)).

4. Explain how to choose λ

Describe using k-fold cross-validation to evaluate a range of λ values (e.g., logarithmically spaced) and select the one that minimizes validation error. Discuss the bias-variance trade-off: larger λ increases bias but reduces variance.

5. Mention practical considerations

Note that feature scaling is important when using regularization, and that λ is a hyperparameter that controls the strength of regularization. Optionally, mention that the intercept can be excluded by centering the data.

Key Points to Mention

  • L2 regularization adds a penalty proportional to the square of the weights, excluding the intercept.
  • The gradient of the regularized cost includes an additional term λ w_j for each weight, but no additional term for the intercept.
  • The factor of 1/2 in the penalty simplifies the derivative to λ w_j.
  • Choosing λ via cross-validation balances underfitting and overfitting.
  • Feature scaling is recommended before applying regularization to ensure fair penalization.
  • Excluding the intercept prevents penalizing the model's baseline prediction, which is important when features are not centered.

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