cancel
Showing results for
Did you mean:

# Data Science Blog

Machine learning & data science for beginners and experts alike.

## Optimizing Fantasy Football (Soccer) Using Alteryx

Alteryx

Working for an American company I see lots of material posted around Baseball, Basketball and “Football” but being British I am a big follower of proper football.

If you are currently reading this you’re most likely trying to get a competitive edge on colleagues, friends, family playing Fantasy Premier League.  If not, don’t worry the concepts will be easily transferable to different versions or even sports.  If you are already bored by my spiel you can download the annotated workflow at the bottom of the post…

Image credit: www.premierleague.com

First things first, connecting to the database, Fantasy Premier League has a free to use RESTFUL API which can be easily connected to from within Alteryx.  All you need is the URL (https://fantasy.premierleague.com/drf/bootstrap-static) and access to Alteryx Designer (free 14 day trial).  Using the download tool from within Alteryx you will extract all the latest information on each player, Number of Points, Goals, Assist, Yellow Card even their Current Form.  This will be returned in a JSON format so some parsing will be required to get into a more readable format.

The Optimization tool will be used to maximize the number of points a team can get within the constraints of the game.  It may seem daunting but hopefully this will educate you to some of the possibilities of using it.

Input O – This is used to provide the names of the variables (Player Names) the coefficients (value you are trying to maximize (Points)).  You also have the option to include the upper and lower bounds which restrict the number of times a variable (Player Names) can be selected.

Input A – This provides the constraint matrix.  I have used the ‘Dense Matrix Variables in Rows’ which would require the constraints to become your column headers and the variables (Player Names) to go in each Row.

 Variable Players Constraint Striker Constraint Midfielder Constraint Crystal Palace Constraint Man United Zlatan Ibrahimović 1 0 0 1 Wilfried Zaha (HERO) 0 1 1 0 Marcus Rashford 1 0 0 1

Input B – This is used to provide the direction and right hand side of the constraint.  The direction requires operators such as;  >=, ==, <=.  The right hand side is the constraint value.  An example might be, no more than 1 Man United Player and exactly 1 Midfielder so you would have a table like this.

 Constraint dir Rhs Man United <= 1 Midfielder == 1

Every constraint included in Input A must be included in the same order on Input B.

The Optimization tool will output the best selection of variables (Player Names) based on the highest number cumulative coefficient (Points) that meet your constraints.  For additional resources please see below:

My team got off to a shocking start, but has found its footing in the middle of the Alteryx UK league.  I have as of yesterday started to use my Alteryx workflow to push up the table, this started with a wildcard replacing the vast majority of my players.  My blinded faith in Crystal Palace players cost me, now I am shifting all my faith towards AAA, Alteryx Advanced Analytics.

Image credit: https://www.premierleague.com/players/4539/Wilfried-Zaha/overview

Alteryx is being used by many the world’s largest football clubs – I’m not sure if I’m allowed to name any of them, so you will have to trust me.

My challenge to all you clever analysts is to build on this further!

• Weighting on first XI and subs bench
• Consider players that are injured
• Consider upcoming fixtures
• Captain Selection

Attached is a version 11 annotated workflow. So if you want to fully understand how it works please have a look at this.

Recording available here: https://pages.alteryx.com/UKI-FPL-Webinar-OW.html

Atom

Hi Nick,

I was on the webinar last week and really looking forward to watching it again. As I'm very new to Alteryx I really wanted to build the workflow from scratch and experiment a little along the way so that would really help. Any chance on that happening?

(Also - I'm getting some errors on the completed workflow btw)

Alteryx

@DarrylBr

The link at the bottom of the blog post will take you to a recording.

With regards to the error you are getting on the completed workflow, I have updated the attachment to include the supporting macros, so should now work.

Thanks,

Nick

Atom

Hi Nick

Thanks for getting the webinar uploaded - Really great seeing it being built from scratch.

I'm still having a problem with the completed workflow on the optimization tool with the error

GenericTool (232) Cannot find macro "Optimization/Supporting_Macros/Optimization.yxmc".

Do we need to build this ourselves to get the output?

Thanks again

Alteryx

Hello Darryl,

You will be required to have the predictive tools installed.  If you haven't already got them please click on Options --> Download Predictive Tools.

Happy to jump on a call with you if this isn't the case.

Thanks,

Nick

Atom

Hi Nick

How did you get the list of all current BPL players

Thanks,

Nholmes

Alteryx

Hello Nholmes,

If you download the workflow it connects to the API to extract all the players that have participated in the Premier League.

In the demo I use a flat file with all current BPL players that I create from a separate API, use the following URL https://fantasy.premierleague.com/player-list/

Thanks,

Nick

Asteroid

@NickC

Inputs etc being refreshed for the new season?

Top Starred Posts
Latest Articles
Archives