Machine learning with football · Chapter 2 · Linear regression

Hyperparameters

The settings you choose before training: learning rate, batch size and epochs.

Estimated time: 15 minutes · page 6 of 7

What you set, and what the model learns

w and b are parameters. Training finds them. A hyperparameter is a setting you choose before training starts, and the model never changes it. Linear regression has three that matter: the learning rate, the batch size and the number of epochs.

Learning rate

Every step moves a parameter by the gradient times the learning rate. With a gradient of 2.5 and a rate of 0.01, w changes by 0.025. Too small and training crawls. Too big and the steps jump over the bottom of the loss, so it bounces around or grows. A good rate drops the loss steeply at first and then flattens out. There is no rate that suits every problem. You try a few.

Batch size

The batch size is how many teams the model looks at before each step. So far every step used the whole table, a full batch. That is fine for 20 teams and hopeless for 20 million rows. Two cheaper ways:

  • Stochastic gradient descent (SGD) uses one random team per step. Very cheap, very noisy.
  • Mini-batch SGD averages the gradient over a few random teams, more than one and fewer than all. This is what most training uses.

Pick a batch size on the board and run 10 steps a few times. At 1 the loss curve shakes, because one team is a poor guide to the whole table. At 5 it shakes less. That noise is not always bad, as the chapter on neural networks will show.

Epochs

An epoch is one pass in which the model has seen every team once. With 20 teams in mini-batches of 5, one epoch is 4 steps, each step also called an iteration. The board counts epochs as you go. Training usually takes many epochs, and more of them give a better model until it converges, at the cost of time.

Here is how many times w and b get updated in 20 epochs on a 20-team league:

BatchSteps per epochUpdates in 20 epochs
Full batch (20)120
Mini-batch (5)480
SGD (1)20400

The smaller the batch, the more steps you get for the same pass over the data. Each one is cheaper and less sure of where downhill is.

Check yourself

What is the ideal learning rate?
What is the best batch size for mini-batch SGD?
Which of these is true?
20 teams, 20 epochs, mini-batches of 5. How many times are w and b updated?

Terms on this page: Batch size, Epoch, Full batch, Hyperparameter, Iteration, Learning rate, Mini-batch, Stochastic gradient descent (SGD)

Leagues