← Databricks Interview Insights

Databricks·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Databricks ML engineer interview with a from-scratch coding problem on linear regression. Pretty technical, lots of follow-ups, and they had a buggy snippet ready to trip you up.

Questions Asked (4)

Q1

Implement linear regression with gradient descent from scratch, no ML libraries. Should predict y from a feature matrix X, compute MSE loss, and support a configurable learning rate with early stopping.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The MSE normalization thing is where people slip up and I almost did too.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem scope and assumptions, then outline the gradient descent algorithm with MSE loss, including weight initialization, learning rate, and early stopping. Implement the solution in a clear, modular way, and discuss trade-offs such as feature scaling, convergence criteria, and computational efficiency.

Pro tip: Mention that you would standardize features and add a bias term to improve convergence, and use vectorized operations for efficiency. Also, discuss how early stopping can prevent overfitting and save computation.

1. Clarify requirements and assumptions

Ask about data size, feature scaling, and whether to include a bias term. Confirm that early stopping is based on validation loss or gradient norm.

2. Initialize parameters and hyperparameters

Set weights to zeros or small random values, choose learning rate, and define early stopping criteria (e.g., patience, tolerance).

3. Implement gradient descent loop

Compute predictions, MSE loss, and gradients. Update weights using the learning rate. Track loss for early stopping.

4. Add early stopping and convergence checks

Monitor loss on a validation set or the training loss. Stop if improvement is below a threshold for a set number of iterations.

5. Discuss optimizations and trade-offs

Mention vectorization, feature scaling, learning rate tuning, and alternatives like stochastic gradient descent.

Key Points to Mention

  • Vectorized implementation using NumPy for efficiency
  • Feature standardization to speed up convergence
  • Adding a bias term (intercept) to the model
  • Choice of learning rate and its impact on convergence
  • Early stopping criteria: patience, tolerance, and validation set
  • Trade-offs between batch, stochastic, and mini-batch gradient descent

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

Q2

What happens to training when the learning rate is too large versus too small?

Technical Trade-offs
Author's notes

Easy enough to explain conceptually.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the learning rate's role in gradient-based optimization, then contrast the two failure modes: too large causing divergence or oscillation, too small causing slow convergence or getting stuck. Use a concrete example like training a neural network to illustrate the trade-off, and mention practical strategies for tuning the learning rate.

Pro tip: Mention that modern optimizers like Adam or learning rate schedules (e.g., cosine decay, warmup) can mitigate these issues, showing you understand real-world training pipelines. Also, note that the optimal learning rate depends on the loss landscape and batch size, demonstrating nuanced understanding.

1. Define the learning rate's purpose

Explain that the learning rate controls the step size during gradient descent, directly impacting how quickly the model converges to a minimum.

2. Describe effects of a too-large learning rate

Discuss how it can cause the loss to diverge, oscillate, or overshoot the minimum, potentially leading to NaN values or unstable training.

3. Describe effects of a too-small learning rate

Explain that it results in very slow convergence, may get stuck in local minima or plateaus, and wastes computational resources.

4. Mention practical tuning strategies

Talk about learning rate schedules (step decay, cosine annealing), adaptive optimizers (Adam, RMSprop), and techniques like learning rate range tests.

5. Conclude with the importance of balance

Summarize that the optimal learning rate is problem-dependent and often found through experimentation, balancing speed and stability.

Key Points to Mention

  • Divergence and oscillation with high learning rates
  • Slow convergence and suboptimal minima with low learning rates
  • Impact on loss landscape navigation (overshooting vs. crawling)
  • Role of batch size and its interaction with learning rate
  • Adaptive optimizers (Adam, RMSprop) and learning rate schedules
  • Practical methods: learning rate range test, grid search, or Bayesian optimization

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

Q3

How would you normalize features before running gradient descent, and why does it matter?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Talked through standardization vs min-max scaling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the standard normalization techniques (min-max scaling, standardization) and when to use each. Then discuss the impact on gradient descent convergence, particularly how feature scaling affects the shape of the cost function and the path of gradient descent. Finally, mention practical considerations like handling outliers and using normalization in pipelines.

Pro tip: Mention that normalization should be fit on the training set only and applied to validation/test sets to avoid data leakage, and that some algorithms like tree-based models don't require normalization.

1. Define normalization and its purpose

Explain that normalization scales features to a similar range, preventing features with larger scales from dominating the learning process.

2. Describe common normalization techniques

Cover min-max scaling (to [0,1]) and standardization (zero mean, unit variance), and mention when each is appropriate.

3. Explain the impact on gradient descent

Discuss how unscaled features lead to elongated cost contours, causing slow convergence and potential oscillation; normalization makes contours more spherical, speeding up convergence.

4. Address practical implementation

Mention fitting the scaler on training data only, applying to validation/test, and using pipelines to avoid data leakage.

5. Note exceptions and trade-offs

Point out that some algorithms (e.g., tree-based) are scale-invariant, and that normalization may not be necessary for all models.

Key Points to Mention

  • Feature scaling ensures all features contribute equally to the distance calculations in gradient descent.
  • Standardization (Z-score normalization) is preferred when data follows a Gaussian distribution; min-max scaling is useful when bounded range is needed.
  • Unnormalized features can cause the cost function to have elongated contours, leading to slow convergence and zigzagging path.
  • Normalization should be fit on training data only to prevent data leakage.
  • Some models like decision trees and random forests are invariant to feature scaling.
  • Batch normalization can be used in neural networks to normalize activations, but that's different from input feature normalization.

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

Q4

Here is a buggy gradient descent implementation. Find and fix the bugs.

Algorithms & Data StructuresRoot Cause Analysis
Author's notes

Three bugs in the snippet: the mean was missing from the loss, the gradient sign was flipped, and the weight update was subtracting instead of applying the scaled gradient correctly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, read the code carefully and identify the intended algorithm (gradient descent for linear regression). Then, trace through the code with a small example to spot logical errors, and finally fix each bug while explaining why it's a bug and how the fix corrects it.

Pro tip: After fixing the bugs, mention that you would add unit tests to verify the gradient computation and convergence, showing a proactive approach to code quality.

1. Understand the intended algorithm

Identify that the code should implement gradient descent for linear regression, computing predictions, gradients, and updating parameters.

2. Trace through the code

Manually simulate the code with a small dataset to observe incorrect behavior and pinpoint where the logic deviates from the expected algorithm.

3. Identify and fix bugs

For each bug, explain why it's wrong and correct it. Common bugs include incorrect gradient sign, missing division by m, wrong update rule, or misused transpose.

4. Verify the fix

Re-trace with the same example to ensure the corrected code converges to the expected solution, and discuss how to test it.

Key Points to Mention

  • Gradient descent update rule: theta = theta - alpha * (1/m) * X^T * (X * theta - y)
  • Importance of dividing by the number of training examples (m) to average the gradient
  • Correct sign in the update: subtract the gradient (not add)
  • Use of transpose for matrix multiplication compatibility
  • Learning rate (alpha) should be positive and appropriately scaled
  • Convergence check: monitor cost function or gradient norm

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