Optimization interview question

Machine LearningOptimizationCalculus & Gradientsbasic

What is the difference between batch gradient descent and stochastic gradient descent (SGD)?

  1. ABatch GD updates the weights after each single random example; SGD computes each update from the gradient over the full training set.
  2. BBatch GD keeps one fixed learning rate; SGD draws a fresh random learning rate at every step, which is what makes it stochastic.
  3. CBatch GD can be used only for convex losses; SGD can be used only for neural networks, because it relies on backpropagation to get gradients.
  4. DBatch GD computes each update from the gradient over the full training set; SGD updates the weights after each single random example.
Show the answer and explanation

Correct answer: D, Batch GD computes each update from the gradient over the full training set; SGD updates the weights after each single random example.

Explanation Optimization

Batch gradient descent computes the exact gradient of the loss over all n training examples, then takes one step: one update per epoch, a smooth path, but expensive when n is large. Stochastic gradient descent (in its classic form) picks one random example, computes its gradient and updates immediately: n cheap, noisy updates per epoch.

The single-example gradient is a noisy but unbiased estimate of the full gradient, so SGD's path zig-zags and usually needs a decaying learning rate to settle near the minimum.

Why the other statements are wrong:

  • Swapping the two definitions is the classic mix-up.
  • "Stochastic" refers to the random sampling of examples, not to a random learning rate.
  • Both methods apply to any differentiable loss; SGD is used for linear models and SVMs as well as neural networks.

Interview tip: note that deep learning libraries call their optimizer "SGD" even though it runs on mini-batches; the interviewer's next question is often why mini-batches are the practical middle ground.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Machine Learning questions

  1. In reinforcement learning vocabulary, what is the reward?
  2. Both series below rise at a similar average rate. Series A was generated as a linear trend plus stationary noise; Series B is a random walk with drift. Which…
  3. A churn model produced this confusion matrix on 10,000 customers, and a manager celebrates its 98.8% accuracy. What is the model's balanced accuracy, and what…
  4. For the query "waterproof hiking boots", assessors graded four products as relevant: Boot-X (3), Boot-Y (3), Boot-Z (2) and Sock-K (1); every other product is…
  5. A gradient-boosted tree model was trained on months 1–36 of demand, using month_index as a feature. Its forecast for months 37–48 is the flat line in the…