
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
Gradient descent is an optimization algorithm that trains many machine learning models by repeatedly adjusting parameters to reduce a loss (error) function. Instead of searching every possible set of weights, the algorithm follows the slope of the loss surface downhill—updating parameters in the direction that most reduces error at each step.
Why it matters now: nearly every production ML stack—linear models, neural nets, ranking systems, and many fine-tuning loops—relies on some form of gradient-based optimization. If you understand gradient descent, learning rates, and batch variants, you can diagnose slow training, unstable loss curves, and models that look good in notebooks but fail after deployment.
What gradient descent really does
Training usually means finding parameters (weights and biases) that make predictions close to labels. You measure that mismatch with a loss (or cost) function. Gradient descent computes the gradient—the vector of partial derivatives of the loss with respect to each parameter—and steps in the opposite direction. That is the direction of steepest descent on the loss surface.
As IBM’s overview of gradient descent explains, two ingredients drive each update: a direction (from the gradient) and a learning rate (step size). Too large a learning rate can overshoot the minimum; too small a rate crawls slowly and may stall. The process repeats until the loss stops improving meaningfully—often called convergence.
Intuitively, it is like standing on a foggy hillside and always taking a small step downhill. You do not need a map of the whole mountain; you only need the local slope. That local view is powerful—and also why bad step sizes, noisy slopes, or weird terrain (saddle points, flat regions) can trap or confuse the walk.
Learning rate, loss, and the update step
A typical update looks like: new parameters = old parameters − (learning rate × gradient). The learning rate (sometimes called alpha) controls how aggressive each step is. Practitioners often start with a small constant rate, then use schedules or adaptive optimizers (Adam, RMSProp, and relatives) that rescale steps per parameter.
The loss function turns prediction error into a number the optimizer can minimize. Mean squared error is classic for regression; cross-entropy is common for classification. Google’s Machine Learning Crash Course lesson on gradient descent walks through the idea in the linear-regression setting: compute loss, compute gradients, take a step, repeat.
Feature scale matters. If one feature is in millions and another in decimals, gradients can be dominated by the large-scale feature. That is one reason feature engineering and normalization often sit upstream of stable training.
Batch, stochastic, and mini-batch gradient descent
How you compute the gradient over the dataset changes speed, memory, and noise:
Batch gradient descent uses the full training set for each update. Gradients are stable, but large datasets make each step expensive and memory-heavy.
Stochastic gradient descent (SGD) updates from one example (or a tiny sample) at a time. Updates are noisy and fast; the noise can help escape shallow local minima but can also make the loss curve jump around. See IBM’s notes on SGD in the same gradient-descent topic family for the practical tradeoffs.
Mini-batch gradient descent splits data into small batches and updates per batch. It is the default in modern deep learning: more efficient than pure batch on GPUs, less noisy than pure SGD.
Choosing batch size is a systems-and-stats tradeoff: larger batches give smoother gradients and better hardware utilization; smaller batches add noise that can regularize training but may need careful learning-rate tuning.
How machine learning models actually “learn” with it
In supervised learning, labels provide the target. Gradients tell each weight how to change so predictions move closer to those labels. In neural networks, backpropagation efficiently computes those gradients layer by layer. Over many epochs, the model’s decision surface shifts from random guesses toward patterns in the training data.
That learning loop is powerful—and fragile. If the model memorizes training quirks, validation performance drops. Techniques like regularization, early stopping, and careful evaluation with cross-validation help you notice when optimization is succeeding on train loss while generalization is failing. Related failure modes are covered in our piece on overfitting and why models fail on new data.
Even “simple” classifiers often train with gradient-based methods. For example, logistic regression is typically fit by maximizing likelihood via iterative optimization that is closely related to gradient descent.
Challenges you will see in real training runs
Local minima and saddle points: On non-convex losses (deep nets), the optimizer may settle in a mediocre basin or linger near flat saddle regions. Noise from mini-batches and modern adaptive methods often helps, but there is no universal guarantee of a global minimum.
Vanishing and exploding gradients: In deep or recurrent networks, gradients can shrink toward zero (early layers stop learning) or blow up (unstable weights). Careful initialization, normalization layers, clipped gradients, and architecture choices mitigate these issues.
Bad learning rates: Loss that diverges or oscillates wildly often means the step size is too large; loss that barely moves may mean it is too small or the data pipeline is broken.
Data and label problems: Optimization will faithfully minimize loss on whatever you feed it—including biased labels and leakage. Clean data beats a fancier optimizer.
A practical checklist
Confirm the loss matches the task, then start with a sane learning rate and plot train/validation loss.
Prefer mini-batches; normalize features when scales differ wildly.
Watch for overfitting: falling train loss with rising validation loss.
If training is unstable, lower the learning rate, clip gradients, or try a proven adaptive optimizer—then re-check data quality.
FAQ
Is gradient descent only for neural networks?
No. It (and close relatives) train linear models, logistic regression, many ranking objectives, and more. Neural nets made it famous because backprop scales gradients to millions of parameters.
When has the model “converged”?
When updates no longer improve the validation metric you care about—or further gains are not worth the compute. Perfect zero loss is rarely the goal; generalization is.
For clear overviews, start with IBM on gradient descent and Google’s ML Crash Course gradient descent lesson. Then practice reading loss curves alongside evaluation discipline.
Learn to build and evaluate models with live practice
If you want hands-on practice with data, models, and evaluation, guided by practitioners, Coderhouse offers live online courses with one class per week:
AI Engineering Course: 8 weeks for experienced developers moving into AI engineering, covering LLM applications, retrieval, agents, evaluation, and deployment.
Data Analytics Course: 11 weeks for career switchers, analysts, and data-driven professionals, covering metrics, SQL, Python, visualization, experimentation, and AI-assisted analysis.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.