Dictionary of Applied Machine Learning
Updated on 2026-09-04
Typeset PDF version — the authoritative form of this entry
Python demo — a script that recomputes what this entry states and prints one line per check
Stochastic gradient descent (SGD) is a variant of gradient descent (GD) in which the gradient of the objective function is replaced by a computationally cheaper stochastic approximation. Its main application in machine learning (ML) is empirical risk minimization (ERM) on a training set that is large or stored in a distributed database: the gradient of the empirical risk requires an average over the entire training set. SGD approximates this average by the average over a randomly drawn batch of data points. The batch size trades the computational cost of a single update against the accuracy of the gradient approximation.
B-weatherConsider an
artificial intelligence system (AI system) that uses logistic regression to learn an image
classifier. Logistic regression amounts to finding the minimum
of a differentiable convex objective function, the
empirical risk
\[
f(\weights) \defeq \frac{1}{\samplesize}
\sum_{\sampleidx=1}^{\samplesize}
\lossfunc{\datapoint^{(\sampleidx)}}{\weights} \text{.}
\]
Here, $\lossfunc{\datapoint^{(\sampleidx)}}{\weights}$ denotes
the loss incurred on the data point
$\datapoint^{(\sampleidx)}$ of a training set
$\trainset = \big\{ \datapoint^{(1)}, \ldots,
\datapoint^{(\samplesize)} \big\}$ by the hypothesis with
model parameters $\weights$, and $\samplesize$ is the number of
data points in the training set. Gradient descent (GD) minimizes a
differentiable convex function by taking a
sufficient number of gradient steps,
\[
\weights^{(\iteridx+1)} = \weights^{(\iteridx)}
- \lrate^{(\iteridx)} \nabla f(\weights^{(\iteridx)})
\text{,}
\]
with a step size $\lrate^{(\iteridx)} > 0$. The
gradient of the above objective function is
$\nabla f(\weights) = \frac{1}{\samplesize}
\sum_{\sampleidx=1}^{\samplesize} \nabla_{\weights}
\lossfunc{\datapoint^{(\sampleidx)}}{\weights}$, an average
with one term per data point, so its exact evaluation
requires a pass over the entire training set. SGD instead uses
the estimate
\[
g(\weights) \defeq \frac{1}{\batchsize}
\sum_{\sampleidx \in \batch} \nabla_{\weights}
\lossfunc{\datapoint^{(\sampleidx)}}{\weights} \text{,}
\]
the same average over a batch
$\batch \subseteq \{1, \ldots, \samplesize\}$ of
$\batchsize = |\batch|$ indices chosen uniformly at random
(see Fig. 1).
Geosphere.at (filled circles) and FMI.fi
(filled squares). The dotted vertical segments are the
prediction errors of a linear hypothesis map
$\hypothesis(\feature)$ (solid line). A GD update of the
model parameters $\weights$ uses the prediction errors of
all $\samplesize$ data points; an SGD update uses only
those of a randomly chosen batch $\batch$ (circled).
Data generated by pythondemos/stochGD.py, which
downloads the observations from the open data services of
GeoSphere Austria and the Finnish Meteorological Institute
B-approxThe batch size $\batchsize$ is an important
parameter of SGD: $\batchsize = \samplesize$ recovers
GD, while $\batchsize = 1$ updates with the gradient
of a single data point and yields the noisiest estimate.
SGD with $1 < \batchsize < \samplesize$ is mini-batch SGD
(Bottou, 1999). Each update costs $\batchsize$ gradient
evaluations instead of $\samplesize$, which is what makes
empirical risk minimization (ERM) on large training sets feasible; the price is noise
in the update, whose variance shrinks as the batch grows
(Bottou, 2010).
@misc{dictml_stochGD,
author = {Jung, Alexander},
editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
title = {stochastic gradient descent},
howpublished = {Dictionary of Applied Machine Learning (course edition)},
year = {2026},
doi = {10.5281/zenodo.21569296},
note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-09-21},
url = {https://dictionaryofml.org/terms/stochGD.html}
}