Predict soccer matches with 50% accuracy | by Benedikt Droste | Towards Data Science

Betting in general and betting games became even more popular in the last years. You can bet everywhere at any time via your pc or your smartphone. Therefore, it is not surprising that a lot of people try to predict results of sport events. For soccer there is a huge market and you are able to bet on nearly every event which can appear in a soccer game like goals, players, cards, corners and so on.The most common bet is called 1x2. You try to predict if there is a win by the home team (1), a draw (x) or a win by the away team (2). People who don ́t trust animals like Paul the octopus are looking for more sophisticated statistical approaches. I want to share a very basic approach with you. We will have a deeper look into the Poisson distribution and how it is used in Python. For the basic statistical concept, please have a look here and here.In the next parts I will use parts of a code which were published by David Sheehan in his fantastic blog. I will go deeper into detail and I will review the the model on a broader sample to answer the question how successful the model is. As always i will not include any code I used but you find it on Github.
Before we create models, predict results and check these for correctness, we need some data. So let’s get the last Premier League (PL) season:
20 Teams are playing in the PL, so we remove the last 10 rows and try to predict the results for the last match day.
For soccer fans, this result is not surprising. The home teams score more goals on average than the away teams.
The highest amount of goals by one team in a single match was 6. Basically, we have now all the required parameters for our Poisson distribution. In the first step we can predict the probability that the home team scores 1 goal for example:
The chance that the home teams scores 1 goal is 32,6%. Let ́s visualize the values for a number of goals between 0 and 6 and for the home and away side:
The bars show the real amount of goals in the season 2018/19. The lines show our Poisson calculated values that seem to fit the real distribution pretty well.
Now we have learned the basic concept of the Poisson distribution. But how can we predict the number of goals for a specific match? The answer is a Poisson Regression:
We will focus on the main aspects of this regression. The number of observations is 740 (37 matchdays for 20 teams). In the first line, we see an entry named “Intercept”. This is the baseline rate and all other estimations are relative to it. The team coefficient for Liverpool is 0.1849 which means that Liverpool scores more goals than average teams. The lower the coefficient, the fewer goals a team shoots on average.The opponent coefficient for Chelsea is -0.2537. Chelsea receives fewer goals than an average team. The lower the coefficient, the fewer goals a teams receive on average. The last row “home 0.2526” is the expression of home advantage: home teams score more goals on average.To calculate the estimated amount of goals for Liverpool we use the following formula:
exp(Intercept+Coefficients)
So let ́s fill our formula for a) Liverpool and b) Chelsea:
Notice that we add the “home”-coefficient (0.2526) just for Liverpool. The prediction would be 2:1, so we expect Liverpool to win. Now, let ́s compare our prediction with the last match day.
Okay, we predicted half of the match day correct and half of the match day wrong. For such an easy model, it isn ́t bad or what do you think? But we just predicted one single match and it was the last match day which should be less predictable in general. Some teams can ́t change their position in the table anymore and therefore they have nothing to lose which results in weaker performances. In a next step, we take a look at the top five European leagues (regarding the UEFA-coefficient) and pick a larger sample. We predict the last 10 match days for each league.
We can easily use the same code as before and run it for 5 instead of 1 league. As we did before, we remove the last 10 match days in our training data set:
In the graphic above you see what we have already expected. The prediction is worse on the last two match days. But overall the line is most of the time around 5 which means half of the matches of a specific match day were predicted right. In sum, we have predicted 48,2% of the match day correctly. You see the headline is click-baiting at it ́s best ;).
We saw that we can nearly predict 50% of the matches correctly with the use of an easy Poisson regression. It can be easy used with Python and allows an efficient calculation. It is also fast scalable. You can expand the code to predict the matches for a) other leagues or b) more matches. If you want to go further with this model, you could check for the form of the teams, time-weighting or correctness of under- or overestimated results. I hope you enjoyed reading!
If you enjoy Medium and Towards Data Science and didn’t sign up yet, feel free to use my referral link to join the community.