Machine learning with football · Chapter 3 · Logistic regression

Calculating a probability

The sigmoid bends a straight line into a curve that stays between 0 and 100%, and that curve is the model.

Estimated time: 15 minutes · page 2 of 4

The sigmoid

A straight line runs off forever in both directions. A probability has to stay between 0 and 1. The sigmoid function fixes that. Whatever number goes in, a probability comes out:

σ(z) = 1 / (1 + e−z)

e is about 2.718. Feed it a big positive number and the answer creeps toward 1, a big negative one and it creeps toward 0, and 0 itself gives exactly 0.5. It never reaches 0 or 1, however far you go.

10.50z = −707
The orange dot is the match picked on the board, at the z your sliders give it.
z-4-3-2-101234
σ(z)0.0180.0470.1190.2690.5000.7310.8810.9530.982

The model

The straight line from chapter 2 is still there. It just stops being the answer and becomes the input to the sigmoid:

z = b + w · x

y′ = σ(z)

With more features z simply gets more terms, b + w₁x₁ + w₂x₂ and so on. Here is one match worked through with your sliders. Click any dot on the board to pick another.

Arsenal FC 3–0 Coventry City FC, so y = 1

x = 1.64 goals of difference per game in the home side's favour

z = 0.00 + 0.00 · 1.64 = 0.00

y′ = 1 / (1 + e0.00) = 50% chance of a home win

Check yourself

A model has b = 0.1, a weight of 1.5 for the goal difference gap and −0.2 for the number of home players out injured. The gap is 0.8 and one home player is out. What is z?
And the chance of a home win?

Log-odds, and what bookmakers already know

Solve the sigmoid for z and you get the logarithm of the odds:

z = ln( y′ / (1 − y′) )

A 75% home win chance is 75 to 25, odds of 3 to 1, and ln 3 ≈ 1.1. That's why z is called the log-odds. Bettors know this scale from the other side. Decimal odds of 1.33 mean the bookmaker thinks it's about 75%, before its margin.

Press Show best curve and the numbers mean something. In Premier League the best fit has b = -0.32, so between two equally good teams the home side wins 42% of the time. Draws make that lower than you might guess. The weight w = 0.82 says each extra goal of difference per game multiplies the odds of a home win by ew = 2.3.

Check yourself

For one match the model gives z = 0. What does it predict?
b came out negative. What does that say?

Terms on this page: Log-odds, Sigmoid function

Leagues