Loading…
Implement Batch Gradient Descent is a medium coding interview question covering machine learning, math, deep learning — the kind asked at FAANG (Facebook/Meta, Apple, Amazon, Netflix, Google) and AI-first companies like Anthropic, OpenAI, and Nvidia.
Implement batch gradient descent to minimize MSE loss for linear regression.
Given: X (n_samples x n_features), labels y, learning_rate, n_epochs.
For each epoch: 1. y_pred = X @ w + b 2. loss = MSE(y_pred, y) 3. dw = (2/n) * X.T @ (y_pred - y) 4. db = (2/n) * sum(y_pred - y) 5. w -= lr * dw, b -= lr * db
Return final weights and loss history.
Solution walkthrough on Pro
Upgrade to Pro to unlock the guided hints, the step-by-step walkthrough, solutions in Python, C++, Java, and Go, and complexity analysis.
What's inside this guide
Fully unlocked, no account needed — solutions, walkthroughs and follow-up answers included.
Or start the Study Plan — a week-by-week order for your loop, and week 1 is entirely free.
A full interview loop is more than one round. These are the others, each with what is on the site for it.