<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 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
Step1:  2. Read in the hanford.csv file in the data/ folder
Step2:  <img src="../../images/hanford_variables.png"></img>
3. Calculate the basic descriptive statistics on the data
Step3:  4. Find a reasonable threshold to say exposure is high and recode the data
Step4:  5. Create a logistic regression model
Step5:  6. Predict whether the mortality rate (Cancer per 100,000 man years) will be high at an exposure level of 50
<ASSISTANT_TASK:>
Python Code:
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("../data/hanford.csv")
Explanation: 2. Read in the hanford.csv file in the data/ folder
End of explanation
df.describe()
Explanation: <img src="../../images/hanford_variables.png"></img>
3. Calculate the basic descriptive statistics on the data
End of explanation
df['Mortality'].hist(bins=5)
df['Mortality'].mean()
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)
def exposure_high(x):
    if x >= 3.41:
        return 1
    else:
        return 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[['Exposure']])
y = np.asarray(df['Mort_high'])
lm = lm.fit(x,y)
Explanation: 5. Create a logistic regression model
End of explanation
lm.predict([50])
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
<END_TASK>