Notes

Batch Gradient Descent

Training a supervised model is basically a repeated “adjust the knobs, check how wrong you are, adjust again” loop. Batch Gradient Descent is one of the cleanest versions of that loop: every update uses the entire training dataset.

What it is and how it works

In gradient descent, you pick a loss function (like mean squared error for regression or cross-entropy for classification) and try to find parameters that minimize it. Batch Gradient Descent computes the gradient of the loss using all training examples, then takes one step in the negative-gradient direction:

w = w - learning_rate * (1/N) * sum_i ∇_w L(x_i, y_i; w)

Because every step is based on the full dataset, the direction is stable and predictable—like steering a ship using the average of all sensor readings rather than a single noisy reading.

Where you see it in practice

  • Linear regression on a modest dataset (e.g., house price prediction) where full passes are cheap.
  • Logistic regression for spam detection or credit scoring when you want smooth, steady convergence.
  • Neural networks in frameworks like PyTorch/TensorFlow when you explicitly set the batch size to the full dataset (less common at scale).

Why it matters (and trade-offs)

Batch updates give a low-variance gradient, which makes learning curves easier to reason about and can help with reproducibility. The cost is speed and memory: each step requires scanning the whole dataset, so it becomes impractical for large-scale churn prediction, fraud detection, or click-through-rate modeling. That’s why stochastic and mini-batch gradient descent are popular: they trade a bit of noise for much faster, more frequent updates.

Batch Gradient Descent is an optimization method that updates model parameters by computing the gradient of the loss over the entire training dataset for each step, then moving parameters in the negative-gradient direction using a chosen learning rate. It matters because it provides stable, deterministic updates and a clear objective decrease per iteration, but can be computationally expensive and slow on large datasets, affecting training time and scalability.

Imagine you’re trying to lower your monthly expenses. One way is to collect every receipt from the whole month, add everything up, and then decide what to change next month. That “look at everything, then adjust” approach is like Batch Gradient Descent.

In supervised learning, a model learns by making guesses and seeing how wrong they are. Batch Gradient Descent updates the model only after it looks at the entire training dataset at once, then takes one step to improve. This can make training steady and predictable, but it can also be slow on huge datasets because every update requires scanning all the data.