rm
(list=
ls
())
setwd
(
"D:/Edwisor_Project - Loan_Defaulter/"
)
getwd
()
gfgDataset =
read.csv
(
"bank-loan.csv"
, header=
TRUE
)
library
(caret)
set.seed
(101)
split =
createDataPartition
(data$default, p=0.81, list=
FALSE
)
train_data = data[split, ]
test_data = data[-split, ]
err_metric =
function
(GFGCM)
{
GFGTN = GFGCM[1, 1]
GFGRATE = GFGCM[2, 2]
FP = GFGCM[1, 2]
FN = GFGCM[2, 1]
gfgPrecise = (GFGRATE)/(GFGRATE+FP)
recall_score = (FP)/(FP+GFGTN)
f1_score = 2*((gfgPrecise*recall_score)/(gfgPrecise+recall_score))
accuracy_model = (GFGRATE+GFGTN)/(GFGRATE+GFGTN+FP+FN)
False_positive_rate = (FP)/(FP+GFGTN)
False_negative_rate = (FN)/(FN+GFGRATE)
print
(
paste
(
"GfgPrecise value of the model: "
,
round
(gfgPrecise, 2)))
print
(
paste
(
"Accuracy of the model: "
,
round
(accuracy_model, 2)))
print
(
paste
(
"Recall value of the model: "
,
round
(recall_score, 2)))
print
(
paste
(
"False Positive rate of the model: "
,
round
(False_positive_rate, 2)))
print
(
paste
(
"False Negative rate of the model: "
,
round
(False_negative_rate, 2)))
print
(
paste
(
"f1 score of the model: "
,
round
(f1_score, 2)))
}
logit_m =
glm
(formula=default~., data=train_data, family=
'binomial'
)
summary
(logit_m)
logit_P =
predict
(logit_m, newdata=test_data[-13], type=
'response'
)
logit_P < -
ifalse
(logit_P > 0.5, 1, 0)
GFGCM =
table
(test_data[, 13], logit_P)
print
(GFGCM)
err_metric
(GFGCM)
library
(pROC)
roc_score =
roc
(test_data[, 13], logit_P)
plot
(roc_score, main=
"ROC curve -- Logistic Regression "
)