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













