← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Apr 2026

Summary

Uber ML engineer interview that went deep on linear regression fundamentals, both the math and the code. More involved than I expected for what sounds like a basic topic.

Questions Asked (4)

Q1

Implement linear regression from scratch, including both a closed-form solution using the normal equation and a gradient descent solution with configurable learning rate and iterations. Include a predict method.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I started with gradient descent because it felt more natural to code up, then circled back to the normal equation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and assumptions (e.g., whether to include an intercept, data shape). Then implement the LinearRegression class with fit and predict methods, using the normal equation for closed-form and gradient descent for iterative optimization. Discuss trade-offs between the two methods and validate with a simple example.

Pro tip: Mention numerical stability: for the normal equation, use np.linalg.solve instead of explicitly computing the inverse, and consider adding a small regularization term if X^T X is ill-conditioned. For gradient descent, feature scaling can dramatically improve convergence.

1. Clarify requirements and assumptions

Ask about input data format, whether to include an intercept term, and any constraints (e.g., time complexity, memory). Confirm that both methods should be implemented in the same class with a flag to choose the solver.

2. Implement closed-form solution

Use the normal equation: theta = (X^T X)^(-1) X^T y. Handle the intercept by adding a column of ones to X. Use np.linalg.solve for numerical stability.

3. Implement gradient descent

Initialize weights (zeros or small random), compute gradients of MSE loss, and update weights iteratively. Include configurable learning rate and number of iterations. Optionally add convergence check.

4. Implement predict method

Given new X, add intercept column if needed, then return X @ theta. Ensure consistent preprocessing between fit and predict.

5. Discuss trade-offs and validation

Compare computational complexity: normal equation O(n^3) due to matrix inversion, gradient descent O(k n d) per iteration. Mention when to use each (small vs large datasets, feature scaling). Validate with a simple synthetic dataset.

Key Points to Mention

  • Normal equation formula and its derivation from minimizing MSE
  • Handling the intercept term by augmenting the feature matrix with a column of ones
  • Gradient descent update rule: theta = theta - learning_rate * (1/m) * X^T (X theta - y)
  • Importance of feature scaling for gradient descent convergence
  • Computational complexity: normal equation O(n^3) vs gradient descent O(k n d)
  • Numerical stability: using np.linalg.solve instead of inv, and potential need for regularization

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

Q2

When would you prefer the closed-form normal equation solution over gradient descent, and what are the tradeoffs around large datasets, high dimensionality, and ill-conditioned matrices?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

This is where it got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the normal equation and gradient descent, then compare their computational and numerical properties. Discuss when the normal equation is preferable (small to medium datasets, low dimensionality, well-conditioned matrices) and when gradient descent is better (large datasets, high dimensionality, ill-conditioned matrices). Highlight tradeoffs in terms of time complexity, memory, and numerical stability.

Pro tip: Mention that while the normal equation is exact and avoids hyperparameter tuning, its O(n^3) inversion cost and O(n^2) memory make it impractical for high-dimensional data; gradient descent scales better but requires careful tuning and may converge to approximate solutions.

1. Define the methods

Briefly explain the closed-form normal equation (θ = (XᵀX)⁻¹Xᵀy) and gradient descent as an iterative optimization algorithm.

2. Compare computational complexity

State that the normal equation has O(n^3) time complexity due to matrix inversion and O(n^2) memory, while gradient descent is O(kn^2) per iteration (k iterations) and can handle larger datasets with mini-batch.

3. Discuss numerical stability

Explain that the normal equation can be unstable if XᵀX is ill-conditioned (near singular), leading to large errors; gradient descent is more robust but may converge slowly or get stuck.

4. Consider dataset size and dimensionality

For small n (features) and moderate m (samples), normal equation is fast and exact; for large m or n, gradient descent (especially stochastic) is preferred due to scalability.

5. Summarize tradeoffs and practical recommendations

Conclude that the choice depends on the problem: use normal equation for simplicity and exactness when n is small and XᵀX is well-conditioned; otherwise use gradient descent with regularization or iterative solvers like conjugate gradient.

Key Points to Mention

  • Time complexity: O(n^3) for normal equation vs. O(kn^2) per iteration for gradient descent.
  • Memory: normal equation requires storing XᵀX (n x n), which is prohibitive for high n.
  • Ill-conditioning: normal equation sensitive to multicollinearity; can use pseudo-inverse or regularization.
  • Gradient descent requires feature scaling and learning rate tuning, but scales to large datasets.
  • Normal equation gives exact solution (up to numerical precision) without hyperparameters.
  • For large datasets, stochastic or mini-batch gradient descent is often the only feasible option.

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

Q3

How would you add L2 (Ridge) regularization to your linear regression implementation?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Pretty comfortable here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the mathematical formulation of L2 regularization and its effect on the loss function, then describe how to modify the gradient computation and update rule. Finally, discuss implementation details like scaling, hyperparameter tuning, and trade-offs in a production setting.

Pro tip: Mention that L2 regularization is equivalent to adding a Gaussian prior on the weights in a Bayesian framework, and that it can be implemented efficiently by augmenting the design matrix—this shows depth and practical awareness.

1. Define the regularized objective

Write the modified loss function: J(w) = MSE(w) + λ * ||w||^2 (excluding the bias term). Explain that λ controls the strength of regularization.

2. Derive the gradient and update rule

Compute the gradient: ∇J(w) = (2/n) * X^T (Xw - y) + 2λw. Show that the update becomes w := w - α * (∇MSE + 2λw), which shrinks weights toward zero.

3. Implement efficiently

Describe how to add the regularization term in code, e.g., by adding λ * np.sum(w**2) to the loss and 2λw to the gradient. Mention that the bias term is typically not regularized.

4. Handle scaling and hyperparameter tuning

Emphasize that features should be standardized so that regularization penalizes all weights equally. Discuss using cross-validation to tune λ.

5. Discuss trade-offs and alternatives

Compare L2 with L1 (Lasso) and Elastic Net, and explain when L2 is preferred (e.g., when all features are useful and we want to avoid overfitting).

Key Points to Mention

  • L2 regularization adds a penalty proportional to the square of the weights, discouraging large weights.
  • The bias term is usually not regularized because it doesn't contribute to overfitting in the same way.
  • The gradient of the L2 penalty is 2λw, which leads to weight decay.
  • Feature scaling is important because L2 penalizes all weights equally.
  • λ is a hyperparameter that controls regularization strength and is tuned via cross-validation.
  • L2 regularization can be solved in closed form (Ridge regression) and is equivalent to a Gaussian prior on weights.

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

Q4

How would you evaluate the quality of your linear regression fit, and how would you distinguish between underfitting and overfitting?

Product Analytics & MetricsTechnical Trade-offs
Author's notes

Covered MSE and R-squared, talked about train vs validation error gaps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the metrics used to evaluate linear regression fit, such as R-squared, adjusted R-squared, RMSE, and residual plots. Then explain how to diagnose underfitting and overfitting by comparing training and validation performance, and discuss techniques to address each issue. Finally, tie your answer to Uber's scale and product context by mentioning the importance of generalization and business impact.

Pro tip: Emphasize that no single metric tells the whole story—combine quantitative metrics with residual analysis and domain knowledge. Also, mention that at Uber's scale, even small improvements in model fit can have significant business impact, so it's crucial to balance bias-variance trade-off with interpretability and operational constraints.

1. Define evaluation metrics

List common metrics for linear regression: R-squared, adjusted R-squared, RMSE, MAE, and residual plots. Explain what each indicates about fit quality.

2. Assess underfitting

Describe signs of underfitting: high bias, poor performance on both training and validation sets, low R-squared, and systematic patterns in residuals. Mention causes like overly simple models or insufficient features.

3. Assess overfitting

Describe signs of overfitting: high variance, excellent training performance but poor validation performance, large gap between training and validation errors, and complex models with many features relative to data points.

4. Use validation techniques

Explain how to use train/validation/test splits, cross-validation (e.g., k-fold), and learning curves to diagnose underfitting vs. overfitting.

5. Address issues and iterate

Discuss remedies: for underfitting, add features, use polynomial terms, or more complex models; for overfitting, use regularization (L1/L2), reduce features, gather more data, or simplify the model. Emphasize iterative improvement.

Key Points to Mention

  • R-squared and adjusted R-squared: interpretation and limitations
  • Residual analysis: checking for patterns, heteroscedasticity, and normality
  • Bias-variance trade-off and its role in underfitting/overfitting
  • Cross-validation techniques for reliable performance estimation
  • Regularization methods (Lasso, Ridge) to combat overfitting
  • Learning curves to visualize training vs. validation error as a function of training set size

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