What is a Monte Carlo Simulation? (Part 1)

  1. Every time we take a step, we roll a dice to see what direction we go in.
  2. If the step places our intoxicated bro inside a table or through a wall, we stop the simulation and call it a “failure to make it to the bathroom.”
  3. If the step places our blitzed comrade through the bathroom door, we stop the simulation and call it a success.
  4. If this is his 50th step since leaving the bar, we’ll stop there because we don’t believe he could realistically take that many steps in a row. This will constitute a failure.

Election prediction

The statistically driven site fivethirtyeight uses Monte Carlo to estimate election odds. At a high-level, their method is to take lots of polls and aggregate them together. For each state (or district), they develop a set of rules for randomly rolling an election result for that state. So in a presidential election, if the average poll says 53% Democrat, 47% Republican, and there’s a standard deviation of 5%, they will randomly draw from a normal distribution with a mean of 53% and a width of 5%. If the state is above 50%, it counts towards the democrat, if it’s below 50% it counts toward the Republican. If you do this for all 50 states, you’d have one “full” election simulated and can see who wins. Then, to make the whole thing more statistically sound, you could simulate hundreds of thousands of elections using the same polling structures, and see which candidate wins and how often (it won’t always be the same since they’re drawing from the distributions randomly). If the Democrat wins 54% of your simulated elections, you’d say there’s a 54% chance the Democrat wins. There are ways that fivethirtyeight improves on this by including extra information, but this is the basics of the method.

Sports results

Let me shamelessly plug my own little toy example here: Baseball Simulator. This method reads the data about each pitcher and batter, and then simulates, batter by batter, what the result will look like. You can see the “About” page there to read in more detail about how it works. If you run 10,000+ games with two teams input, it will converge on which team is actually the better team (based on their stats). It does a pretty good job and is fairly fun to play around with.

Weather prediction

Modeling the weather is HARD. Like, really really hard. There are two ways you can go about it. 1) You can do a fluid dynamics simulation where you track the whole atmosphere really accurately, accounting for every cubic inch of sky and water. That could work if you had unlimited time and resources. Or 2) you can track the “ballpark” behavior of a bunch of big sections of the atmosphere and then simulate it thousands of times. Then, if it rains in 6,000 out of your 10,000 simulations, you label it as a 60% chance of rain. Most weather systems use the latter (with some really neat optimizations we don’t have time to talk about).

Monte Carlo sounds pretty neat…

All this is to say that there are tons of REALLY cool applications of Monte Carlo techniques that exist in our daily lives. It’s an extremely underrated technique that doesn’t get nearly as much love as it deserves. I’ve even undersold its flexibility a bit, as Monte Carlo’s don’t have to have the EXACT same rules at every step. Instead, things like “state-driven probabilities” are possible. We’ll see more about that in a separate blog, as it opens a whole new world of possible problems we can solve.

Accelerating data science careers through full-time bootcamps, part-time professional development courses, corporate training & more. NYC | SF | CHI | SEA | DC.

Share your ideas with millions of readers.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store