<jupyter_start><jupyter_text>Train the model without re-sampling (5 - classes)<jupyter_code># Train the model

rfc = RandomForestClassifier(n_estimators = 100, n_jobs = -1).fit(X_train, y_train)
rfc_pred = rfc.predict(X_test)
# Performance results

print("Accuracy: \t", accuracy_score(y_test, rfc_pred))
print("F1 Score: \t", f1_score(y_test, rfc_pred, average = 'macro'))
print("Precision:\t", precision_score(y_test, rfc_pred, average = 'macro'))
print("Recall:   \t", recall_score(y_test, rfc_pred, average = 'macro'))
# Plot normalized confusion matrix

import matplotlib.pyplot as plt

classes = ["1", "2", "3", "4", "5"]
title = "Random Forest Without Re-sample 5-class"
disp = plot_confusion_matrix(rfc, X_test, y_test, display_labels = classes, cmap = "copper", normalize = "true")
disp.ax_.set_title(title)
plt.show()<jupyter_output><empty_output><jupyter_text>Train the model without re-sampling (3 - classes)<jupyter_code># Train the model

rfc = RandomForestClassifier(n_estimators = 100, n_jobs = -1).fit(X_train, y_train_3_class)
rfc_pred = rfc.predict(X_test)
# Performance results

print("Accuracy: \t", accuracy_score(y_test_3_class, rfc_pred))
print("F1 Score: \t", f1_score(y_test_3_class, rfc_pred, average = 'macro'))
print("Precision:\t", precision_score(y_test_3_class, rfc_pred, average = 'macro'))
print("Recall:   \t", recall_score(y_test_3_class, rfc_pred, average = 'macro'))
# Plot normalized confusion matrix

import matplotlib.pyplot as plt

classes = ["Low", "Medium", "High"]
title = "Random Forest Without Re-sample 3-class"
disp = plot_confusion_matrix(rfc, X_test, y_test_3_class, display_labels = classes, cmap = "copper", normalize = "true")
disp.ax_.set_title(title)
plt.show()<jupyter_output><empty_output><jupyter_text>Train the model with re-sampling (5 - Classes)<jupyter_code># Re-sample the training set

sm = SMOTEENN(random_state = 27, n_jobs = -1)
X_train_sampled_5_class, y_train_sampled_5_class = sm.fit_sample(X_train, y_train)
print(X_train_sampled_5_class.shape)
# Train the model

rfc_sampled = RandomForestClassifier(n_estimators = 100, n_jobs = -1).fit(X_train_sampled_5_class, y_train_sampled_5_class)
rfc_sampled_pred = rfc_sampled.predict(X_test)
# Performance results

print("Accuracy: \t", accuracy_score(y_test, rfc_sampled_pred))
print("F1 Score: \t", f1_score(y_test, rfc_sampled_pred, average = 'macro'))
print("Precision:\t", precision_score(y_test, rfc_sampled_pred, average = 'macro'))
print("Recall:   \t", recall_score(y_test, rfc_sampled_pred, average = 'macro'))
# Plot normalized confusion matrix

classes = ["1", "2", "3", "4", "5"]
title = "Random Forest With Re-sample"
disp = plot_confusion_matrix(rfc_sampled, X_test, y_test, display_labels = classes, cmap = "copper", normalize = "true")
disp.ax_.set_title(title)
plt.show()<jupyter_output><empty_output><jupyter_text>Train the model with re-sampling (3 - Classes)<jupyter_code># Re-sample the training set

sm = SMOTEENN(random_state = 27, n_jobs = -1)
X_train_sampled_3_class, y_train_sampled_3_class = sm.fit_sample(X_train, y_train_3_class)
print(X_train_sampled_3_class.shape)
# Train the model

rfc_sampled = RandomForestClassifier(n_estimators = 100, n_jobs = -1).fit(X_train_sampled_3_class, y_train_sampled_3_class)
rfc_sampled_pred = rfc_sampled.predict(X_test)
# Performance results

print("Accuracy: \t", accuracy_score(y_test_3_class, rfc_sampled_pred))
print("F1 Score: \t", f1_score(y_test_3_class, rfc_sampled_pred, average = 'macro'))
print("Precision:\t", precision_score(y_test_3_class, rfc_sampled_pred, average = 'macro'))
print("Recall:   \t", recall_score(y_test_3_class, rfc_sampled_pred, average = 'macro'))
# Plot normalized confusion matrix

classes = ["Low", "Medium", "High"]
title = "Random Forest With Re-sample 3-class"
disp = plot_confusion_matrix(rfc_sampled, X_test, y_test_3_class, display_labels = classes, cmap = "copper", normalize = "true")
disp.ax_.set_title(title)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13351772692984662, 'fraction_numerical': 0.017349761126477244, 'mean_word_length': 7.445859872611465, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '130595', 'license': 'MIT', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1489, 'n_words': 308, 'path': 'Random_Forest.ipynb', 'repo_name': 'OnerInce/ml-earthquake', 'size': '3977'}