Apply logistic regression to categorize whether a county had high mortality rate due to contamination

1. Import the necessary packages to read in the data, plot, and create a logistic regression model


In [1]:
import pandas as pd
%matplotlib inline
import numpy as np
from sklearn.linear_model import LogisticRegression

2. Read in the hanford.csv file in the data/ folder


In [2]:
df = pd.read_csv("hanford.csv")

In [3]:
df


Out[3]:
County Exposure Mortality
0 Umatilla 2.49 147.1
1 Morrow 2.57 130.1
2 Gilliam 3.41 129.9
3 Sherman 1.25 113.5
4 Wasco 1.62 137.5
5 HoodRiver 3.83 162.3
6 Portland 11.64 207.5
7 Columbia 6.41 177.9
8 Clatsop 8.34 210.3

3. Calculate the basic descriptive statistics on the data


In [4]:
df.describe()


Out[4]:
Exposure Mortality
count 9.000000 9.000000
mean 4.617778 157.344444
std 3.491192 34.791346
min 1.250000 113.500000
25% 2.490000 130.100000
50% 3.410000 147.100000
75% 6.410000 177.900000
max 11.640000 210.300000

In [10]:
df['Exposure'].max() - df['Exposure'].min()


Out[10]:
10.390000000000001

In [11]:
df['Mortality'].max() - df['Mortality'].min()


Out[11]:
96.800000000000011

In [12]:
df['Exposure'].quantile(q=0.25)


Out[12]:
2.4900000000000002

In [ ]:
df['Exposure'].quantile(q=0.25)

In [13]:
df['Exposure'].quantile(q=0.5)


Out[13]:
3.4100000000000001

In [14]:
df['Exposure'].quantile(q=0.75)


Out[14]:
6.4100000000000001

In [20]:
iqr_ex = df['Exposure'].quantile(q=0.75) - df['Exposure'].quantile(q=0.25)
iqr_ex


Out[20]:
3.9199999999999999

In [16]:
df['Mortality'].quantile(q=0.25)


Out[16]:
130.09999999999999

In [17]:
df['Mortality'].quantile(q=0.5)


Out[17]:
147.09999999999999

In [18]:
df['Mortality'].quantile(q=0.75)


Out[18]:
177.90000000000001

In [22]:
iqr_mort = df['Mortality'].quantile(q=0.75) - df['Mortality'].quantile(q=0.25)
iqr_mort


Out[22]:
47.800000000000011

In [23]:
df.std()


Out[23]:
Exposure      3.491192
Mortality    34.791346
dtype: float64

4. Find a reasonable threshold to say exposure is high and recode the data


In [ ]:


In [ ]:


In [ ]:


In [ ]:

5. Create a logistic regression model


In [ ]:


In [ ]:


In [ ]:

6. Predict whether the mortality rate (Cancer per 100,000 man years) will be high at an exposure level of 50


In [ ]:


In [ ]: