← Capital One Interview Insights

Capital One·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Capital One ML Engineer interview with a meaty coding round focused on implementing linear regression from scratch. No sklearn allowed, which sounds fine until you actually have to remember the math under pressure.

Questions Asked (2)

Q1

Implement linear regression from scratch using NumPy. Include both the closed-form solution and a gradient descent implementation, and walk through trade-offs between the two approaches.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The closed-form part went fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem setup and assumptions, then implement the closed-form solution using the normal equation with NumPy. Next, implement gradient descent, ensuring proper feature scaling and convergence checks. Finally, compare the two methods in terms of computational complexity, numerical stability, and scalability, and discuss when each is preferable.

Pro tip: Mention that while the closed-form solution is exact, it requires inverting a matrix which can be unstable if features are collinear; adding a small regularization term (ridge) can help. Also, highlight that gradient descent can be extended to online learning and large-scale data.

1. Clarify assumptions and setup

State that you assume a linear relationship with additive Gaussian noise, and that you will include an intercept term by augmenting the feature matrix with a column of ones.

2. Implement closed-form solution

Derive the normal equation: theta = (X^T X)^(-1) X^T y. Implement using NumPy's linalg.inv or preferably linalg.solve for numerical stability, and handle potential singularity with pseudo-inverse or regularization.

3. Implement gradient descent

Initialize parameters, compute gradients of MSE loss, and update iteratively. Emphasize feature scaling, learning rate selection, and convergence monitoring (e.g., loss change threshold).

4. Compare trade-offs

Discuss computational complexity: closed-form O(n^3) due to matrix inversion vs. gradient descent O(k n^2) per iteration. Mention numerical stability, memory usage, and suitability for large datasets or streaming data.

5. Conclude with practical recommendations

Summarize when to use each: closed-form for small to medium datasets with well-conditioned features; gradient descent for large-scale, online, or when feature count is high.

Key Points to Mention

  • Normal equation derivation and its computational complexity O(n^3).
  • Gradient descent update rule and importance of feature scaling for convergence.
  • Numerical stability issues with matrix inversion (e.g., multicollinearity) and use of pseudo-inverse or regularization.
  • Trade-offs: closed-form is exact but not scalable; gradient descent is scalable but requires tuning and may converge to approximate solution.
  • Extensions: stochastic gradient descent for online learning, regularization (ridge/lasso) to handle overfitting.
  • Evaluation metrics: MSE, R-squared, and residual analysis to validate assumptions.

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

Q2

How do you handle the bias term, feature scaling, and ridge regularization when building linear regression from scratch?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Bias term I got right immediately, just prepend a column of ones.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the mathematical formulation of linear regression with bias, feature scaling, and ridge regularization. Then discuss implementation details: how to incorporate the bias term (e.g., adding a column of ones), why feature scaling is crucial for regularization and gradient descent, and how ridge regularization modifies the loss function and gradient updates. Finally, mention trade-offs and practical considerations like choosing the regularization strength.

Pro tip: Emphasize that feature scaling should be done after splitting data to avoid data leakage, and that the bias term is typically not regularized. Also, mention that closed-form solution exists for ridge regression but gradient descent is often used for large datasets.

1. Mathematical Formulation

Write the linear regression model with bias: y = Xw + b + ε. For ridge, the loss is MSE + λ||w||² (excluding bias). Explain that bias shifts the hyperplane, and regularization penalizes weights to prevent overfitting.

2. Handling the Bias Term

Describe two common approaches: augmenting the feature matrix with a column of ones and treating bias as another weight, or keeping it separate and updating it without regularization. Mention that the bias should not be regularized.

3. Feature Scaling

Explain why scaling (e.g., standardization or min-max) is important: it ensures all features contribute equally to the distance metric and speeds up convergence in gradient descent. Also, it makes regularization fair across features.

4. Ridge Regularization Implementation

Detail how to incorporate L2 regularization: modify the cost function and gradient updates. For gradient descent, the weight update includes a decay term (1 - 2λη)w. For closed-form, solve (XᵀX + λI)w = Xᵀy, but exclude bias from penalty.

5. Trade-offs and Practical Considerations

Discuss the impact of λ: too high leads to underfitting, too low to overfitting. Mention that scaling affects the effective regularization strength, so λ should be tuned after scaling. Also, note computational trade-offs between closed-form and iterative methods.

Key Points to Mention

  • Bias term should not be regularized; it captures the intercept and is not a slope parameter.
  • Feature scaling (e.g., standardization) is essential before regularization to ensure fair penalty and faster convergence.
  • Ridge regression adds L2 penalty to the loss function, which shrinks weights but not the bias.
  • Gradient descent update for ridge includes a weight decay term: w := w - η(∇MSE + 2λw).
  • Closed-form solution for ridge: w = (XᵀX + λI)⁻¹Xᵀy, with bias handled separately or by excluding from penalty.
  • Scaling should be fit on training data only and applied to validation/test to avoid data leakage.

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