Building a soccer prediction model with machine learning: the 2022 World Cup
How each team was encoded with FIFA ranking data, why gradient boosting beat six other classifiers and what 10,000 simulations of the tournament showed.
In August 2022, Héctor Cotelo built a machine learning model to estimate who would win the World Cup in Qatar. It correctly called 78.12% of the matches at Russia 2018 and, after simulating the tournament 10,000 times, picked Belgium. Argentina won and Belgium went out in the group stage, but the method still holds: FIFA ranking data, seven classifiers compared and a stage-by-stage simulation.
TABLA DE CONTENIDOS
This article was published in August 2022, before the World Cup in Qatar. The model picked Belgium as the favorite, but Argentina won the tournament, beating France on penalties in the final. Belgium went out in the group stage, and so did Uruguay, which finished third in its group, level on points with South Korea. What follows is still useful for the method: how to build a soccer prediction model with machine learning, how to evaluate it and how to simulate an entire tournament.
Why the World Cup called for a new model
It is no secret that I am passionate about soccer and about artificial intelligence. With the World Cup approaching, it was obvious I would try putting the machine to work to see which national team had the best chance of becoming the next champion.
I had already run an experiment for the South American qualifiers, but this time the approach had to be different. For the qualifiers, I framed the problem as a simulation, sampling from the matches the two teams had already played against each other (for example, Uruguay vs. Paraguay results in Asunción). That wasn’t so simple for the World Cup, because the same teams rarely have much history against each other.
Data modeling: each team as a vector
So I went with a more traditional machine learning approach: find a way to encode (generate an embedding for) each team and the match itself, and then train on the history of every international soccer match played since 1872.

To turn each team into a vector, I used FIFA ranking data. To represent a team as a list of numbers at a given point in time, I used:
- its points on that date;
- its ranking position;
- whether it had moved up or down since the previous ranking;
- the mean, maximum, minimum and standard deviation of its points over the last year, the last two years and the last three years;
- its results in its last five matches (win, loss, draw);
- its confederation;
- whether it was the reigning world champion at the time (because of the so-called champion’s curse).

The advantage of representing teams this way is that the teams themselves no longer matter: to the algorithm, they are just two vectors.
There were several ways to approach the problem. For my purposes I didn’t need to predict the exact score, so I framed it as a binary classification problem in which the algorithm predicts whether the “home” team will win. I actually ask the algorithm for the probability of that outcome, and if it falls within a window around 50%, I call it a draw.
One curious finding is that the algorithm detected home-field advantage. For example, the probability of Bolivia beating Uruguay might come out at 75%, but the probability of Uruguay beating Bolivia comes out at 95%.
As you can see, these probabilities don’t add up to 1, which seems pretty strange at first but makes sense once you think about it.
Since home advantage doesn’t carry the same weight at a World Cup, I had to adapt the model to “average and scale” the probabilities in each direction.
Models and evaluation with the 2018 World Cup in Russia
I trained several models: LogisticRegression, KNeighborsClassifier, DecisionTreeClassifier, LinearSVC, GaussianNB, RandomForestClassifier and GradientBoostingClassifier. The last one performed best.
After hyperparameter tuning came the real test: running the model on the 2018 World Cup in Russia to get a clear idea of how well it predicts World Cup matches. The model correctly predicted 78.12% of the final results (50 of 64 matches).


That is a solid result: a trivial model that always predicts an away win, no matter what, would get 26 of 64 matches right, or 40.63%.
On top of that, the 2018 tournament produced some fairly unlikely results.




Predictions for the World Cup in Qatar
Once trained, the model can estimate the probability of any match. For the group stage, the picture looked like this: Uruguay had a 76% chance of beating South Korea and a 79% chance of beating Ghana, while Portugal had a 64% chance of beating Uruguay. Here are the probabilities for every group-stage match.

Based on that, the most likely outcome was Uruguay finishing second in the group, with two wins and one loss, and facing Brazil (which won all three of its group matches). Here is what the model projected for the round of 16, quarterfinals, semifinals and final.

In that projection, Brazil beat Uruguay and knocked it out of the World Cup: Brazil’s probability of beating Uruguay was 79%.
Not wanting to end on that sad note, and since I had a model that could estimate the probability of any possible match, I simulated the World Cup 10,000 times to see whether Uruguay had even a remote chance of winning it.
10,000 tournament simulations
After 10,000 simulations, Belgium won the title 1,628 times. It was followed by Brazil, Argentina, France, England, Spain, the Netherlands, Portugal, Denmark, Germany, Mexico, the USA and Uruguay. Uruguay won 88 of the 10,000 tournaments, less than 1%. Hard, but not impossible.

Of the 32 teams in the tournament, Uruguay had the 13th-best chance of winning it.

Uruguay’s group
In the group stage, Uruguay could finish with any number of points from 0 to 9 except 8: with three matches, 8 points is impossible.

The most likely outcome was 6 points, which is no surprise. What was quite encouraging is that the second most likely outcome was 9.
In terms of group position, Uruguay had about a 40% chance of finishing first, a little over 45% of finishing second, about 10% of finishing third and less than 5% of finishing fourth.

Adding up the chances of finishing first or second, Uruguay’s probability of advancing was over 80%.

In other words, first place in the group would go to Portugal 55.72% of the time, Uruguay 39.05%, South Korea 4.51% and Ghana 0.72%.

The best-case scenario
As a fun fact, in one of the runs Uruguay reached the round of 16 with just 2 points. How is that possible?

If Portugal beat everyone (Uruguay by a narrow margin, South Korea and Ghana by a wide one) and every other match ended in a draw, Uruguay could advance with just two points.
Round of 16
Everything suggested Uruguay would get through the group stage. Who would it face?

The most likely opponents were Brazil (47%), Switzerland (28%), Serbia (6%) and Cameroon (5%).
The most likely outcome was a round-of-16 exit, with a 64% probability.

But if Uruguay avoided Brazil, its chances of reaching the quarterfinals rose to 59.50%.

Uruguay’s path through the tournament
So, knowing that Uruguay would most likely go out in the round of 16, what were its chances of reaching each stage?

As we saw, the most likely outcome was going out in the round of 16 (54.68%), followed by the quarterfinals (20.19%), the group stage (14.72%) and the semifinals (6.99%), with runner-up at 2.54% and champion at 0.88%.
If Uruguay reached the final (3.42%), who would the opponent be?

Fun facts
The easiest path
Across the 10,000 simulations, one path was truly easy: Switzerland, Japan, Senegal and the USA.

The hardest path
There was also a truly tough path in which Uruguay still ended up as champion: Brazil, Spain, Argentina and France.

Summary
The odds were stacked against La Celeste, but hope dies last: here’s to that 0.88% chance of winning it all!
A prediction contest with machine learning models
Inspired by this idea, in October 2022 we launched a prediction contest in which data science professionals and students entered their own automated prediction models for the World Cup in Qatar; once the tournament ended, the most accurate model won.
Héctor Cotelo
Data & Analytics Consultant