Not all choices are equal
We are all familiar with the classic dilemma - you have two (or more) choices and must decide on the best option. Without any other information, your only option is to go with your intuition. Things may change as more details emerge.
This is the reasoning behind Bayes Theorem, the work of an English minister in the 18th century. Whilst there are different views on probability, Bayes Theorem remains a popular tool for many data scientist's today.
Let's make things clearer with an example.
Did the world's smartest person make the wrong choice?
Marilyn vos Savant has the highest recorded intelligence quotient (IQ) in the Guinness Book of Records, a competitive category the publication has since retired. She introduced us to a seemingly simple challenge - The Monty Hall Problem. After describing the solution, many people (more than 10,000) wrote to Marilyn to describe 'the gross error' she had made. It turns out Marilyn was right all along and many people (including reknowned mathematicians) dined on humble pie that year! It's worth watching on YouTube if you haven't seen it before.
The rules of the game
Imagine you’re on a television game show and the host presents you with three closed doors. Behind one of them, sits a prize beyond your wildest dreams. Behind the other two, are smelly old goats. The host encourages you to pick a door, and you select, let's say, door 1. Then, the host, who is well-aware of what’s going on behind the scenes, opens door 3, revealing one of the goats. The host's offer to you is, do you want to stick with door 1, or switch to door 2?
The broader question is no matter which door you first choose, is it always better to change your mind?
Opening doors with Python
We can support Marilyn with a little Python by running many thousands of Monty Hall simulations. The plots below show that the chances increase significantly when you change your mind about which door to open. In this example, each option is executed 100,000 times.
Recommended by LinkedIn
This shows that when we stick with our first choice, we win approximately a third of the time. When we exercise our option to change, we win approximately two thirds of the time. Switching doors effectively doubles our chance of winning! While this can be proven mathematically, a few lines of code can often provide insights before making any further commitments.
Setting up the starting conditions is simple enough...
def SetupDoors():
# Create 3 doors and hide a prize behind one of them
gameDoors = [False, False, False]
prize = random.randint(0, 2)
gameDoors[prize] = True
return gameDoors
What happens if we stick with our first choice...
correctGuesses = 0
correctList = []
for tries in range(numberOfTries):
doors = SetupDoors()
guess = random.randint(0, 2)
if doors[guess]:
correctGuesses += 1
correctList.append(doors[guess])
What happens if we change our minds...
correctGuesses = 0
correctList = []
for tries in range(numberOfTries):
doors = SetupDoors()
guess = random.randint(0, 2)
# Open a door that has no prize behind it
while True:
openDoor = random.randint(0, 2)
if not doors[openDoor] and openDoor != guess:
break
# Change the guess to the other door
for newGuess in range(len(doors)):
if newGuess != guess and newGuess != openDoor:
guess = newGuess
break
if doors[guess]:
correctGuesses += 1
correctList.append(doors[guess]
There is a jupyter notebook on GitHub with all of the functioning code if you wish to explore for yourself MH/monty.ipynb at master · mattwibboweaver/MH (github.com).
Making sense of it all
We are often overwhelmed with vast amounts of data in the modern world. Our job is to make sense of it all and derive meaningful insights that make our jobs easier and our businesses more successful.
I'd love to learn how data provides value for your business - or help you make sense of it if it doesn't.