Saturday, July 30, 2011

Fantasy Football Optimisation

Some friends challenged me to a game called fantasy "football" where you pretend to be a Russian billionaire. Not the bit where you steal natural resources off the population but where you buy a bunch of poncy overpaid foreigners who flounce around and earn insane amounts of money.

While I'm ranting about "football". Why do football ads always say it has "the beauty of a dance". If you like dancing that much go to the ballet



Anyway So I have to pretend to know something about this "football" which I dont but I do know a bit about optimization and more about copying stuff. I remembered this old R package article about optimising for fantasy football. This was written by prasoonsharma and I have just reused his code.

I scraped last seasons scores off the fantasy premierleague website. Some parsing turned this into the correct format. You can download the cleaned up data here

The constraints for this version of the game are slightly different than the one prasoonsharma was playing. This means you need more goalies, have more money to spend on players and other such changes.

The best single team for last season would have been

Player Club Pos Price Pts
1 Hart MCI GK 70 175
5 Al-Habsi WIG GK 45 125
48 Ivanovic CHE DEF 70 144
49 Huth STO DEF 60 138
51 Hughes FUL DEF 50 129
54 Bardsley SUN DEF 50 123
55 Johnson WOL DEF 50 120
197 Adam LIV MID 90 192
200 Dempsey FUL MID 85 168
201 N'Zogbia WIG MID 75 167
210 Jarvis WOL MID 60 133
212 Barton NEW MID 60 131
386 Berbatov MUN STR 95 176
388 Odemwingie WBA STR 75 171
393 Davies K BOL STR 65 132

with a total score of 2224 points. You get to change the team every week in the real game. This optimisation is just if you got to pick one team and leave it.

Picking a fantasy football team involves
1. Predicting how many points each player will score that week
2. Optimising based on this prediction so you pick the team that covers all the rule constraints that scores the most points.

This code carries out the second part. If you have a prediction for how many points players will score that is better than
"exactly the same amount they scored last season" you can change the data with your new prediction and run it (or I can run it for you if you want). A web app that allowed you to enter your player score predictions and ran an optimisation so that the best team that could be picked based on your predictions was then created might be useful. If you save the data in a new google doc and change the Pts values to your player predictions. Then post a link to that google doc in the comments I will run the optimisation for you.

No comments: