Skip to content

Instantly share code, notes, and snippets.

@audhiaprilliant
Created April 25, 2022 15:31
Show Gist options
  • Select an option

  • Save audhiaprilliant/f63d51fc74bdfd55058eb53176db3b24 to your computer and use it in GitHub Desktop.

Select an option

Save audhiaprilliant/f63d51fc74bdfd55058eb53176db3b24 to your computer and use it in GitHub Desktop.
Simulation of Monty Hall Problem
# Perform a empirical simulation
data_switch = monty_hall(
num_iter = 1000,
switch = True
)
# Create a data rame
df_switch = pd.DataFrame(
data = data_switch
)
# Create a column of probability
df_switch['win_rate'] = (df_switch['win'] / df_switch['iter']).apply(
lambda x: round(x, 3)
)
df_switch['lose_rate'] = (1 - df_switch['win_rate']).apply(
lambda x: round(x, 3)
)
# Show data frame
df_switch.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment