Python Jupyter Notebook Logistic Regression
The dataset can be found on KAGGLE (COMPAS SCORES).
data = pd.read_csv('compas-scores-two-years.csv')
data = data.query('days_b_screening_arrest <= 30 & days_b_screening_arrest >= -30')
data
1A is not complete and needs an explanation for 1c.
Question 1. Logistic Regression: What are the odds of getting a high-risk score?
A higher (i.e., more "risky") score. COMPAS labels scores 1-4 as low, 5-7 as medium, and 8-10 as high scores. For the purposes of their analysis, ProPublica labeled any score above a low score as high.
Question 1a (i)
Create a logistic regression model to predict the score of defendants based on their sex, age, race, previous arrests, seriousness of the crime, and future criminal behavior. Please be sure to:
- Standard scale your inputs
- One-hot encode categorical inputs (hint: pd.get_dummies() is a useful function!)
For the purposes of this notebook, do not worry about cross-validation or parameter selection. Please use the default LogisticRegression object (already imported at the top).
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
feature_columns = select_data[["sex", "age", "race", "priors_count", "c_charge_degree", "two_year_recid"]]
target_column = select_data["score_text"]
Question 1a (ii)
Print out the coefficients paired with the corresponding feature names
# Pair the coefficients with feature names
# Student Code Here
Question 1c
Are Black defendants more likely to get a high-risk score opposed to white defendants? If so, by how much? Show your calculations.
# Student Calculations Here