Soccer Predictions using Python (part 3)

in #programming7 years ago

Hello again.  I've been busy today with some updates to the code, adding a fair bit of functionality.  I'm also starting to get to grips with using Github.

The first thing added was an option to limit how much of the historical data the poisson function will consider in making it's predictions.  I think this will vary a lot depending on both the country and the competition but I've set the default to 100 games.  We should be able to calculate a usable value for this from the amount of games in each season.  It would probably be worthwhile applying a bit of machine learning to this also. (Definitely going down the ML route in the future...)

Next, I added a function to update the data file and bring in the latest scores.    I also added a data folder and changed the static "data.csv" filename to one based on the country and competition to allow it to work on multiple competitions without destroying previous data.

This was then all tied together with Python's argparse function to let us control the program without altering the code each time.

So to run the program we can now do something like this...

python3 soccerprediction.py -u -c Scotland -l Premiership -d 2017-09-23

This will get the data for the Scottish Premiership, update it if necessary and predict games for 23rd September.  It will output to data/Scotland-Premiership.csv in the current folder.  You can use "-p ~/SoccerPredictions/" to store to your home folder.

Available options are

  • -u or --update to request an update, default is no update
  • -c or --country to set country, defaults to "England"
  • -l or --league to set competition/League, defaults to "Premier League"
  • -d or --date to predict games on specific date, defaults to today's date
  • -p or --path to set data path, defaults to "data/"
  • -y or --history to set how many historical games to consider, defaults to 100

I added a couple of extra calculations from the poisson, so in addition to homewin, draw and awaywin probabilities, the function now predicts the total number of expected goals, and probabilities for both teams to score and 3 or more goals.

The code's getting a bit longer now so I haven't included it within this article but it is freely available at the GitHub site.  Please download and have a play with it.  If you can improve it or have any suggestions or questions, let me know.

I've run predictions for both the English Premier League and the Scottish Premiership, so for the record, here are those predictions.

Home Away homewin draw awaywin goals 3+ btts
Burnley Huddersfield 18.08 25.56 56.36 2.30 40.41 41.57
Everton Bournemouth 22.96 44.21 32.83 1.087 9.80 17.25
Leicester Liverpool 32.00 17.16 50.84 5.38 90.40 86.30
Man City Crystal Palace 98.91 1.09 0 4.51 82.87 0
Southampton Man Utd 12.03 36.80 51.17 1.29 13.94 17.07
Stoke Chelsea 3.93 12.44 83.63 2.85 54.27 28.58
Swansea Watford 19.62 23.75 56.63 2.63 48.97 48.64
West Ham Spurs 1.68 5.85 92.47 3.87 74.35 30.39
Kilmarnock Dundee 46.00 32.58 21.41 1.72 24.84 31.24
Partick Thistle Hearts 38.24 30.95 30.81 1.97 31.67 39.14
Rangers Celtic 6.72 11.09 82.19 4.08 77.35 56.23
Ross County Hibs 37.00 21.96 41.04 3.60 69.77 69.82
St. Johnstone Hamilton 66.64 22.16 11.20 2.34 41.47 36.14

I'll be back with more updates soon, including (hopefully) getting some Machine Learning into the mix. As usual, your comments, advice and questions are all more than welcome.

Sort:  

I really need to work on my formatting. :-)

This post recieved an upvote from minnowpond. If you would like to recieve upvotes from minnowpond on all your posts, simply FOLLOW @minnowpond

Congratulations @stevencurrie! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got a First Reply

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

I don't understand anything about code, but the subject interests me. :)

Hey, it's worth trying to pick it up, I find it immensely enjoyable. There are plenty of beginners tutorials here on Steemit and on the rest of the net. In fact @cristi posted a link that includes a bunch of nice free Python books a few days back - here.

(Don't do it if you value your time though. I regularly find myself wondering why I'm hungry or why it's suddenly light outside, then realising I've been sitting at the keyboard for 20 hours straight.)

Coin Marketplace

STEEM 0.25
TRX 0.11
JST 0.029
BTC 69095.98
ETH 3678.90
USDT 1.00
SBD 3.48