Tuesday, September 15, 2015

Fantasy Football Optimization and PuLP

I've written previously about how to solve a basic fantasy football optimization using lpSolve in R. It's not terribly easy to read and just as hard to debug. That's why I was thrilled to find a Python package called PuLP. I found this package to be very simple and much easier to use than any open source solvers in R. Using the same logic described in my previous post, I implemented it using this package. Here's the code for reference:


Tuesday, September 8, 2015

Koding: R analytics environment

This is a pretty random post, but I found a nice website that was worth sharing. There are several online websites and courses that will teach you a programming language of your choice. Most have the same requirements, have a laptop and install the open source software / language on your laptop. What happens if you have an aging laptop? Or a chromebook? Or maybe just an iPad? The answer is Koding.com.

Koding allows you to setup a free Ubuntu server. Their goals are to enable users with the ability to learn programming. In addition, this gives the user the ability to learn Linux as well. You can install your utilities, understand commands and even setup basic workflows. The server has modest specifications, but with just a few commands you can install and run R.

Here's a quick few lines on getting started:

sudo nano /etc/apt/sources.list

Add this line at the end of the file:
deb https://cran.rstudio.com/bin/linux/ubuntu trusty/

Then hit control+x to exit. 
Hit Y to save the file. 
Hit Enter to overwrite the file.

sudo apt-get update
sudo apt-get install r-base

Enter Y to continue.
Enter Y to install the base packages.

Now you’re ready to go. Type in the command “R” to get started.

Tuesday, September 1, 2015

Simulating a baseball game

As many of you know, I'm an avid baseball fan. Therefore, whenever I come across a topic involving Operations Research and baseball, I can't just simply ignore it. Awhile ago, I discovered this website that analyzes the strategies of a team throughout a baseball game. It's an interesting approach that uses dynamic programming to maximize the probability of winning the overall game by breaking up each inning into the various situations that are possible and then picking the optimal strategy for that situation.

My first reaction was, "Cool! I want to play with it!" But wait, it's in MATLAB?! I don't have MATLAB at home. I had a couple of options, I could try and get a copy of MATLAB (which is not very cheap) or translate to a language I had access to on my laptop. I thought about R, Python, or potentially learning Octave but eventually sided with R. Below are links to the Git that has the translated code in R. Note that this version is strictly a translation and has not been optimized for the R language.

This is really a work in progress since I'd like to build it out a bit. Here's what I see as future work I hope to accomplish on this problem:
  1. Optimize for the R language and decrease overall runtime for a particular run.
  2. Adjust for a team of different players (currently assumes the same player at all nine hitting spots). 
  3. Create a nice way to visualize the results.
  4. Link to more recent data. 
    1. Through the Lahman package.
    2. Through "live" data.
  5. Add in ability to manipulate lineup order and be able to compare pros and cons behind various strategies.
  6. Add in ability for lineup substitutions.
Links:
Github repository
Original Problem website