Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Israel/project #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","id":"a41f3622","metadata":{},"source":["# Probability examples"]},{"cell_type":"markdown","id":"a6bdbd89","metadata":{},"source":["## Example 1 \n","\n","**A Coin Flipping Game**\n","\n","You are the lucky winner of a sweepstakes contest. Your prize is an all-expense-paid vacation\n","at a major hotel in Las Vegas, including some chips for gambling in the hotel\n","casino.\n","\n","Upon entering the casino, you find that, in addition to the usual games (blackjack,\n","roulette, etc.), they are offering an interesting new game with the following rules.\n","Rules of the Game.\n","\n","1. Each play of the game involves repeatedly flipping an unbiased coin until the difference\n","between the number of heads tossed and the number of tails is 3.\n","2. If you decide to play the game, you are required to pay $1 for each flip of the coin.\n","You are not allowed to quit during a play of the game.\n","3. You receive $8 at the end of each play of the game.\n","\n","Thus, you win money if the number of flips required is fewer than 8, but you lose money\n","if more than 8 flips are required. Here are some examples (where H denotes a head and\n","T a tail).\n","\n","- HHH 3 flips You win $5\n","- THTTT 5 flips you win $3\n","- THHTHTHTTTT 11 flips you lose $3\n","\n","Would you join the game ?"]},{"cell_type":"code","execution_count":1,"id":"8939d892","metadata":{},"outputs":[],"source":["# TODO"]},{"cell_type":"markdown","id":"fa58cd64","metadata":{},"source":["## Example 2 \n","\n","**The Monty Hall problem**\n","\n","The Monty Hall problem is a probability puzzle named after Monty Hall, the original host of the TV show Let’s Make a Deal. It’s a famous paradox that has a solution that is so absurd, most people refuse to believe it’s true.\n","\n","Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice? ~ (From Parade magazine’s Ask Marilyn column)\n","\n","Should you Switch?\n"]},{"cell_type":"markdown","id":"1e609466","metadata":{},"source":[]},{"cell_type":"markdown","id":"d2316ae5","metadata":{},"source":["## Example 3\n","\n","**The Taxicab Problem**\n","\n","A cab was involved in a hit and run accident at night. Two cab companies, the Green and the Blue, operate in the city. 85% of the cabs in the city are Green and 15% are Blue.\n","\n","A witness identified the cab as Blue. The court tested the reliability of the witness under the same circumstances that existed on the night of the accident and concluded that the witness correctly identified each one of the two colors 80% of the time and failed 20% of the time.\n","\n","What is the probability that the cab involved in the accident was Blue rather than Green knowing that this witness identified it as Blue?\n"]},{"cell_type":"code","execution_count":null,"id":"6ebc988a","metadata":{},"outputs":[],"source":["# TODO"]}],"metadata":{"interpreter":{"hash":"9248718ffe6ce6938b217e69dbcc175ea21f4c6b28a317e96c05334edae734bb"},"kernelspec":{"display_name":"Python 3.9.12 ('ML-BOOTCAMP')","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.4"}},"nbformat":4,"nbformat_minor":5}
1 change: 1 addition & 0 deletions israel/examples.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","id":"a41f3622","metadata":{},"source":["# Probability examples"]},{"cell_type":"markdown","id":"a6bdbd89","metadata":{},"source":["## Example 1 \n","\n","**A Coin Flipping Game**\n","\n","You are the lucky winner of a sweepstakes contest. Your prize is an all-expense-paid vacation\n","at a major hotel in Las Vegas, including some chips for gambling in the hotel\n","casino.\n","\n","Upon entering the casino, you find that, in addition to the usual games (blackjack,\n","roulette, etc.), they are offering an interesting new game with the following rules.\n","Rules of the Game.\n","\n","1. Each play of the game involves repeatedly flipping an unbiased coin until the difference\n","between the number of heads tossed and the number of tails is 3.\n","2. If you decide to play the game, you are required to pay $1 for each flip of the coin.\n","You are not allowed to quit during a play of the game.\n","3. You receive $8 at the end of each play of the game.\n","\n","Thus, you win money if the number of flips required is fewer than 8, but you lose money\n","if more than 8 flips are required. Here are some examples (where H denotes a head and\n","T a tail).\n","\n","- HHH 3 flips You win $5\n","- THTTT 5 flips you win $3\n","- THHTHTHTTTT 11 flips you lose $3\n","\n","Would you join the game ?"]},{"cell_type":"code","execution_count":16,"id":"8939d892","metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["-3.0\n"]}],"source":["import numpy as np\n","\n","coin_number = np.random.rand(1)\n","\n","def coin_result(coin_number):\n"," if coin_number <= 0.5:\n"," return \"H\"\n"," else:\n"," return \"T\"\n","\n","for sim in range(1000):\n"," \n"," array = []\n"," count_H = 0\n"," count_T = 0\n"," profit = 0\n"," save_profit = []\n"," \n"," coin_number = np.random.rand(1)\n"," result = coin_result(coin_number)\n"," array.append(result)\n"," if result == \"H\":\n"," count_H +=1\n"," else:\n"," count_T +=1\n"," diff = np.abs(count_H - count_T)\n"," profit = 8-len(array)\n"," save_profit.append(profit) \n","avg_profit = np.mean(np.array(save_profit))\n","print(avg_profit)\n"]},{"cell_type":"markdown","id":"fa58cd64","metadata":{},"source":["## Example 2 \n","\n","**The Monty Hall problem**\n","\n","The Monty Hall problem is a probability puzzle named after Monty Hall, the original host of the TV show Let’s Make a Deal. It’s a famous paradox that has a solution that is so absurd, most people refuse to believe it’s true.\n","\n","Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice? ~ (From Parade magazine’s Ask Marilyn column)\n","\n","Should you Switch?\n"]},{"cell_type":"markdown","id":"1e609466","metadata":{},"source":[]},{"cell_type":"markdown","id":"d2316ae5","metadata":{},"source":["## Example 3\n","\n","**The Taxicab Problem**\n","\n","A cab was involved in a hit and run accident at night. Two cab companies, the Green and the Blue, operate in the city. 85% of the cabs in the city are Green and 15% are Blue.\n","\n","A witness identified the cab as Blue. The court tested the reliability of the witness under the same circumstances that existed on the night of the accident and concluded that the witness correctly identified each one of the two colors 80% of the time and failed 20% of the time.\n","\n","What is the probability that the cab involved in the accident was Blue rather than Green knowing that this witness identified it as Blue?\n"]},{"cell_type":"code","execution_count":17,"id":"6ebc988a","metadata":{},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Real Cab</th>\n"," <th>Witness Guess</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Green</td>\n"," <td>Green</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Green</td>\n"," <td>Green</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>995</th>\n"," <td>Green</td>\n"," <td>Green</td>\n"," </tr>\n"," <tr>\n"," <th>996</th>\n"," <td>Green</td>\n"," <td>Green</td>\n"," </tr>\n"," <tr>\n"," <th>997</th>\n"," <td>Green</td>\n"," <td>Green</td>\n"," </tr>\n"," <tr>\n"," <th>998</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>999</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>1000 rows × 2 columns</p>\n","</div>"],"text/plain":[" Real Cab Witness Guess\n","0 Green Blue\n","1 Green Green\n","2 Green Blue\n","3 Green Blue\n","4 Green Green\n",".. ... ...\n","995 Green Green\n","996 Green Green\n","997 Green Green\n","998 Blue Blue\n","999 Blue Blue\n","\n","[1000 rows x 2 columns]"]},"execution_count":17,"metadata":{},"output_type":"execute_result"}],"source":["import numpy as np\n","import pandas as pd\n","\n","result = []\n","for sim in range(1000):\n","\n"," cab_color = np.random.rand(1)\n"," vision_number = np.random.rand(1)\n","\n"," def cab_real(cab_color):\n"," if cab_color <= .85:\n"," return \"Green\"\n"," else:\n"," return \"Blue\"\n","\n","\n"," def witness_guess(cab_real):\n"," if vision_number <= 0.80:\n"," return cab_real\n"," else:\n"," if cab_real == \"Blue\":\n"," return \"Green\"\n"," else:\n"," return \"Blue\"\n"," \n"," real_cab = cab_real(cab_color)\n"," witness_guess = witness_guess(real_cab)\n"," data = {'Real Cab':real_cab, 'Witness Guess': witness_guess}\n"," result.append(data)\n","df = pd.DataFrame(result)\n","df\n"]},{"cell_type":"code","execution_count":18,"id":"86571841","metadata":{},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Real Cab</th>\n"," <th>Witness Guess</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>8</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>11</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>981</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>987</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>992</th>\n"," <td>Green</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>998</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," <tr>\n"," <th>999</th>\n"," <td>Blue</td>\n"," <td>Blue</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>260 rows × 2 columns</p>\n","</div>"],"text/plain":[" Real Cab Witness Guess\n","0 Green Blue\n","2 Green Blue\n","3 Green Blue\n","8 Green Blue\n","11 Green Blue\n",".. ... ...\n","981 Blue Blue\n","987 Blue Blue\n","992 Green Blue\n","998 Blue Blue\n","999 Blue Blue\n","\n","[260 rows x 2 columns]"]},"execution_count":18,"metadata":{},"output_type":"execute_result"}],"source":["df_slice = df.loc[df[\"Witness Guess\"]==\"Blue\"]\n","df_slice"]},{"cell_type":"code","execution_count":19,"id":"9dc6c762","metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Real Cab\n","Green 141\n","Blue 119\n","Name: count, dtype: int64\n"]}],"source":["print(df_slice[\"Real Cab\"].value_counts())"]},{"cell_type":"code","execution_count":20,"id":"d3a773ec","metadata":{},"outputs":[{"data":{"text/plain":["0.4576923076923077"]},"execution_count":20,"metadata":{},"output_type":"execute_result"}],"source":["119/260"]}],"metadata":{"interpreter":{"hash":"9248718ffe6ce6938b217e69dbcc175ea21f4c6b28a317e96c05334edae734bb"},"kernelspec":{"display_name":"Python 3.9.12 ('ML-BOOTCAMP')","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.4"}},"nbformat":4,"nbformat_minor":5}
Loading