liveBook · Manning

Epoch

As explained in Grokking Machine Learning, Second Edition

A complete iteration of an iterative learning procedure over the training data.

An epoch is one repetition of a training procedure. During each epoch, an algorithm selects data, adjusts its model, and moves toward a better fit. In simple algorithms, one epoch may use one randomly selected point; the total number of epochs is chosen before training begins. section 3.15 section 5.15

Use the epoch count to control how long training runs:

  • Run a fixed number of epochs based on available computing power or time. section 5.15
  • Stop when the error falls below a chosen threshold. section 5.15
  • Stop when the error changes very little across several epochs. section 5.15
  • Treat the number of epochs as a hyperparameter alongside the learning rate and batch strategy. section 10.16

Watching a line improve

A linear regression program can run for 10,000 epochs. The line may move quickly during the first 10 epochs, look good after 50, and fit the points very well by the final epoch. Each cycle gives the model another chance to adjust its slope and intercept. section 3.17

import random                              #A
def linear_regression(features, labels, learning_rate=0.01, epochs = 1000):
    price_per_room = random.random()
    base_price = random.random()          #B
    for epoch in range(epochs):           #C
        i = random.randint(0, len(features)-1) #D
        num_rooms = features[i]
        price = labels[i]
        price_per_room, base_price = square_trick(base_price,         
                                                  price_per_room,
                                                  num_rooms,
                                                  price,
                                                  learning_rate=learning_rate) #E
    return price_per_room, base_price

Inspect the Python loop that initializes model values, selects a random data point, applies the square trick, and repeats for the requested number of epochs. section 3.15

How Grokking Machine Learning, Second Edition covers it

How deep it goes
Defines epochs through repeated updates, stopping criteria, and batch variants, but defers their mathematical details.
Examples
Uses a Python linear regression loop, 10,000 training cycles, and perceptron updates on randomly selected points.
What you can do after
Apply it by choosing a training duration and stopping rule for iterative machine-learning algorithms.
How it connects
Links epochs to learning rate, perceptron algorithms, linear regression, gradient descent, batch size, and hyperparameter tuning.

Also explained in

Compare how 14 books explain epoch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning, Second Edition. The section links point to the parts of the book it draws on.