-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loan Prediction Using Cibil Score.r
59 lines (46 loc) · 1.7 KB
/
Loan Prediction Using Cibil Score.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
a <- read.csv("cibil.csv")
View(a)
summary(a)
linearMod <- lm(CreditScor ~ Income, data=a)
print(linearMod)
summary(linearMod)
scatter.smooth(x=a$Income, y=a$CreditScor, main="CreditScor ~ Income")
set.seed(100)
trainingRowIndex <- sample(1:nrow(a), 0.8*nrow(a))
trainingData <- a[trainingRowIndex, ]
testData <- a[-trainingRowIndex, ]
logitMod <- glm(Approved ~ Debt + Income, family="binomial", data = trainingData)
predictedY <- predict(logitMod, testData, type="response")
str(a)
glm(Approved ~ CreditScor, family="binomial", data = a)
a <- a[,-1]
for(i in 1:9) {
a[, i] <- as.numeric(as.character(a[, i]))
}
a$Approved <- ifelse(a$Approved == "+", 1, 0)
a$Approved <- factor(a$Approved, levels = c(0, 1))
table(a$Approved)
library(caret)
'%ni%' <- Negate('%in%') # define 'not in' func
options(scipen=999)
set.seed(100)
trainDataIndex <- createDataPartition(a$Approved, p=0.7, list = F) # 70% training data
trainData <- a[trainDataIndex, ]
testData <- a[-trainDataIndex, ]
table(trainData$Approved)
# Down Sample
set.seed(100)
down_train <- downSample(x = trainData[, colnames(trainData) %ni% "Approved"],
y = trainData$Approved)
table(down_train$Approved)
set.seed(100)
up_train <- upSample(x = trainData[, colnames(trainData) %ni% "Approved"],
y = trainData$Approved)
table(up_train$Approved)
logitmod <- glm(Class ~ Employed + CreditScor + Income, family = "binomial", data=down_train)
summary(logitmod)
pred <- predict(logitmod, newdata = testData, type = "response")
y_pred_num <- ifelse(pred > 0.5, 1, 0)
y_pred <- factor(y_pred_num, levels=c(0, 1))
y_act <- testData$Approved
mean(y_pred == y_act)