create account

Soccer Predictions using Python (part 4) by stevencurrie

View this thread on: hive.blogpeakd.comecency.com
· @stevencurrie ·
$0.02
Soccer Predictions using Python (part 4)
<html>
<p>Evening sports fans. &nbsp;Hope everyone's having a wonderful weekend.</p>
<p>Before we get to the code, I'm happy to say that 7 out of 10 predictions were correct and the 3 that were wrong were draws!</p>
<p>If we had put £1 single bets on each game, then for our £10 stake, we'd have had £12.86 back. &nbsp;Only time will tell if this 28.6% ROI will continue.</p>
<p>In <a href="https://steemit.com/programming/@stevencurrie/soccer-predictions-using-python-part-3">Part 3</a>, I spoke about limiting how far back the system would look when making it's predictions and chose 100 games as a default limit. &nbsp;I've now added a function to backtest different values for this.</p>
<p>The updated code is available on my <a href="https://github.com/steviecurrie/soccer-prediction">GitHub</a>.</p>
<p>What I've done is take 60 days of games from a year before the current date and backtest with values from 50 to 500 games, outputting the most successful value.</p>
<p>I've also added a cutoff value for the predicted probability to decide if the game is worth betting on. &nbsp;So the code also sweeps through values for this from 40 to 95.</p>
<p>There was a problem with this approach initially in that it would get to 100% accuracy but only suggest betting on 1 game out of 100. &nbsp;In other words only games that were pretty much foregone conclusions and therefore not worth betting on.</p>
<p>So I've now limited this to advise of at least 1 game out of 10. &nbsp;It reports somewhere in the region of 70-90% accuracy during the backtest.</p>
<p>Now this is a pretty naive form of machine learning, basically a brute force scan through what could be called our hyperparameters, so there's likely to be a danger of curve fitting. &nbsp;To rule this out, I also added a function to test the parameters found during the scan on the next 60 days of games. &nbsp;If the reported accuracy still looks good then we're golden.</p>
<p>New command line options are "-t" or "--test" to scan through the values, and "-b" or "--cutoff" to have the program print out predictions with predicted probabilities above that value.</p>
<p>Running the following command line will find the best values to use for the Scottish Premiership.</p>
<p><code>python3 soccerprediction.py -c Scotland -l Premiership -t</code></p>
<p>This returns with values of 450 for history and 70 for cutoff with 100% accuracy for 7 predictions out of 70 games. &nbsp;Sounds too good to be true, I know! &nbsp;However, it also returns 100% accuracy in the validation test.</p>
<p>Running the tests on the English Premier League returns 400 &amp; 70 with 71% accuracy for 7 games from 70. &nbsp;The validation test returns 93%.</p>
<p>I've only tested with the English Premier League, English Championship and the Scottish Premiership so far but as the predictions the code made in <a href="https://steemit.com/programming/@stevencurrie/soccer-predictions-using-python-part-3a">Part 3a</a> show, it appears to be working pretty well.</p>
<p>Hey, I know the code isn't pretty, efficient, elegant or any of the things it would be if a professional programmer had written it but who the hell cares if it works eh? &nbsp;I'll be continuing to test it and hope some of you guys give it a try too. &nbsp;Feel free to use or change the code in any way you want and if you've any ideas for improvements or fixes please share them here. &nbsp;</p>
<p>Maybe we can all stick it to the bookies. hehehehe.</p>
<p><br></p>
</html>
👍  , , , , ,
properties (23)
authorstevencurrie
permlinksoccer-predictions-using-python-part-4
categoryprogramming
json_metadata{"tags":["programming","python","soccer","predictions"],"links":["https://steemit.com/programming/@stevencurrie/soccer-predictions-using-python-part-3","https://github.com/steviecurrie/soccer-prediction","https://steemit.com/programming/@stevencurrie/soccer-predictions-using-python-part-3a"],"app":"steemit/0.1","format":"html"}
created2017-09-23 20:33:09
last_update2017-09-23 20:33:09
depth0
children13
last_payout2017-09-30 20:33:09
cashout_time1969-12-31 23:59:59
total_payout_value0.020 HBD
curator_payout_value0.001 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,488
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,738,974
net_rshares6,789,601,814
author_curate_reward""
vote details (6)
@outcast81 ·
Hi its me again :)
What data goes into the prediction? You said the system looks back 100 games to make the predictions, just the result? Bookie odds? what does it use? 
Thanks
👍  
properties (23)
authoroutcast81
permlinkre-stevencurrie-soccer-predictions-using-python-part-4-20170923t212303486z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-23 21:23:03
last_update2017-09-23 21:23:03
depth1
children3
last_payout2017-09-30 21:23:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length176
author_reputation209,754,362,359
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,741,630
net_rshares944,947,518
author_curate_reward""
vote details (1)
@stevencurrie · (edited)
Hey bud, the only data it uses is the scores from the previous games.  We take averages for home and away goals in the competition, then the averages for each team we want to predict, use these to calculate expected goals for each team.  These are then used to pick random samples from the poisson distribution which get averaged out to give us our prediction.  [Here](https://www.pinnacle.com/en/betting-articles/Soccer/how-to-calculate-poisson-distribution)'s an excellent description of the process - it's the one I followed to get started.
👍  ,
properties (23)
authorstevencurrie
permlinkre-outcast81-re-stevencurrie-soccer-predictions-using-python-part-4-20170923t220838373z
categoryprogramming
json_metadata{"tags":["programming"],"links":["https://www.pinnacle.com/en/betting-articles/Soccer/how-to-calculate-poisson-distribution"],"app":"steemit/0.1"}
created2017-09-23 22:08:39
last_update2017-09-23 22:34:15
depth2
children2
last_payout2017-09-30 22:08:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length543
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,744,005
net_rshares2,036,356,883
author_curate_reward""
vote details (2)
@outcast81 · (edited)
You are guilty for making me lose a couple of hours already, boy I look dumb staring at all this stuff on my screen, we have a saying in portuguese, "like an ox  staring at a palace".
Wouldn't going so far back in games kind of ruin the prediction a bit, when calculating averages for each team? (Because you go into past seasons, diferent players, managers etc.)

Anyway I tried to run your code and got this error: ModuleNotFoundError: No module named 'pandas'
I need the database right? Can I use my own database?

The possibiltys with this are immense, unfortunatly my knowledge of this isn't.
👍  ,
properties (23)
authoroutcast81
permlinkre-stevencurrie-re-outcast81-re-stevencurrie-soccer-predictions-using-python-part-4-20170923t233320223z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-23 23:33:21
last_update2017-09-23 23:35:30
depth3
children1
last_payout2017-09-30 23:33:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length597
author_reputation209,754,362,359
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,747,956
net_rshares907,149,618
author_curate_reward""
vote details (2)
@precise ·
I like what you've done here. I was able to run your code. Do you mind if i 
 use and test it? I can see where improvements can be done. Great job! 

By the way, an easier to install dependencies is to store them in a file for example **requirement.txt** then place these lines inside that file: 

```
pandas
requests
beautifulsoup4
```

you can then install it by 
`
pip install -r requirements.txt
`

you can also specify module versions on **requirements.txt** ie. `pandas=0.20.0`
👍  
properties (23)
authorprecise
permlinkre-stevencurrie-soccer-predictions-using-python-part-4-20170930t034843069z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-30 03:48:45
last_update2017-09-30 03:48:45
depth1
children1
last_payout2017-10-07 03:48:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length483
author_reputation4,300,224,767,048
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,339,109
net_rshares822,104,341
author_curate_reward""
vote details (1)
@stevencurrie ·
Hi, I don't mind at all if you use the code, in fact I welcome it.  It would be great if you could improve it.

There's so much that could be added, making use of the over/under and BTTS predictions, adding over/under predictions for other scores, predictions for handicaps, correct scores, the list goes on.

I've also thought about scraping a list of available countries & competitions and implementing a GUI with some nice graphs comparing each team.

Anyway, feel free to do anything you like with the code.  And if you wanted to, you could post your improvements here on Steem.

Thanks as well for the advice on requirements.txt.  I'll just go and add that now.

Have fun mate.  :-)
properties (22)
authorstevencurrie
permlinkre-precise-re-stevencurrie-soccer-predictions-using-python-part-4-20170930t095231830z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-30 09:52:30
last_update2017-09-30 09:52:30
depth2
children0
last_payout2017-10-07 09:52:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length687
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id16,361,398
net_rshares0
@stevencurrie ·
$0.69
My program has only 2 predictions for today.
Match|Predicted|Prob%|My Odds|Betfair Odds
-|-|-|-|-
Motherwell v Aberdeen| Aberdeen Win|78.38|1.28|1.57
Verona v Lazio|Lazio Win|95.28|1.05|1.9
👍  , ,
properties (23)
authorstevencurrie
permlinkre-stevencurrie-soccer-predictions-using-python-part-4-20170924t002231165z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-24 00:22:30
last_update2017-09-24 00:22:30
depth1
children6
last_payout2017-10-01 00:22:30
cashout_time1969-12-31 23:59:59
total_payout_value0.517 HBD
curator_payout_value0.169 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length189
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,750,235
net_rshares202,692,619,336
author_curate_reward""
vote details (3)
@outcast81 ·
yup another two lmao fortunatly I saw this in time to bet on Lazio :)
👍  
properties (23)
authoroutcast81
permlinkre-stevencurrie-re-stevencurrie-soccer-predictions-using-python-part-4-20170924t183722257z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-24 18:37:24
last_update2017-09-24 18:37:24
depth2
children4
last_payout2017-10-01 18:37:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length69
author_reputation209,754,362,359
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,819,230
net_rshares883,525,930
author_curate_reward""
vote details (1)
@stevencurrie ·
Hey, that's great. I'm going to test a little longer before I start betting live.

Did you manage to get the code running btw?  (I'm looking into the best way to automate installing the prerequisite packages.)
👍  
properties (23)
authorstevencurrie
permlinkre-outcast81-re-stevencurrie-re-stevencurrie-soccer-predictions-using-python-part-4-20170924t190541754z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-24 19:05:42
last_update2017-09-24 19:05:42
depth3
children3
last_payout2017-10-01 19:05:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length209
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,821,114
net_rshares1,165,679,270
author_curate_reward""
vote details (1)
@stevencurrie ·
Woohoo.  Both predictions correct!
properties (22)
authorstevencurrie
permlinkre-stevencurrie-re-stevencurrie-soccer-predictions-using-python-part-4-20170924t145159319z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-24 14:52:00
last_update2017-09-24 14:52:00
depth2
children0
last_payout2017-10-01 14:52:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation7,132,661,654
root_title"Soccer Predictions using Python (part 4)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id15,801,013
net_rshares0