← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Uber ML engineer screen, basically one big coding and theory question about implementing linear regression from scratch. They wanted working code plus a real conversation about the math and edge cases, not just pseudocode.

Questions Asked (1)

Q1

Implement linear regression from scratch in code, supporting both the closed-form normal equation and gradient descent on MSE. Your implementation should include a fit method, a predict method, and handle the bias term cleanly. Be ready to discuss numerical pitfalls, collinearity, regularization, and why feature scaling matters for gradient descent.

Technical Trade-offsAlgorithms & Data StructuresSystem Design
Author's notes

This one took longer than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by outlining the class structure with fit and predict methods, then implement the closed-form solution using the normal equation with a bias trick. Next, implement gradient descent with feature scaling and monitor convergence, and finally discuss numerical pitfalls, collinearity, regularization, and scaling.

Pro tip: Demonstrate awareness of numerical stability by using np.linalg.lstsq or adding a small ridge term to the normal equation, and always standardize features before gradient descent to avoid divergence.

1. Define the class and bias handling

Create a LinearRegression class with fit and predict methods. Handle the bias term by augmenting the feature matrix with a column of ones or by maintaining a separate intercept parameter.

2. Implement closed-form solution

Use the normal equation: theta = (X^T X)^(-1) X^T y. For numerical stability, use np.linalg.lstsq or add a small regularization term.

3. Implement gradient descent

Compute gradients of MSE with respect to weights and bias, update parameters iteratively. Include a learning rate and number of iterations, and optionally track loss for convergence.

4. Address feature scaling and numerical issues

Standardize features before gradient descent to ensure convergence. Discuss collinearity and its effect on the normal equation, and mention regularization (ridge/lasso) to mitigate.

5. Discuss trade-offs and extensions

Compare closed-form vs. gradient descent in terms of complexity, scalability, and numerical stability. Mention regularization techniques and their impact on bias-variance trade-off.

Key Points to Mention

  • Normal equation: closed-form solution, O(n^3) complexity due to matrix inversion, sensitive to collinearity.
  • Gradient descent: iterative, requires feature scaling, learning rate selection, and convergence monitoring.
  • Bias term handling: augmenting X with a column of ones or separate intercept, and its effect on regularization.
  • Numerical pitfalls: ill-conditioned X^T X, use of pseudo-inverse or lstsq, and importance of scaling.
  • Collinearity: leads to unstable estimates, can be addressed with regularization or feature selection.
  • Regularization: ridge (L2) and lasso (L1) to prevent overfitting and handle collinearity, and their effect on the bias term.

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