{ "cells": [ { "cell_type": "markdown", "metadata": { "tags": [ "s1", "content", "l1" ] }, "source": [ "# Independent Events\n", "\n", "Consider the example of drawing a ball from a bucket consisting of many different colored balls. For simplicity, consider that there are only two different colored balls - 6 Green balls and 4 Red balls, 10 balls in total. Now draws can be made in two different ways:\n", "\n", "* with replacement - The ball drawn in every single draw is kept back into the bucket, keeping the total number of balls and mixture of colored balls constant, from draw to draw.\n", "\n", "* without replacement - A ball drawn in a single draw is retained and not replaced or substituted in any way in the bucket. This changes total number of balls and mixture of balls with each draw. Note that with no replacement or substitution, the total number of single ball draws that can be made in the bucket would be equal to the total number of balls in the bucket.\n", "\n", "\n", "\n", "When balls are drawn without replacements, each draw affects the probabilities/outcomes of subsequent draws and say, the outcome of the second draw will be dependent upon the outcome of the first draw. In the same scenario, if balls are drawn with replacement, that is, every ball drawn is kept back into the bucket or is replaced with an identical ball, then every draw is independent of another/subsequent draws.\n", "\n", "So, when the probability of occurrence of event A does not, in any way, affect the probability of occurrence of event B and vice versa, then A and B are said to be independent events (events whose probability of occurrence is independent of each other).\n", "\n", "Examples are \n", "\n", "* Tossing of two coins : Occurrence of heads in one coin is independent of occurrence of heads/tails in the second coin.\n", "* Rolling of two dice : The number on one die does not in any way affect the number on rolling the second die.\n", "\n", "\n", "\n", "\n", "\n", "## Multiplication Rule and Conditional Probability\n", "\n", "According to the Multiplication Rule, if **A** and **B** are two independent events then,\n", "\n", "**P(A $\\cap$ B) = P(A) * P(B)**\n", "\n", "Conditional probability of occurence of event B given event A has occurred is given by,\n", "\n", "**P(B|A) = $\\frac{P(A \\cap B)}{P(A)}$**\n", "\n", "But since **A** and **B** are independent events,\n", "\n", "**P(B|A) = $\\frac{P(A) * P(B)}{P(A)}$**\n", "\n", "**P(B|A) = $P(B)$**\n", "\n", "Now we can see that conditional probability of **B** given **A** is equal to **B** itself, which goes to show that occurrence or non-occurrence of **A** does not affect the probability of occurrence of **B** in any way.\n", "\n", "### Exercise\n", "\n", "Given there are 100 transactions executed in a given day. Let us assume that in terms of failure of transaction the 100 transactions are classified into 2 categories, high risk - 35 transactions and mid-risk - 65 transactions. High risk are transactions with higher probability of failure and mid-risk are transactions that have relatively lower risk of failure. Lets say there are 100 customers belonging to 3 major countries - 25 from Region1, 30 from Region2 and the rest from Region3. \n", "\n", "A transaction is picked from the above given list of transactions and also a customer is picked from the list of all customers.\n", "\n", "* Compute the probability of the transaction being a high risk transaction and the customer belonging to Region3. Assign the value to a variable \"hr_int_reg3\".\n", "\n", "Note that in this example, the transaction need not be necessarily made by the customer. The transaction data and customer data are not connected in this scenario, and hence they are independent of each other. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true, "tags": [ "s1", "ce", "l1" ] }, "outputs": [], "source": [ "# Pre-loaded code\n", "\n", "Total_trs = 100\n", "hrisk = 35\n", "mrisk = 65\n", "\n", "Total_cust = 100\n", "Region1 = 25\n", "Region2 = 30\n", "Region3 = 45\n", "\n", "P_of_hrisk =\n", "P_of_mrisk =\n", "\n", "P_of_Region1 =\n", "P_of_Region2 =\n", "P_of_Region3 =\n", "\n", "hr_int_reg3 = " ] }, { "cell_type": "markdown", "metadata": { "tags": [ "s1", "l1", "hint" ] }, "source": [ "# Hint\n", "\n", "Use the multiplication rule stated above to solve the combined probability of both the independent events" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [ "s1", "l1", "ans" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1575\n" ] } ], "source": [ "# Solution\n", "\n", "P_of_hrisk = hrisk/Total_trs\n", "P_of_mrisk = mrisk/Total_trs\n", "\n", "P_of_Region1 = Region1/Total_cust\n", "P_of_Region2 = Region2/Total_cust\n", "P_of_Region3 = Region3/Total_cust\n", "\n", "hr_int_reg3 = P_of_hrisk * P_of_Region3\n", "\n", "print(hr_int_reg3)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [ "s1", "hid", "l1" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "continue\n" ] } ], "source": [ "ref_tmp_var = False\n", "\n", "# ref_assert_var block\n", "\n", "try:\n", " ref_assert_var = False\n", " test1 = 0.1575\n", " \n", " if test1 == hr_int_reg3:\n", " ref_assert_var = True\n", " \n", "except Exception:\n", " print('Please follow the instructions given and use the same variables provided in the instructions.')\n", "else:\n", " if ref_assert_var == True:\n", " ref_tmp_var = True\n", " else:\n", " print('Please follow the instructions given and use the same variables provided in the instructions.')\n", "\n", "assert ref_tmp_var" ] } ], "metadata": { "executed_sections": [], "kernelspec": { "display_name": "Python 3", "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }