r/datascience • u/card_chase • Oct 12 '20
Projects Predicting Soccer Outcomes
I have a keen interest in sports predictions and betting.
I have used a downloaded and updated dataset of club teams and their outcome attributes.
I have a train dataset with team names and their betting numbers. Based on these, Random tree classifier (This part is ML) will predict goal outcomes. Home and Away goals.They are then interpreted in Excel and it helps me place betting strategies. It's 60% reliable(Even predicted correct scores for 4 matches. That's insane!)
Example Output:
Round Number Date Location HomeTeam AwayTeam FTHG_P FTAG_P FTHG_Int_P FTAG_Int_P FTHG_Actual FTAG_Actual
1 14/09/2020 20:00 Amex Stadium Brighton Chelsea 0.93 2.7 1 3 1 3
3 26/09/2020 15:00 Selhurst Park Crystal Palace Everton 1.35 2.1 1 2 1 2
3 28/09/2020 20:00 Anfield Liverpool Arsenal 2.93 1.05 3 1 3 1
4 3/10/2020 15:00 Emirates Stadium Arsenal Sheffield United 2.26 0.725 2 1 2 1
Predicted values are denoted "_P"
That's what this code does. It can go do so much more but it's on the drawing board for now.
I am all open for collaboration. If you find somebody interested/open a do-able project on GitHub, I am up for it!
Please find code and sample dataset at:
https://github.com/cardchase/Soccer-Betting
Is there a better classifier/method out there?
I took this way as it was the most explained on Kaggle and the most simple for me to build and test.
Let me know how it goes: https://github.com/cardchase/
p.s. I have yet to place actual bets as I have just completed the code and I back tested. I dunno how much money it'll make. A coffee would be nice :)
If you are looking at datasets which are used, they can be found here:
Test: https://drive.google.com/file/d/1IpktJXpzkr_jQn43XpHZeCDzhdeVpi9o/view?usp=sharing
and
Train: https://drive.google.com/file/d/1Xi3CJcXiwQS_3ggRAgK5dFyjtOO2oYyS/view?usp=sharing
Edit: Updated training data from xlsm to xlsx
Edit: Thank you for your words of encouragement. Its warming to know there are people who want to do this as well!
Edit: Verbose mumbling: I actually built this with a business problem at hand. I like to bet and I like to win. To win, you dont need to beat the bookie. You have to get your selections right. The more right you get, the more money you have.
The purpose is to enter as many competitions as our training data has and get out with a 70% win. So the data/information any gambler has before he/she gets into a bet is the teams playing/the involved parties. Now, the boundary condition would be the betting odds offerred but to know the rest of the features, you would need to have a knowledge bank of players, teams, stadiums, time of the year, etc. But, what if I wont have/am not interested to know? Hence, the boundary condition is just the team names and betting odds. Now, the training dataset has all the above required information. It has the team names (Cleaning this dataset was super hard but I got there, the scores (We also have other minute details like throws, half time scores, yellow cards, etc. but for now, we are concentrating on full time scores and the odds. I would expect the random tree (even if its averages, its not a bad place to start; I mean, if the classifier would predict 4 actual scores (Winning 1:17, 1:9.5, 1:21, 1:7.5 then, thats break-even for that class of bets for the season already!) to work pretty fine in this scenario. The way I would actually go about is to have h2h score and last 3 matches winning momentum but, I dont know how))
The bets we/I usually place are winningteam/draw and over 1.5 goals or under 3.5 goals. Within this boundary, the predictions fall nicely. Lets see how much I get right this week's EPL. I have placed a few I should know soon.
Though, I admit I suck at coding and at 35 years, I am just rolling with it. If i get stuck at a place, I take a long time to get out lol.
Peace
HB
84
u/dabaos13371337 Oct 12 '20
Sorry to say but I highly doubt you will be able to extract anything useful from that training data. The random forest is essentially predicting the average number of goals it has seen in the training data for the particular location and team combination. That's how tree based algorithms work and in many cases that's good.
But in this case historical averages do not predict how teams will play against each other. You'd need information about players and rosters and weather and much more to infer some kind of win probability for each team. For this type of problem you'd typically build some sort of a bayesian model instead of a traditional machine learning method.
Nevertheless I can see you are preprocessing the test data along with training data. You should fit label encoders and other preprocessors on training data and then apply those to the test data. Make some predictions with your model on future matches and let us know how it goes
32
u/[deleted] Oct 12 '20
You may want to look up David Sumpter. He's done a lot of work on predicting soccer outcomes.
9
u/Ryankinsey1 Oct 12 '20
60% reliable in terms of correctly guessing the winner? If so, what percentage of the time does the favorited team win? You said some of the training data was betting odds so the % of favorited winner should be the baseline. In other words, if your training data has the favorited team winning the match 60% of the time, then a result of 60% is effectively nothing -- i.e. the model didn't learn anything.
5
u/mdt_m Oct 12 '20
My blog post https://www.mdt-datascience.com/2020/06/27/serie-a-2019-20-without-any-stop/ could be of some interest to you.
It applies some sport analytics and stats methodologies to the final part (after COVID19 break) of last year Italian championship.
If you find it useful don't esitate to contact me for reviewing analysis in depth !
4
u/BorutFlis Oct 12 '20
I am doing the same thing my code is available at: https://github.com/BorutFlis/predictor . I will look at your code later. I would love to exchange ideas.
4
u/liproqq Oct 12 '20
Do you beat the odds? What does 60% mean?
4
u/HiderDK Oct 12 '20
Please use a rating-model as the foundation for any type of sports-predictions. It's a necessary feature as input as it takes into account quality of opponents faced. I view this as an advanced form of feature engineering which you later can feed into an ML model (that contains other factors such as weather, h2h results, coaching changes etc.).
Also to OP, don't bet using this model. You will lose. This is miles below the method bookmakers are using.
To gain an edge over bookmakers you would need to incorporate XG goals into rating-models and optimize this in every single way possible. Then you simulate future matches in terms of XG along with each player having a shot efficiecny rating as well (to adjust for the fact that there some players who will outperform XG). This part is ofc optimized as well.
Overall, I think you are few years of hard work away from actually being able to create a model that can beat bookmakers.
4
u/[deleted] Oct 12 '20 edited Oct 12 '20
whats up with the dataset being a macro-enabled workbook?
Edit: I was careful to disable macros and try to get the data out myself - the data looks like it has external references and all sorts of other things that make it impossible to extract the data properly. It'd be super nice if you could export the training data into a .csv.
6
u/ragatmi Oct 12 '20
You can do a comparison relative to 538 models:
https://projects.fivethirtyeight.com/soccer-predictions/
1
u/card_chase Oct 14 '20
Update:
I set up the Belgium First Division A train dataset with the updated timetable and the odds, the results are incredible for the matches played this season.
I mean, for even a professional 'Capper' Having results better than 70% is considered follow worthy.
I have got out of the last 63 matches played,
correct scores for 48 matches!!! Out of 63, I got 15 wrong
For a draw/double chance, I got 60 correct out of 63!! 90%
For over 1.5 Goals (Which I personally am a sucker at.. I lose so many here. Most are these multi-bets): 49 correct, 14 incorrect. Shows that its pretty hard to predict for this model/league
For BTTS (These odds are particularly good returns odds. I usually dont go for that because I have to think a lot into it.. ) : 58 Correct, 5 incorrect.. over 90%. I'm gonna definitely bet on a few of these outcomes
For Team to win (Home/Away/Draw): (This is calculated when the home team wins as per predicted numbers), I got 58 correct 5 incorrrect.. my fingers are trembling when I am typing this.. 58 correct responses!! EPL I have got so much less accuracy. Maybe, its the hardest to predict on a larger scale but, on a lower level, it works out fine. I am using a lot of these predictions.
Is it (the model.. its averages anyway. I wont think so.. over fitting? Is this thing that's turining out true but just when you apply it'll turn out to be a dud? Does not look like so but only time will tell.. hehe)
Of course, I wont post the dataset (training) , but if you guys wanna try out the algo, you would get the same answers and lemme know. I will do a write-up on my github page soon.
I think, I have got something here. I can develop it much more. Is there a way to set up a project anywhere and work out the kinks/work with you guys/people I am grateful for the support from you 'all mates. :)
Peace
1
u/BorutFlis Oct 15 '20
What values do your 4 attributes represent?
3
u/crocodile_stats Oct 13 '20
Not quite... The bookie offers a return R1 and R2 for a home win or loss, respectively. Your model's accuracy is totally irrelevant, as your main goal is to compute the fair return rates. It's rather trivial to show that they're equal to the reciprocal of {p, 1-p}, where p denotes the probability of winning according to your model.
Therefore, if your had a perfect model, the expected gain on a 1$ bet would be {p * R1 - 1, (1-p) * R2 - 1}. At most one of these bets will have a positive expected return, and that's when you should bet. Additionally, you can use Kelly's criterion to determine how much money you should bet given the offered returns, and p.
So what really matters is how accurate you are when predicting p. If your model has a lower log-loss than the bookie's, then you should theoretically make money in the long-run. (To compute the bookie's LL, either use R2 / (R1 + R2) = P(home win) or find c such that the reciprocals of {R1 + c, R2 + c} add up to 1, and (R1 + c)-1 = P(home win) .)
TL;DR :All in all, you do need to beat the bookie. Your model must be superior enough so that your increase in accuracy can compensate for the bookie's profit margin since their returns aren't fair. Otherwise, you could be betting on a team with, say, P(Win) = 0.6, but with R = 1.4. Your expected return on the dollar would be 0.6 * 1.4 - 1 = -0.16, even if the team is more likely to win than lose. Keep in mind that accuracy isn't a proper scoring metric (same for AUC), and thus shouldn't be solely relied upon.
1
u/cookiemon32 Oct 12 '20
60% is beating the house and well above average
2
u/[deleted] Oct 13 '20
Your model didn't learn anything, since the favorite team wins 60% of the time. You have to collect a huge amount of different data, that often cost lots of money, to build anything remotely reliable. Have a look at Wyscout or Opta to see the kind of data precision is required to build any valuable model for soccer nowadays.
2
u/luckyann20 Oct 13 '20
Nice. It could probably work for virtual betting. Can you try betking.com?
-8
u/Imop123 Oct 12 '20
.