Beating the Fantasy Premier League game with Python and Data Science

They more often than not base their decisions on which teams they support and on which EPL players are the “hottest” at the moment and are considered superstars.We believe that if we remove bias and favoritism from the decision-making process and just focus on individual player stats and overall team performance when picking our Fantasy squad, we can do much better than the Average Joe at the end of the season.2..Key questions our analysis will aim to answer:Is there a correlation between individual player Fantasy League stats, their team’s total points in the English Premier League EPL and their corresponding table position?Can we identify the teams that have a lot of underperforming overpriced players and those that have a very solid undervalued squad so we can tell our algorithm to pick from these teams accordingly?Can we approach the Official English Premier League Fantasy game as an equivalent of the stock market and look at individual players as financial assets and try to find all the underpriced and overpriced players based on their ROI and invest our budget accordingly?Individual Player ROI = Player Fantasy points / Player Cost (or in other words our total point return per 1MM Fantasy-dollar spent.)Our theory is that this can help spend our limited Fantasy League budget of 100MM on players that will generate the maximum number of points possible per Fantasy Dollar spent throughout the length of the season.If that turns out to be true, can we then use Python to build an algorithm that optimizes the use our budget by picking as many of the high ROI players as possible?How does our Algorithm stack against the average person who plays the EPL Fantasy?.Also, we should be able to identify the teams with coaches that do not use frequent player rotation, which would create a solid core of regular squad players that play 90 minutes almost every game and generate a high aggregate ROI in the long run.In the graph above we’re looking for teams with a very tall “blue bar” (cumulative player ROI) and a shorter “orange bar” (total number of players that the coach uses on a regular basis)..The plan is to isolate a list of players with the highest ROI and write a Python algorithm that will use smart logic to pick the most optimal combination of individual players, which will generate the highest return on investment for our limited budget of 100MM.Looking at the scatter plot of Player Cost vs..Player Total Fantasy Points above, we would want our AI to pick players who appear as west-north as possible on the plot(Players with low Cost that generate a lot of Fantasy Points)..Writing the Python Algorithm for picking the optimal Fantasy teamNow it’s time for the most fun part — writing the actual Python algorithm and comparing the results of the AI picks to what an average person might pick for their Fantasy team.To understand the logic of our Algorithm one must first understand the rules and constraints of the EPL Fantasy Game below:Each fantasy player starts with a limited budget of 100MM and has to buy 15 soccer players (11 for the main squad + 4 subs) in order to compete.You need to have at least 2 Goalkeepers, 5 Defenders, 5 Midfielders, and 3 Strikers in order to complete your squad and be eligible to play.You cannot have more than 3 players from the same soccer team.So, we start our python algorithm with and if-else statement for these conditions and then we add our own conditions and logic on top of that, so that each time that the algorithm loops through our list of players, it can use smart logic to make a valid pick guided by our conditions below:Check if a player is injured, suspended or unavailable to play and if so, do not pick that player for our Fantasy team even if they have a high ROI.Pick the top three star players with the most cumulative league points in the league first..(We will test the outcome of this condition with different numbers of star-players and pick the version that generates the biggest return on investment, while still allowing enough left-over budget to fill the squad.)Every time we pick a player and add it to our team, we subtract their cost from our 100MM budget and we add their position and team-name to a list, to make sure that we stop buying players for the positions and the teams that hit their constraint limit.Once the optimal number of expensive superstar players are picked, the Algorithm starts going through the list of players with the highest ROI and tries to get us as many of the top names as we can, until we get close to depleting our budget and filling all of the team positions.Algorithm prints a list of the players it picked at the end and gives us the remaining budget and the total fantasy points of the team.Here is some of our condensed Python Code for the team picking algorithm:Optimal Fantasy Team SelectorBelow you can see a screenshot of the final team that our Algo picked:Money Team (944 Total Fantasy Points)Note: We wrote a similar algorithm for the AVG Joe team, which focuses more on spending the budget on star players from big teams, who are often overpriced and might not return the highest cumulative ROI for our limited budget of 100M.Note: We also asked a classmate to pick a random team of his own, so we can compare his picks and verify that our random team picker function for the AVG Joe algorithm is accurate.4..Did the AVG Joe Algoritm and our classmate pick more of the expensive overpriced players from the top teams?Below we can see that our Algorithm picked a combination of players from most of the high ROI teams that we identified at the beginning of our project:Money Team Player distributionThis is a much more balanced and unbiased selection method than what the AVG Joe used when selecting his/her players..Since the AVG Joe spent most of his/her budget on picking 11 very expensive players, he/she had to spend the remaining budget on the cheapest available players to fill in all the substitute positions, but none of these players can be used to generate fantasy points due to the fact that they never actually played in the real games and were only used as team fillers..This deep dive into the player data allowed us to realize that we were allowing team favoritism and a tendency to buy a lot of the overpriced players hurt our overall Fantasy League performance.5.. More details

Leave a Reply