alteryx Community

Data Science

Machine learning & data science for beginners and experts alike.

Introducing Alteryx Optimization Tool: Part 1: Fantasy Baseball Daily Line-up Problem

Alteryx Alumni (Retired)

The new Optimization tool has just come out in the Alteryx 10.6 Predictive Release (see Dr Dan's post on prescriptive analytics). With this single tool, we can solve linear programming, mixed integer linear programming and quadratic programming problems. The tool offers 3 input modes (manual input, file input and matrix input) to give you flexibility in defining your model. If you are a baseball fan and Alteryx fan, I have a great news for you! Today I'll show you how to use the Alteryx Optimization tool to solve a fantasy baseball daily lineup problem.

The fantasy baseball daily lineup problem is very straight-forward: given a fixed budget and 6 types of field positions to fill in, how should you draft players based on their projected points, salary and field positions? In other words, we want to

1. maximize the total projected points of all drafted players.
2. make sure the total salary for the 9 players is under budget.
3. make sure each field postion is filled, i.e. we want
• 1 Pitcher (P)
• 1 Base 1 player (1B)
• 1 Base 2 player (2B)
• 1 Short Stopper (SS)
• 1 Base 3 player (3B)
• 1 Catcher (C)
• 3 Out Fielders (OF)

The decision we need to make is: which players to pick.

The tricky part is how to express the objective, constraints and decisions above mathematically.
Let's denote

• xi: the decision whether we will draft the i'th MLB player. For example, if x6 = 1, then the 6th player will be drafted, if x6 = 0, then the 6th player won't be drafted.
• Pti: the projected points the i'th player will earn.
• Si: the salary of the i'th player.
• Pi: whether the i'th player is a pitcher. For example, if P5 = 1, then the 5th player is a pitcher, if P5 = 0, then the 5th player is not a pitcher.
• Similarly, 1Bi, 2Bi,  SSi3Bi, Ci, OFi : whether the i'th player plays Base 1, Base 2, Short Stop, Base 3, Catcher and Out Field respectively.

where, i  can be 1, 2, ... 384 (384 is the total number of MLB players in the data set we are going to use in the attached example.) Based on the notations and assume our budget is \$25200, the mathematical formulation for the daily fantasy baseball problem is as follows:

Once we have constrcuted the formulation, it is very straight-forward to use the new Optimization tool in Alteryx, since the inputs for Optimization tool are essentially different parts of the formulation.

We first obtain baseball player data from http://www.rotowire.com/daily/mlb/optimizer.htm and load it into Alteryx. Let's take a look the first couple of rows of data:

It is easy to see that only the columns in red circles are relevant to our problem setup. (Note that Pos stands for "position" and Pts is short for "projected points".) Configuring the Optimization tool is simple. Since we will use the baseball player data as input, instead of an industry standard optimization modelling file (e.g CPLEX_LP, MathProg, or MPS format), we will use "matrix input" mode. Because our decision variables (x1, x, ..., x384) can only have values 0 or 1, this is a mixed integer programming problem. We use "Symphony" as the solver, due to its overall better performance on mixed integer linear programming over "GLPK".

For Optimization inputs, please see the comments in the attached workflow for details. Thanks to @ramnath and @cfreeman's hard work, the Optimization tool generates an interactive report of which players you should select, and more.

For more details, see Optimization Tool Help.