# 1.Law of Total Probability

Last updated: August 31st, 2020
In [2]:
import pandas as pd

In [3]:
toy_dataset = pd.read_csv('Churn Modeling.csv')

Out[3]:
RowNumber CustomerId Surname CreditScore Geography Gender Age Tenure Balance NumOfProducts HasCrCard IsActiveMember EstimatedSalary Exited
0 1 15634602 Hargrave 619 France Female 42 2 0.00 1 1 1 101348.88 1
1 2 15647311 Hill 608 Spain Female 41 1 83807.86 1 0 1 112542.58 0
2 3 15619304 Onio 502 France Female 42 8 159660.80 3 1 0 113931.57 1
3 4 15701354 Boni 699 France Female 39 1 0.00 2 0 0 93826.63 0
4 5 15737888 Mitchell 850 Spain Female 43 2 125510.82 1 1 1 79084.10 0

exercise: Check that the probability of a person withdrawing their account using the law of total probability is the same as we calculated in the previous assignments

$P(A)=P(A|B)\times P(B)+P(A|B')\times P(B')$

With B= the person is Female.

In [ ]:


In [4]:
data_E = toy_dataset[(toy_dataset["Exited"]==1)]
data_FE = toy_dataset[(toy_dataset["Gender"] == "Female") & (toy_dataset["Exited"]==1)]
data_F= toy_dataset[toy_dataset["Gender"] == "Female"]
data_M= toy_dataset[toy_dataset["Gender"] == "Male"]
data_ME = toy_dataset[(toy_dataset["Gender"] == "Male") & (toy_dataset["Exited"]==1)]
PFE=data_FE.shape[0]/data_F.shape[0]
PME=data_ME.shape[0]/data_M.shape[0]
PFE*(data_F.shape[0]/toy_dataset.shape[0])+PME*(data_M.shape[0]/toy_dataset.shape[0]),data_E.shape[0]/toy_dataset.shape[0]

Out[4]:
(0.2037, 0.2037)
In [ ]:


In [ ]: