Machine learning with football · Chapter 3

Logistic regression

Will the home side win? Linear regression gives a number. For a yes or no question we want a probability.

Estimated time: 5 minutes · page 1 of 4

From a number to a chance

Chapter 2 drew a line through the table and read off points per game, a number. Plenty of football questions are yes or no instead. Will the home side win? Will both teams score? Will there be more than 2.5 goals? For those we want a probability, something like "62% home win", and the model that gives one is logistic regression.

The data is every match Premier League has finished this season, 110 of them, one dot each on the board. The feature x is how much better the home team is: its goal difference per game minus the away team's. The label y is 1 when the home side won and 0 for a draw or an away win. 48 of the 110 ended in a home win.

The home wins sit along the top of the board and everything else along the bottom. Each square is the real share of home wins among matches with a similar gap. They climb from bottom left to top right, and a good model should run through them.

One shortcut: the goal differences come from today's table, which already contains these matches, so the feature peeks a little at the answer. Chapter 7, on datasets, explains why that flatters a model and how to avoid it.

Check yourself

Which of these are yes or no questions that logistic regression can answer? Pick all of them.
In our data, a match ends 1–1. What is its label?

Why not a straight line?

You could fit chapter 2's line to these dots. It would cross 100% for the biggest mismatches and drop below 0% for the worst away trips, and neither means anything. A probability needs a curve that flattens out at both ends. Logistic regression gets one by passing the straight line through the sigmoid function, on the next page.

Linear regressionLogistic regression
Predictsa number, any sizea probability, 0 to 1
Football examplepoints per gamechance of a home win
Labela measured number1 or 0
Losssquared loss (MSE)log loss

The sliders already work. w and b set the curve the same way they set the line, so try to make it pass through the squares.

Terms on this page: Logistic regression

Leagues