import pandas as pd
%matplotlib inline
import numpy as np
from sklearn.linear_model import LogisticRegression

"""
Explanation: 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
End of explanation
"""


df=pd.read_csv('/home/sean/git/algorithms/class7/data/hanford.csv')

"""
Explanation: 2. Read in the hanford.csv file in the data/ folder
End of explanation
"""


df.describe()

"""
Explanation: <img src="/home/sean/git/algorithms/class7/images/hanford_variables.png"></img>
3. Calculate the basic descriptive statistics on the data
End of explanation
"""


df

df['Mort_High']=df['Mortality'].apply(lambda x:1 if x>=147.1 else 0)
df['Expo_High']=df['Exposure'].apply(lambda x:1 if x>=3.41 else 0)

df

"""
Explanation: 4. Find a reasonable threshold to say exposure is high and recode the data
End of explanation
"""


lm = LogisticRegression()

x = np.asarray(df[['Expo_High']])
y = np.asarray(df['Mort_High'])

lm = lm.fit(x,y)

"""
Explanation: 5. Create a logistic regression model
End of explanation
"""


lm

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


