text_plain_output_1.png image_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay, classification_report

from sklearn.neighbors import KNeighborsClassifier

from sklearn.svm import LinearSVC

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

data = pd.read_csv('/kaggle/input/loan-data-set/loan_data_set.csv')

data = data.dropna()

data_encoded = pd.get_dummies(data, columns=['Property_Area'])

model_knn = KNeighborsClassifier()
model_knn.fit(X_train, y_train)

model_svm = LinearSVC()
model_svm.fit(X_train, y_train)

model_tree = DecisionTreeClassifier()
model_tree.fit(X_train, y_train)

model_logistic = LogisticRegression()
model_logistic.fit(X_train, y_train)

from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay, classification_report
cm_knn = confusion_matrix(y_test, model_knn.predict(X_test))

cm_tree = confusion_matrix(y_test, model_tree.predict(X_test))

cm_svm = confusion_matrix(y_test, model_svm.predict(X_test))

cm_logistic = confusion_matrix(y_test, model_logistic.predict(X_test))

y_pred = model_logistic.predict(X_test)
arr = np.array(y_pred)
compare_pre_act = pd.DataFrame(arr, columns=['Prediction'])
y_true = y_test.values
flatten_y_true = y_true.flatten()
df_pred = pd.DataFrame({'y_true': flatten_y_true, 'y_pred': y_pred})
df_pred

model_knn = KNeighborsClassifier()
model_knn.fit(X_train, y_train)

model_tree = DecisionTreeClassifier()
model_tree.fit(X_train, y_train)

cm_knn = confusion_matrix(y_test, model_knn.predict(X_test))

print(classification_report(y_test, model_tree.predict(X_test)))
cm_tree = confusion_matrix(y_test, model_tree.predict(X_test))
ConfusionMatrixDisplay(cm_tree).plot()
plt.show()