Logistic regression
You want one number: the probability a team wins. Logistic regression is the model built for exactly that. In this lesson we build it up one piece at a time. First we see why the obvious approach fails, then we fix it with a famous S-shaped curve, then you calculate a real win probability by hand, and finally you drive the model yourself.
What the model is actually doing
Take the features of a match (ranking gap, recent form, home advantage) and turn them into a single probability between 0% and 100% that the team wins. That is the entire job. Everything below is just how.
Why not just draw a straight line?
In an earlier lab you may have fit a straight line through data to predict a number. Natural question: why not use a straight line here too? Put ranking gap along the bottom and "did they win (1) or not (0)" up the side, and draw the best line.
The problem is that a straight line does not stop. Push the ranking gap high enough and the line predicts a probability of 130%. Push it low and it predicts −20%. Those are nonsense: no event is 130% likely. A probability must stay between 0 and 1, and a straight line simply will not.
A straight line keeps going forever, so it happily predicts impossible probabilities. We need something that bends to stay between 0% and 100%.
Step 1: mix the clues into one score, called z
First we combine the features into a single number. We do it the simple way: multiply each feature by a weight that says how much it matters, then add them all up. We call the result z.
The Greek letters look fancy but mean something simple. Each β (say "beta") is a weight, a number the model learned. A bigger weight means that feature pushes the score harder. β0 is a starting value called the bias, there before any feature is added. So far this is just "multiply and add."
A big positive z means the clues strongly favour a win. A big negative z means they strongly favour a loss. A z near zero means it is a toss-up. But z can be any size, so we still cannot read it as a probability yet. That is the next step.
Step 2: squash z into a probability with the sigmoid
So we run z through a function that takes any number, however huge or tiny, and squashes it into the range 0 to 1. That function is the sigmoid, and it draws the S-shape you saw at the top of the page.
Take it piece by piece. σ (say "sigma") is the name of the sigmoid function. The letter e is a fixed number, about 2.718, that shows up all over maths. You would not work this out by hand, a calculator or computer does the e part. What matters is how it behaves:
- When z is a big positive number, the answer climbs toward 1 (100%).
- When z is a big negative number, the answer falls toward 0 (0%).
- When z is exactly 0, the answer is exactly 0.5 (50%).
That last point is important. z = 0 always gives 50%, so z = 0 is the decision boundary: the exact tipping point where the model switches from "probably loses" to "probably wins."
Do one by hand
It clicks fastest when you plug in real numbers, so follow each line.
Worked example: Team Gold at home
Team Gold is ranked 8th and hosts Team Coral, ranked 34th. Gold has been playing well (recent form +3) and they are at home today.
Read off the features: ranking gap = 34 − 8 = 26, recent form = 3, home advantage = 1 (yes = 1, no = 0).
The model already learned these weights: β0 = −0.4, β1 = 0.05, β2 = 0.3, β3 = 1.1.
Plug into z:
$$z = -0.4 + (0.05 \times 26) + (0.3 \times 3) + (1.1 \times 1)$$
$$z = -0.4 + 1.3 + 0.9 + 1.1 = 2.9$$
Squash with the sigmoid:
$$P(\text{win}) = \dfrac{1}{1 + e^{-2.9}} = \dfrac{1}{1 + 0.055} \approx 0.948$$
Answer: about a 95% chance Team Gold wins. High, but honest: the model still leaves a 5% door open for an upset, and football lives in that 5% all the time.
Now you drive it
That was your gut. Now try the real model. Press Fit the S-curve to train it on 40 past matches, then move the sliders to set up any matchup. The formula panel computes z and the probability exactly like the worked example, and the gold dot rides the curve as you go.
How to use this lab
- Press Fit the S-curve. The 40 dots are past matches (teal = win, coral = no win); the gold curve fits itself through them.
- Drag the ranking gap and recent form sliders, and toggle home advantage, to describe today's match.
- Read the live formula panel: it shows your z and your win probability as you move.
- Find the settings where the gold dot sits right on the dashed 50% line. That is the decision boundary.
Where do the weights come from?
Nobody types in β0 = −0.4 by hand. The computer finds the weights by training, the same guess-check-adjust loop from Lesson 1, applied to logistic regression like this.
First, the model needs a way to score how wrong it is. For probabilities we use a scorecard called log loss. You do not need to compute it, just understand what it rewards: it gives a small penalty when the model is confident and right, and a big penalty when it is confident and wrong.
Here yi is the real answer (1 for a win, 0 for not), and p̂i is the probability the model gave for match i. The formula just adds up the penalty across all n matches.
Then the model nudges every weight a tiny step in the direction that makes the loss smaller, and repeats thousands of times. That nudging is called gradient descent. Think of walking downhill in thick fog: you cannot see the bottom, but you can feel which way slopes down and step that way. That is exactly what "Fit the S-curve" did.
The height on the hill is how wrong the model is right now. Each step downhill is one round of nudging the weights. The valley at the bottom is the set of weights that gets the most predictions right. The model never sees the valley, it just keeps stepping down until the ground stops sloping.
- A straight line cannot predict a probability because it does not stay between 0 and 1.
- Step 1: combine features into one score, $z = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dots$
- Step 2: the sigmoid $\sigma(z) = 1/(1+e^{-z})$ squashes z into a probability.
- z = 0 gives 50%, the decision boundary.
- The weights (β) are found by training: shrinking log loss with gradient descent.
Next: a completely different way to predict, by asking smart questions.