<jupyter_start><jupyter_text>Load Dependencies<jupyter_code>import numpy as np
import pandas as pd
from pathlib import Path
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler, LabelEncoder
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_blobs
from sklearn.ensemble import RandomForestClassifier<jupyter_output><empty_output><jupyter_text>Predictions:  Which model will do I think will preform better?Probably the Logistic Regression model as it is not as randomized and the Random Forest Classifier  Which model will do I think will preform better after scaling the data?Maybe after the data is scaled the Logistic Regression model will become more accurate and preform better than before and still better than the Random Forest Classifier   Step 1: Load the Datasets<jupyter_code>train_df = pd.read_csv(Path('Resources/2019loans.csv'))
test_df = pd.read_csv(Path('Resources/2020Q1loans.csv'))<jupyter_output><empty_output><jupyter_text>Step 2: Preprocessing Data For each set of data convert categorical data to numeric and separate target feature for training dataTHEN convert categorical data to numeric and separate target feature for testing data  Training Data<jupyter_code>X_dummiestrain = pd.get_dummies(train_df)
print(X_dummiestrain.columns)
X_dummiestrain


X_dummiestrain.drop('Unnamed: 0', axis=1, inplace=True)
X_dummiestrain<jupyter_output><empty_output><jupyter_text>Testing Data<jupyter_code>X_dummiestest = pd.get_dummies(test_df)
print(X_dummiestest.columns)

X_dummiestest

X_dummiestest.drop('Unnamed: 0', axis=1, inplace=True)<jupyter_output><empty_output><jupyter_text>add missing dummy variables to testing set to make even amount of columns<jupyter_code>X_dummiestest['debt_settlement_flag_Y'] = 0
X_dummiestest<jupyter_output><empty_output><jupyter_text>Step 3: separate target feature for testing data and create  X_train, X_test, y_train, y_test<jupyter_code>X_train = X_dummiestrain.drop('loan_status_low_risk', axis=1)
X_train
y_train = LabelEncoder().fit_transform(X_dummiestrain['loan_status_low_risk'])
y_train
X_test = X_dummiestest.drop('loan_status_low_risk', axis=1)
X_test
y_test = LabelEncoder().fit_transform(X_dummiestest['loan_status_low_risk'])
y_test<jupyter_output><empty_output><jupyter_text>Step 4: Train the Logistic Regression model on the unscaled data and print the model score<jupyter_code>classifier = LogisticRegression()
classifier
 classifier.fit(X_train, y_train)
 print(f"Training Data Score: {classifier.score(X_train, y_train)}")
print(f"Testing Data Score: {classifier.score(X_test, y_test)}")<jupyter_output>Training Data Score: 0.6573891625615763
Testing Data Score: 0.5216928966397277<jupyter_text>Step 5: Train a Random Forest Classifier model and print the model score<jupyter_code>clf = RandomForestClassifier(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)}')<jupyter_output>Training Score: 1.0
Testing Score: 1.0<jupyter_text>Step 6: Scale the data<jupyter_code>scaler = StandardScaler().fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)<jupyter_output><empty_output><jupyter_text>Step 7: Train the Logistic Regression model on the scaled data and print the model score<jupyter_code>classifier.fit(X_train_scaled, y_train)
 print(f"Training Data Score: {classifier.score(X_train_scaled, y_train)}")
print(f"Testing Data Score: {classifier.score(X_test_scaled, y_test)}")<jupyter_output>Training Data Score: 1.0
Testing Data Score: 0.9997873245427478<jupyter_text>Step 8: Train a Random Forest Classifier model on the scaled data and print the model score<jupyter_code>clf = RandomForestClassifier(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: 1.0
Testing Score: 1.0
{'fraction_non_alphanumeric': 0.08485735186539868, 'fraction_numerical': 0.02267739575713241, 'mean_word_length': 8.980535279805352, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '94646', 'license': 'ADSL', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1409, 'n_words': 338, 'path': 'Credit Risk Evaluator RT.ipynb', 'repo_name': 'racheltsitomeneas/Supervised-Machine-Learning-Homework', 'size': '4101'}