Created
April 25, 2022 15:31
-
-
Save audhiaprilliant/f63d51fc74bdfd55058eb53176db3b24 to your computer and use it in GitHub Desktop.
Simulation of Monty Hall Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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