What is the difference between batch gradient descent and stochastic gradient descent (SGD)?
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.