text_plain_output_1.png image_output_1.png
from imblearn.ensemble import BalancedRandomForestClassifier

from sklearn.metrics import f1_score, accuracy_score, roc_auc_score, plot_roc_curve, plot_confusion_matrix

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import seaborn as sns

data = pd.read_csv('/kaggle/input/loan-prediction-based-on-customer-behavior/Training Data.csv')

import matplotlib.pyplot as plt
total = list(data.Risk_Flag.value_counts())
Flag0 = total[0]
Flag1 = total[1]

import seaborn as sns
g=sns.catplot(x='STATE', data=data, height=12, aspect=1.5, kind='count', palette='deep')
g.set_xticklabels(rotation=60)

import seaborn as sns
import matplotlib.pyplot as plt
plt.xticks(rotation=60)

from imblearn.ensemble import BalancedRandomForestClassifier
from sklearn.metrics import f1_score, accuracy_score, roc_auc_score, plot_roc_curve, plot_confusion_matrix
brf = BalancedRandomForestClassifier().fit(X_train, y_train)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))
plt.title('asfafasf')
ax1.set_title('Confusion matrix (Balanced RF)')
ax2.set_title('ROC curve (Balanced RF)')
ax2.plot([0, 1], [0, 1], 'g--', alpha=0.25)
plot_confusion_matrix(brf, X_test, y_test, cmap=plt.cm.Blues, normalize='true', ax=ax1)
plot_roc_curve(brf, X_test, y_test, ax=ax2)
y_pred = brf.predict(X_test)
acc_brf = accuracy_score(y_test, y_pred)
f1_brf = f1_score(y_test, y_pred)
roc_brf = roc_auc_score(y_test, y_pred)
print('Roc_Auc score: %.3f' % roc_brf)