text_html_output_1.png
from imblearn.over_sampling import SMOTE

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

from sklearn.preprocessing import LabelEncoder

import matplotlib.pyplot as plt

import pandas as pd

df_train = pd.read_csv('/kaggle/input/loan-data-set/loan_train.csv')
df_test = pd.read_csv('/kaggle/input/loan-data-set/loan_test.csv')

df_train.isna().sum()

df_train.isna().sum()

columns_list = list(df_train.columns)
for i in range(len(columns_list)):
    plt.xticks(rotation=45)
plt.tight_layout()

le = LabelEncoder()
str_col = df_train.select_dtypes(include='object').columns
for c in str_col:
    df_train[c] = le.fit_transform(df_train[c])

smt = SMOTE(random_state=0)
xtrain_res, ytrain_res = smt.fit_resample(xtrain, ytrain)

rf = RandomForestClassifier(max_depth=3, random_state=0)
rf.fit(xtrain_res, ytrain_res)

ypred = rf.predict(xtest)

le = LabelEncoder()
str_col = df_test.select_dtypes(include='object').columns
for c in str_col:
    df_test[c] = le.fit_transform(df_test[c])

test_predict = rf.predict(df_test)
test_result = pd.DataFrame(df_test)
test_result['predicted_status'] = test_predict

test_result.head()