# Stochastic gradient descent (SGD)

> Canonical: https://skillalmanac.com/glossary/stochastic-gradient-descent | Last verified: 2026-11-25 | Index status: index-eligible

Stochastic gradient descent (SGD) is an optimisation method that trains a model by repeatedly nudging its parameters to reduce error, using one example or a small batch of data at a time instead of the whole dataset.

Also called: SGD, SGD optimizer, SGD machine learning, mini-batch gradient descent, minibatch SGD.

## In plain language

Training a model means adjusting many numbers until its errors shrink. Gradient descent does that by checking which direction lowers the error and taking a step. Stochastic gradient descent takes each step after looking at just one example or a small handful, so it is like improving a recipe after each taste instead of after cooking for the whole village. Steps are cheaper, but they are noisier, so progress wobbles. The step size and other settings must be chosen, and a poor choice can make training slow or unstable. Running it on large models costs computing time, which can mean real money.

## Technical definition

SGD updates parameters using a gradient estimated from a single sample or a small mini-batch, rather than the entire training set as batch gradient descent does. According to IBM, the term SGD is loosely used for mini-batch gradient descent, strict single-sample SGD is uncommon in practice, and its convergence is noisier than full-batch gradient descent. The scikit-learn guide calls it an optimisation technique rather than a model family, and notes that it needs hyperparameters such as the regularisation parameter and number of iterations and is sensitive to feature scaling. The Keras SGD optimizer adds an optional momentum term.

## How it shows up when you use agents

SGD shows up when an agent writes or tunes training code. If you ask Claude Code, Codex or Cursor for a classifier, the script may name an SGD optimizer, in scikit-learn's SGDClassifier or as a Keras optimizer. You will see settings such as a learning rate, a batch size and a number of epochs, and a loss value that falls unevenly from step to step.

What breaks when it is misunderstood: the settings and the data. The scikit-learn guide says SGD needs hyperparameters and is sensitive to feature scaling, and it recommends standardising features and applying the same scaling to the test data. An agent that skips scaling can produce a model that trains badly while the code runs without errors. The word SGD also hides a choice: IBM says it is often used loosely to mean mini-batch gradient descent, so check the batch size actually used.

A practical next step: ask the agent which batch size, learning rate and scaling it used, and why. See [Gradient descent](/glossary/gradient-descent), [Learning rate](/glossary/learning-rate) and [Batch size](/glossary/batch-size). The catalogue has no skills that train or tune models, so the examples are contrast cases.

## Common confusions

- **SGD versus gradient descent.** Batch gradient descent uses the entire training set for each update. SGD uses one sample or a small batch, which IBM says gives noisier convergence.
- **SGD versus mini-batch.** IBM says strict single-sample SGD is uncommon in practice and the term is often used for mini-batch gradient descent.
- **SGD versus a model.** The scikit-learn guide says SGD is an optimisation technique and does not correspond to a specific family of models. It is a way to train one.
- **Myth: SGD needs no tuning.** The scikit-learn guide lists hyperparameters and feature scaling among its disadvantages.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill checks train, validation and test files for duplicates, shared groups, time and label leakage and prints JSON.

Why it exercises the concept: A contrast case. SGD fits a model on training data, and this skill checks that the data splits around that fit are clean. It does not train anything. The catalogue has no optimiser skills, and this is illustrative, not executed.

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill is a fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive, evidenced and caveated.

Why it exercises the concept: The scikit-learn guide says SGD is sensitive to feature scaling. Profiling columns beforehand can show their ranges, though the skill does no scaling or training. This is illustrative, not executed.

### [llm-cost-estimator](https://skillalmanac.com/skills/skill-almanac/llm-cost-estimator)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill turns a usage profile and your own price table into a monthly LLM cost range with cache, batch and subscription effects.

Why it exercises the concept: A contrast case about cost. It estimates the cost of using a model, which is a different matter from the compute cost of training one with SGD. This is illustrative, not executed.

## Related terms

- [Gradient descent](https://skillalmanac.com/glossary/gradient-descent.md)
- [Learning rate](https://skillalmanac.com/glossary/learning-rate.md)
- [Batch size](https://skillalmanac.com/glossary/batch-size.md)
- [Loss function](https://skillalmanac.com/glossary/loss-function.md)
- [Backpropagation](https://skillalmanac.com/glossary/backpropagation.md)
- [Neural network](https://skillalmanac.com/glossary/neural-network.md)

## Sources

- [Stochastic Gradient Descent](https://scikit-learn.org/stable/modules/sgd.html), scikit-learn (accessed 2026-11-24)
- [What is stochastic gradient descent?](https://www.ibm.com/think/topics/stochastic-gradient-descent), IBM (accessed 2026-11-24)
- [SGD optimizer](https://keras.io/api/optimizers/sgd/), Keras (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
