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
| # Data frame manipulation | |
| import pandas as pd | |
| # Matrices operation | |
| import numpy as np | |
| # Data visualization with plotnine | |
| from plotnine import * | |
| import plotnine |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| plotnine.options.figure_size = (10, 4.8) | |
| ( | |
| ggplot( | |
| data = df_general | |
| )+ | |
| geom_line( | |
| aes(x = 'iter', | |
| y = 'value', | |
| group = 'status', | |
| color = 'status'), |
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_general = monty_hall( | |
| num_iter = 1000, | |
| switch = True | |
| ) | |
| # Create a data rame | |
| df_general = pd.DataFrame( | |
| data = data_general | |
| ) |
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
| # Probability of winning the game (stick in the door) | |
| plotnine.options.figure_size = (10, 4.8) | |
| ( | |
| ggplot( | |
| data = df_stick | |
| )+ | |
| geom_line( | |
| aes(x = 'iter', | |
| y = 'win_rate', | |
| group = 1), |
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_stick = monty_hall( | |
| num_iter = 1000, | |
| switch = False | |
| ) | |
| # Create a data rame | |
| df_stick = pd.DataFrame( | |
| data = data_stick | |
| ) |
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
| # Probability of winning the game (switch the door) | |
| plotnine.options.figure_size = (10, 4.8) | |
| ( | |
| ggplot( | |
| data = df_switch | |
| )+ | |
| geom_line( | |
| aes(x = 'iter', | |
| y = 'win_rate', | |
| group = 1), |
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 | |
| ) |
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
| # Monty Hall Problem | |
| def monty_hall( | |
| num_iter: int, | |
| switch: bool | |
| ): | |
| # Data object | |
| obj = [] | |
| for iteration in range(num_iter): | |
| # Possibilities in doors |
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
| # Data frame manipulation | |
| import pandas as pd | |
| # Mathematical operations | |
| import numpy as np | |
| # Data visualization | |
| import plotnine | |
| from plotnine import * |