<jupyter_start><jupyter_text>Data Cleaning & Split the Data into Training and Testing<jupyter_code>columns = [
    "loan_amnt", "int_rate", "installment", "home_ownership", "annual_inc", 
    "verification_status", "pymnt_plan", "dti", "delinq_2yrs", 
    "inq_last_6mths", "open_acc", "pub_rec", "revol_bal", "total_acc", 
    "initial_list_status", "out_prncp", "out_prncp_inv", "total_pymnt", 
    "total_pymnt_inv", "total_rec_prncp", "total_rec_int", 
    "total_rec_late_fee", "recoveries", "collection_recovery_fee", 
    "last_pymnt_amnt", "collections_12_mths_ex_med", "policy_code", 
    "application_type", "acc_now_delinq", "tot_coll_amt", "tot_cur_bal", 
    "open_acc_6m", "open_act_il", "open_il_12m", "open_il_24m", 
    "mths_since_rcnt_il", "total_bal_il", "il_util", "open_rv_12m", 
    "open_rv_24m", "max_bal_bc", "all_util", "total_rev_hi_lim", "inq_fi", 
    "total_cu_tl", "inq_last_12m", "acc_open_past_24mths", "avg_cur_bal", 
    "bc_open_to_buy", "bc_util", "chargeoff_within_12_mths", "delinq_amnt", 
    "mo_sin_old_il_acct", "mo_sin_old_rev_tl_op", "mo_sin_rcnt_rev_tl_op", 
    "mo_sin_rcnt_tl", "mort_acc", "mths_since_recent_bc", 
    "mths_since_recent_inq", "num_accts_ever_120_pd", "num_actv_bc_tl",
    "num_actv_rev_tl", "num_bc_sats", "num_bc_tl", "num_il_tl", 
    "num_op_rev_tl", "num_rev_accts", "num_rev_tl_bal_gt_0", "num_sats", 
    "num_tl_120dpd_2m", "num_tl_30dpd", "num_tl_90g_dpd_24m", 
    "num_tl_op_past_12m", "pct_tl_nvr_dlq", "percent_bc_gt_75", 
    "pub_rec_bankruptcies", "tax_liens", "tot_hi_cred_lim", 
    "total_bal_ex_mort", "total_bc_limit", "total_il_high_credit_limit", 
    "hardship_flag", "debt_settlement_flag",
    "loan_status"
]

df = pd.read_csv(R'/Users/melissa/Downloads/Supervised_Machine_Learning/Resources /Generator /2019loans.csv', skiprows=1, header=None, names=columns, index_col=False)
df

df1 = df.drop("tot_coll_amt", axis=1)
x = pd.get_dummies(df1, dtype=float)

x
y = LabelEncoder().fit_transform(df['tot_coll_amt'])
y
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1)<jupyter_output><empty_output><jupyter_text>Predictions and Comparison Makes a prediction on which model will perform better on the unscaled data. Since we are dealing with a large dataset and contains categorical variables it is imoortant to take into account the models that can divide the data based on categorical data. With that, I think that random Forest will do better because it generalizes the data (random). Makes a prediction on which model will perform better on the scaled data.  The model that will preform better on the scaled data will bee the  Logistic regression because there is less noise variables as a result there could be a higher true and false positive rate. Makes a comparison between predicted behavior of the models on unscaled data and the actual results. indicate that training accuracy is higher than testing in both model and similar to my prediction it random forest can be a better model. Makes a comparison between predicted behavior of the models on scaled data and the actual results. the scaled data indicate that test accuracy is much higher than training in the linear regression this shows that radnom forest would be better model because the test score and training score are closer in number. I however assumed that linear model would be better.<jupyter_code># Train the Logistic Regression model on the unscaled data and print the model score
linear_df = LogisticRegression()
linear_df.fit(x_train, y_train)

training_score = linear_df.score(x_train, y_train)
testing_score = linear_df.score(x_test, y_test)

print(f"Training Score: {training_score}")
print(f"Testing Score: {testing_score}")
# Train a Random Forest Classifier model and print the model score
clf = RandomForestClassifier(max_depth=10, random_state=1, n_estimators=500).fit(x_train, y_train)
print(f'Training Score: {clf.score(x_train, y_train)}')
print(f'Testing Score: {clf.score(x_test, y_test)}')

# Scale the data
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1)
scaler = StandardScaler().fit(x_train)
x_train_scaled = scaler.transform(x_train)
x_test_scaled = scaler.transform(x_test)
linear_df.fit(x_train_scaled, y_train)
training_score = linear_df.score(x_train_scaled, y_train)
testing_score = linear_df.score(x_test_scaled, y_test)

print(f"Training Score: {training_score}")
print(f"Testing Score: {testing_score}")
clf = RandomForestClassifier(max_depth=10, random_state=1, n_estimators=500).fit(x_train_scaled, y_train)
print(f'Training Score: {clf.score(x_train_scaled, y_train)}')
print(f'Testing Score: {clf.score(x_test_scaled, y_test)}')<jupyter_output>Training Score: 0.8562671045429666
Testing Score: 0.8492610837438423
{'fraction_non_alphanumeric': 0.10420168067226891, 'fraction_numerical': 0.01953781512605042, 'mean_word_length': 6.716369529983792, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '304734', 'license': 'ADSL', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1704, 'n_words': 430, 'path': 'Credit Risk Evaluator.ipynb', 'repo_name': 'melcardenas28/Supervised_Machine_Learning', 'size': '4760'}