Skip to content

Gradient descent

Also called: gradient descent algorithm

Published:

How does gradient descent work, step by step?

Google describes it as an iterative technique for finding the weights and bias that give the lowest loss [1]. You start with the weight and bias near zero, calculate the loss, use the slope of the loss function to work out which direction reduces it, and move the parameters a small amount that way. The loop repeats until the loss stops falling [1]. Once extra iterations no longer cut the loss meaningfully, the model has converged [1].

In Google's fuel-efficiency example, the weight and bias start at zero with a step size of 0.01. Over six iterations the loss falls from 303.71 to 42.17 [1].

What does the learning rate change?

The learning rate sets the size of each step towards the minimum. Set it high and you can overshoot; set it low and you gain precision but need more iterations and compute [2]. For linear models the loss surface is convex, so a converged model has found the lowest-loss values [1]. On nonconvex problems, local minima and saddle points can flatten the slope to near zero and stall learning early [2].

What variants are there?

IBM lists three. Batch gradient descent sums the errors over the whole training set before each update; it is stable but can be slow on large datasets. Stochastic gradient descent (SGD) updates the parameters after every single example. Mini-batch gradient descent works on small batches and sits between the two [2].

Frequently asked questions

Does gradient descent always find the best solution?

No. It finds the minimum on convex problems, but on nonconvex ones it can get stuck at local minima or saddle points.

Sources

  1. Linear regression: Gradient descent (Machine Learning Crash Course) — Google for Developers
  2. What is Gradient Descent? — IBM