<jupyter_start><jupyter_text>Analysis<jupyter_code>decisions = decision_data[list(judge_decisions) + ['House Democrats','House Republicans','Senate Democrats',
                                                   'Senate Republicans','House Independents','Senate Independents',
                                                   'Recess Appointment']]
decisions = decisions.drop(columns = ['Authoring Judge'])
decisions = decisions.dropna()
# We begin by converting the decision ideology, which is either liberal or conservative, into a dummy.
def libcon_dummy(ideology):
    if ideology == 'Conservative':
        return 1
    if ideology == 'Liberal':
        return 0
    else:
        return np.nan
decisions['Decision Ideology'] = decisions['Decision Ideology'].apply(libcon_dummy)
categories_dec = ['Court Location', 'Circuit', 'Case Type', 'Case Category', 'Appointing President', 'Judge Party', 'Gender',
              'Race', 'ABA Rating', 'Congress', 'Unity', 'Recess Appointment']

# Categorical variables 
continuous_variables_dec = list(filter(lambda col: col not in categories_dec + ['Decision Ideology'], list(decisions)))
X_dec_train, X_dec_test, y_dec_train, y_dec_test = prep_data(
    decisions, continuous_variables_dec, categories_dec, 'Decision Ideology'
)
alphas = np.exp(np.linspace(-2., -12., 25))
lr_model = linear_model.LinearRegression(n_jobs = 100)
logistic_model = linear_model.LogisticRegression(solver="liblinear", max_iter = 1000, n_jobs = 100)
lasso_model = linear_model.LassoCV(cv=6, alphas = alphas,  max_iter=500, n_jobs = 100)
forest_model = RandomForestRegressor(n_estimators = 100, n_jobs = 100)
nn_scaled_model = pipeline.make_pipeline(
    preprocessing.StandardScaler(),  # this will do the input scaling
    neural_network.MLPRegressor((150,),activation = "logistic",
                                solver="adam",alpha=0.005)) # we tried a few alphas chose this one 
                                                            # based on minimizing mse_test ... but it was somewhat arbitrary
models = { "OLS": lr_model, "Logistic": logistic_model, "Lasso": lasso_model,
          "Random Forest": forest_model, "Neural Network":nn_scaled_model}
MSE_by_model = pd.DataFrame(index = models.keys(),
                            columns= ["Train MSE","Test MSE"])
ideo_mse_list = [fit_and_report_mses(model,X_dec_train, X_dec_test, y_dec_train, y_dec_test) for model in models.values()]
MSE_by_model['Train MSE'] = ['%f' % result["mse_train"] for result in ideo_mse_list]
MSE_by_model['Test MSE'] = ['%f' % result["mse_test"] for result in ideo_mse_list]
MSE_by_model<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11537001897533207, 'fraction_numerical': 0.014041745730550285, 'mean_word_length': 3.7155635062611805, 'pattern_counts': {'":': 5, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '399427', 'license': 'MIT', 'n_tokens_mistral': 856, 'n_tokens_neox': 799, 'n_words': 194, 'path': 'Carp-Manning Analysis.ipynb', 'repo_name': 'isapollnik/uscourts', 'size': '2635'}