-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCredit_Default_Model.Rmd
More file actions
4780 lines (2134 loc) · 97.9 KB
/
Credit_Default_Model.Rmd
File metadata and controls
4780 lines (2134 loc) · 97.9 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Taiwan Customer Defaults"
author: "Abhay Kulkarni"
date: "12/02/2019"
output:
pdf_document:
fig_caption: yes
number_sections: yes
toc: yes
toc_depth: 3
word_document:
toc: yes
toc_depth: '3'
html_document:
df_print: paged
toc: yes
toc_depth: '3'
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\LARGE\includegraphics[height=20cm]{FINAL SUBMISSION.jpg}\\[\bigskipamount]}
- \posttitle{\end{center}}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newpage
# Libraries
```{r message=FALSE, warning=FALSE}
library(knitr)
library(readxl)
library(DataExplorer)
library(memisc)
library(funModeling)
library(cowplot)
library(MASS)
library(DMwR)
library(caTools)
library(DataExplorer)
library(ggplot2)
library(caTools)
library(skimr)
library(caret)
library(cowplot)
library(caTools)
library(ROSE)
library(ROCR)
library(MLmetrics)
library(MASS)
library(class)
library(e1071)
library(car)
library(ROSE)
library(MASS)
library(pROC)
library(e1071)
library(class)
library(lattice)
library(klaR)
library(ipred)
library(rpart)
library(xgboost)
library(adabag)
library(pROC)
library(rattle)
```
\newpage
# Introduction
## Problem Statement
Beginning in 1990, the Taiwanese government allowed the formation of new banks. These new banks lent large sums of money to real estate companies with the goal of expanding their businesses and increasing profits. The new banks turned to other new business – credit cards and cash cards. In expanding this area of business, banks lavished money on commercials encouraging people to apply for credit cards to consume, apparently without consequences. These banks lowered the requirements for credit card approvals to get more customers.
In Taiwan, in February 2006, debt from credit cards and cash cards reached $268 billion USD. More than half a million people were not able to repay their loans. They became “credit card slaves”, a term coined in Taiwan to refer to people who could only pay the minimum balance on their credit card debt every month (“News & Important policy”). This issue resulted in significant societal problems.
## Need of the study
In 2005, to prevent more and more new credit card slaves from appearing, the Taiwanese Finance Supervisory Commission issued some orders to require banks to modify their requirements of credit card applications. Some of the changes included raising the income and job requirements, prohibiting improper credit card commercials, prohibiting inappropriate collection behaviors and prohibiting compound interest.
## Business/Social Opportunity
A Taiwan-based bank wants to improve their prediction of defaults of their customers, as well as identify the patterns that determine this likelihood. This would help the bank decide whether to issue the credit card or not. Also, fix credit limt and risk type to the customer and avoid future defaults.
We would be analyzing the dataset and build a predictive model to identify and predict default payments.
\newpage
# Acknowledgement

# Speeding Processor Cores
```{r}
library(parallel)
library(doParallel)
clusterforspeed <- makeCluster(detectCores() - 1) ## convention to leave 1 core for OS
registerDoParallel(clusterforspeed)
```
# Understanding the dataset and Data Cleaning
## Set Working Directory
```{r}
setwd("Z:\\Projects\\Capstone")
getwd()
```
## Import dataset
```{r}
myrawdata <- read_excel("Taiwan-Customer defaults.xls", skip = 1)
```
## Data Dictionary/ Description
|| Name | Description |
|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ID | ID of each client |
| LIMIT\_BAL | Amount of given credit in NT dollars \(includes individual and family/supplementary credit\) |
| SEX | Gender \(1=male, 2=female\) |
| EDUCATION | \(1=graduate school, 2=university, 3=high school, 4=others, 5=unknown, 6=unknown\) |
| MARRIAGE | Marital status \(1=married, 2=single, 3=others\) |
| AGE | Age in years |
| PAY\_0 | Repayment status in September, 2005 \(\-2=no consumption, \-1=pay duly, 0=the use of revolving credit, 1=payment delay for one month, 2=payment delay for two months, … 8=payment delay for eight months, 9=payment delay for nine months and above\) |
| PAY\_2 | Repayment status in August, 2005 \(scale same as above\) |
| PAY\_3 | Repayment status in July, 2005 \(scale same as above\) |
| PAY\_4 | Repayment status in June, 2005 \(scale same as above\) |
| PAY\_5 | Repayment status in May, 2005 \(scale same as above\) |
| PAY\_6 | Repayment status in April, 2005 \(scale same as above\) |
| BILL\_AMT1 | Amount of bill statement in September, 2005 \(NT dollar\) |
| BILL\_AMT2 | Amount of bill statement in August, 2005 \(NT dollar\) |
| BILL\_AMT3 | Amount of bill statement in July, 2005 \(NT dollar\) |
| BILL\_AMT4 | Amount of bill statement in June, 2005 \(NT dollar\) |
| BILL\_AMT5 | Amount of bill statement in May, 2005 \(NT dollar\) |
| BILL\_AMT6 | Amount of bill statement in April, 2005 \(NT dollar\) |
| PAY\_AMT1 | Amount of previous payment in September, 2005 \(NT dollar\) |
| PAY\_AMT2 | Amount of previous payment in August, 2005 \(NT dollar\) |
| PAY\_AMT3 | Amount of previous payment in July, 2005 \(NT dollar\) |
| PAY\_AMT4 | Amount of previous payment in June, 2005 \(NT dollar\) |
| PAY\_AMT5 | Amount of previous payment in May, 2005 \(NT dollar\) |
| PAY\_AMT6 | Amount of previous payment in April, 2005 \(NT dollar\) |
| default\.payment\.next\.month | Default payment \(1=yes, 0=no\) |
## Convert to Data Frame
```{r}
myrawdata<- as.data.frame(myrawdata)
```
## Understanding how data was collected in terms of time and frequency
```{r echo=FALSE, warning=FALSE}
head(myrawdata)
```
**Findings **
* The dataset contains information on default payments, demographic factors, credit data, history of payment, and bill statements of credit card clients in Taiwan from April 2005 to September 2005.
## Dimension (Rows and Column in the dataset)
```{r echo=FALSE}
dim(myrawdata)
```
**Findings **
* There are 30000 observations and 25 Features
## Number of Discreate and Continous Variables
```{r echo=FALSE, warning=FALSE}
introduce(myrawdata)
```
**Findings **
* The above table incorrectly reads dataset as 25 Continuos and 0 Discreate
* Have to convert 'Sex', 'Education', 'Marriage' and 'Default Payment'as factors.
## Converting incorrectly read data types to factors
```{r echo=FALSE}
a <- c(3,4,5,25)
converteddata <- myrawdata
```
```{r echo=FALSE}
for (i in a) {
converteddata[,i] <- as.factor(converteddata[,i])
}
```
```{r echo=FALSE}
introduce(converteddata)
```
**Findings **
* Have converted 'Sex', 'Education', 'Marriage' and 'Default Payment'as factors.
## Will look into pay_1,2,3,4,5,6 later
* For fields pay1 to pay6 , roughly 50% of them have 0s and there are many -2s as well.
* Cannot conclude anything about the data right now.
* PAY_* is an ordinal variable where the levels are ordered and have some meaning
**Only exploring the data further can reveal some insights**
**Retaining it as numeric for the moment**
## Check for data summary/ data details
```{r echo=FALSE}
datadetails <-df_status(converteddata)
```
## Change names of few columns
**Findings **
* To have similar column names, changing "PAY_0" to "PAY_1"
* Column default.payment.next.month rename to DEFAULT
```{r echo=FALSE}
names(converteddata)[names(converteddata) == "PAY_0"] <- "PAY_1"
names(converteddata)[names(converteddata) == "default payment next month"] <- "DEFAULT "
```
## Converting data levels of category
**Findings **
* Converting Default factor from "0" and "1" to "No" and "Yes"
* Converting Marriage "1", "2" and "3" to "Married", "Single" and "Other"
* As there is no description for "5" and "6". Converting Education to "Graduate.School", "University", ""High.School" and "Unknown".
```{r echo=FALSE}
converteddata$DEFAULT <- as.factor(ifelse(converteddata$DEFAULT == 1, "Yes", "No"))
converteddata$SEX <- as.factor(ifelse(converteddata$SEX == 1, "Male", "Female"))
converteddata$MARRIAGE <- as.factor(ifelse(converteddata$MARRIAGE == 1, "Married",
ifelse(converteddata$MARRIAGE == 2, "Single", "Other")))
converteddata$EDUCATION <- as.factor(ifelse(converteddata$EDUCATION == 1, "Graduate.School",
ifelse(converteddata$EDUCATION == 2, "University",
ifelse(converteddata$EDUCATION == 3, "High.School",
ifelse(converteddata$EDUCATION == 4, "Other", "Unkown")))))
```
## Let's check the above conversion
```{r echo=FALSE}
table(converteddata$MARRIAGE)
table(converteddata$SEX)
table(converteddata$EDUCATION)
```
## Before we begin EDA. Let's get rid off ID column
```{r echo=FALSE}
converteddata<- converteddata[,c(-25,-1)]
```
## Create backup and proceed with EDA
```{r echo=FALSE}
backupdata <- converteddata
```
\newpage
## Check for Missing Values
```{r echo=FALSE, fig.height=7}
plot_missing(converteddata)
```
**Findings **
* There are no missing values
# EDA
## Before Univariate Analysis. A quick check with corr plot and understand pattern
```{r echo=FALSE, fig.height=9, fig.width=11, warning=TRUE}
plot_correlation(converteddata)
```
**Findings **
* Look at DEFAULT correlation with other variables.
* Lowest is with LIMIT_BAL.LIMIT_BAL and DEFAULT are Negatively Correlated. Negative correlation indicates higher Credit Limit, lower Default.
* Highest is correlation with PAY_1. PAY_1 and DEFAULT are positively correlated. Positive correlation indicates longer period of Delay Payment, higher Default.
* In general PAY_1 ~ PAY_6 have higher correlation to DEFAULT compare to other variables.
* Clients payment behaviour give strong indication on Default.
## UNIVARIATE ANALYSIS. Let's start with Categorical Variable
## Check for dependent(DEFAULT) column split
```{r echo=FALSE}
a <- ggplot(converteddata) +
aes(x = DEFAULT, y = prop.table(stat(count)),fill = DEFAULT,label = scales::percent(prop.table(stat(count)))) +
geom_bar() +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Default Split Percentage") +
theme(plot.title = element_text(hjust = 0.5))+
geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
a
```
**Findings **
* The dependent data is not evenly distributed. We have more of "NO 78% and 22% "YES"
* Dataset of Bank Credit Defaults are good examples of imbalanced data. We'll check if the data needs to be balanced during Model Building.
## Let's check percentage of customer based on SEX
```{r echo=FALSE}
b <- ggplot(converteddata) +
aes(x = SEX, y = prop.table(stat(count)),fill = SEX,label = scales::percent(prop.table(stat(count)))) +
geom_bar() +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "SEX Split Percentage") +
theme(plot.title = element_text(hjust = 0.5))+
geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
b
```
**Findings **
* There are more Female credit card holers than male.
* There are 20% more female customer than male. This could be an important feature to build deault prediction model. We'll investigate further during bivariate analysis(gender vs default)
## Let's check percentage of customer based on EDUCATION
```{r echo=FALSE}
c <- ggplot(converteddata) +
aes(x = EDUCATION, y = prop.table(stat(count)),fill = EDUCATION,label = scales::percent(prop.table(stat(count)))) +
geom_bar() +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "EDUCATION Split Percentage") +
theme(plot.title = element_text(hjust = 0.5))+
geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
c
```
**Findings **
* We can immediately see that "Other" and "Unknown" are negligible. However, there are more credit card holders who have "University" level education, followed by "Graduate School" and "High School"
* We'' investigate this further during Bivariate Analysis and check if this is an important feature to preidct default.
## Let's check percentage of customer based on MARRIAGE
```{r echo=FALSE}
d <- ggplot(converteddata) +
aes(x = MARRIAGE, y = prop.table(stat(count)),fill = MARRIAGE,label = scales::percent(prop.table(stat(count)))) +
geom_bar() +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "MARRIAGE Split Percentage") +
theme(plot.title = element_text(hjust = 0.5))+
geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
d
```
**Findings **
* We can immediately see that "Other" has negligible data. However, there is difference of 7.7% between "Married" and "Single" customers.
## Let's investigate Continous features
## Let's check the distribution and outliers(if any) of Limit Balance
```{r echo=FALSE}
e <- ggplot(converteddata) +
aes(x = LIMIT_BAL) +
geom_histogram(bins = 20L, fill = "#a6cee3") +
labs(title = "Histogram of Limit Balance") +
theme(plot.title = element_text(hjust = 0.5))
f <- ggplot(converteddata) +
aes(x = "", y = LIMIT_BAL) +
geom_boxplot(fill = "#a6cee3") +
labs(title = "Box Plot of Limit Balance") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(e,f)
summary(converteddata$LIMIT_BAL)
sd(converteddata$LIMIT_BAL)
```
**Findings **
* Histogram : By looking at histogram we can see that it is a bit right skewed. The **Mean** of distribution is **167484** and **Standard Deviation** of **129747.7**
* Box Plot : We can see that there are outliers present per the BOX PLOT. We'll treat it later (Notes2 Submission). Would treat outliers using Winsorizing transformation.
* Min Value is 10000, Q1 is 50000, Median is 140000, Mean is 167484, Q3 is 240000 and Max is 1000000.
## AGE
```{r echo=FALSE}
g <- ggplot(converteddata) +
aes(x = AGE) +
geom_histogram(bins = 20L, fill = "#a6cee3") +
labs(title = "Histogram of AGE") +
theme(plot.title = element_text(hjust = 0.5))
h <- ggplot(converteddata) +
aes(x = "", y = AGE) +
geom_boxplot(fill = "#a6cee3") +
labs(title = "Box Plot of AGE") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(g,h)
summary(converteddata$AGE)
sd(converteddata$AGE)
```
# Bivariate Analysis
## Let's see how each feature reacts with dependent feature, DEAFULT. Let's start Bivariate Analysis with Categorical Features.
## Let's check if there is significant difference between "Male" and "Female" with respect to Default
```{r echo=FALSE}
k <- ggplot(converteddata) +
aes(x = SEX, y = prop.table(stat(count)),fill = DEFAULT,label = scales::percent(prop.table(stat(count)))) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "SEX VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))+geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
k
```
**Findings **
* From the above figure. We can see that the Default of Female is 12.5% and Male is 9.6%.
* Let's check Chi-Square test of Independence
Test the hypothesis whether the Default is independent of the SEX level at .05 significance level.
**Null Hypothesis(HO)** : Default is Independent of SEX
**Alternative Hypothesis(H1)** : Default is dependent on SEX
```{r echo=FALSE}
SEXtable <- table(converteddata$SEX,converteddata$DEFAULT)
SEXtable
```
**Let's run Chi-Square test**
```{r echo=FALSE}
SEXchi<- chisq.test(SEXtable)
SEXchi
```
**Findings **
* p- value is way lesser than 0.05. We reject Null Hypothesis and go with Alternative hypothesis that Default" depends on "SEX".
* SEX is an important feature to distinguish between Default vs No Default.
## Let's check EDUCATION VS DEFAULT
```{r echo=FALSE}
l<- ggplot(converteddata) +
aes(x = EDUCATION, y = prop.table(stat(count)),fill = DEFAULT,label = scales::percent(prop.table(stat(count)))) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "EDUCATION VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))+geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
l
```
```{r echo=FALSE}
EducationTable <- table(converteddata$EDUCATION,converteddata$DEFAULT)
EducationTable
```
**Let's run Chi-Square test**
```{r echo=FALSE}
Educhisq<- chisq.test(EducationTable)
Educhisq
```
**Findings **
* From the above figure. We can see that the difference Default percentage of University is the most at 24.56% followed by Graduate School at 21.71%
* Let's check Chi-Square test of Independence
Test the hypothesis whether the Default is independent of the EDUCATION level at .05 significance level.
**Null Hypothesis(HO)** : Default is Independent of EDUCATION
**Alternative Hypothesis(H1)** : Default is dependent on EDUCATION
**Findings **
* p- value is way lesser than 0.05. We reject Null Hypothesis and go with Alternative hypothesis that Default" depends on "EDUCATION".
* EDUCATION is an important feature to distinguish between Default vs No Default.
## MARRIAGE VS DEFAULT
```{r echo=FALSE}
m<- ggplot(converteddata) +
aes(x = MARRIAGE, y = prop.table(stat(count)),fill = DEFAULT,label = scales::percent(prop.table(stat(count)))) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "MARRIAGE VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))+geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3)
m
```
**Findings **
* From the above figure. It looks like "Married" and "Single" default percentage is very close.
* Lets run Chi Square test of independence
```{r echo=FALSE}
MarriageTable <- table(converteddata$DEFAULT,converteddata$MARRIAGE)
MarriageTable
```
**Let's run Chi-Square test**
```{r echo=FALSE}
MarriageChi<- chisq.test(MarriageTable)
MarriageChi
```
**Findings **
* p- value is way lesser than 0.05. We reject Null Hypothesis and go with Alternative hypothesis that Default" depends on "MARRIAGE".
* MARRIAGE is an important feature to distinguish between Default vs No Default.
## Let's start BiVariate Analysis with Numerical feature VS Dependent Feature(DEFAULT). Let's dig in with the information received from Correlation Plot
```{r echo=FALSE, fig.width=9}
LD <- ggplot(converteddata) +
aes(x = LIMIT_BAL, fill = DEFAULT) +
geom_density(adjust = 1L) +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Density Plot LIMIT BAL VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
dodge <- position_dodge(width = 0.9)
Boxld <- ggplot(converteddata) +
aes(x = "", y = LIMIT_BAL, fill = DEFAULT) +
geom_violin(adjust = 1L, scale = "area") +geom_boxplot(width=0.1,position = dodge)+
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Violin Plot LIMIT BAL VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(LD,Boxld)
```
**Findings **
* We can see the inverse relationship between LIMIT BAL and DEFAULT. Lesser the BALANCE More the DEFAULT
## AGE VS DEFAULT
```{r echo=FALSE, fig.width=9}
AGEDen <- ggplot(converteddata) +
aes(x = AGE, fill = DEFAULT) +
geom_density(adjust = 1L) +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Density Plot AGE VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
dodge <- position_dodge(width = 0.9)
BOXAGE<- ggplot(converteddata) +
aes(x = "", y = AGE, fill = DEFAULT) +
geom_violin(adjust = 1L, scale = "area") +geom_boxplot(width=0.1,position = dodge)+
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Violin Plot AGE VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(AGEDen ,BOXAGE)
```
**Findings **
* There are more defaulters between Age 20 and Age 25
## BILL_AMT1 VS DEFAULT
```{r echo=FALSE, fig.width=9}
BILL_AMT1Den <- ggplot(converteddata) +
aes(x = BILL_AMT1, fill = DEFAULT) +
geom_density(adjust = 1L) +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Density Plot BILL_AMT1 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
dodge <- position_dodge(width = 0.9)
BOXBILL_AMT1<- ggplot(converteddata) +
aes(x = "", y = BILL_AMT1, fill = DEFAULT) +
geom_violin(adjust = 1L, scale = "area") +geom_boxplot(width=0.1,position = dodge)+
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Violin Plot BILL_AMT1 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(BILL_AMT1Den ,BOXBILL_AMT1)
```
**Findings **
* It appears that there is more defaults between **BILL AMT 0 and 250000**
## BILL_AMT6 VS DEFAULT
```{r echo=FALSE, fig.width=9}
BILL_AMT6Den <- ggplot(converteddata) +
aes(x = BILL_AMT6, fill = DEFAULT) +
geom_density(adjust = 1L) +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Density Plot BILL_AMT6 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
dodge <- position_dodge(width = 0.9)
BOXBILL_AMT6<- ggplot(converteddata) +
aes(x = "", y = BILL_AMT6, fill = DEFAULT) +
geom_violin(adjust = 1L, scale = "area") +geom_boxplot(width=0.1,position = dodge)+
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Violin Plot BILL_AMT6 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(BILL_AMT6Den ,BOXBILL_AMT6)
```
**Findings **
* It appears that there is more defaults towards initial Billing AMT 6 and DEFAULTS gradually reduces as Billing Increases.
## PAY_AMT1 VS DEFAULT
```{r echo=FALSE, fig.width=9}
PAY_AMT1Den <- ggplot(converteddata) +
aes(x = PAY_AMT1, fill = DEFAULT) +
geom_density(adjust = 1L) +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Density Plot PAY_AMT1 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
dodge <- position_dodge(width = 0.9)
BOXPAY_AMT1<- ggplot(converteddata) +
aes(x = "", y = PAY_AMT1, fill = DEFAULT) +
geom_violin(adjust = 1L, scale = "area") +geom_boxplot(width=0.1,position = dodge)+
scale_fill_brewer(palette = "Pastel2") +
labs(title = "Violin Plot PAY_AMT1 VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))
plot_grid(PAY_AMT1Den ,BOXPAY_AMT1)
```
**Findings **
* We can immediately see that there are more 0 values in the PAY_AMT1 column. Also, it is directly related to defaults. Amount due and unpaid will result in defaults.
## Finally let's plot correlation plot between only numberical variables
```{r echo=FALSE, fig.height=11, fig.width=9}
plot_correlation((converteddata), type = "c")
```
**Findings **
* Billing AMT 1 to Billing AMT6 are highly correlated. These highly correlated features can undergo dimension reduction using PCA.
* PAY AMT1 to PAY AMT6 are highly correlated. These highly correlated features can undergo dimension reduction using PCA.
* PAY1 to PAY 6 needs further investigation. These features will be handeled in future.
# Summarise by asking some questions
## Defaulters are more in which Age bracket?
* There are more defaulters between Age 20 and Age 25
## Any effect of Education (level) on Default?
* High School and Graduate school education holders are likely to Default more.
## Did you find any any gender bias in extending credits?
* There are more FEMALE credit card holders. 20% more to be precise.
## More Defaulters belong to which Gender?
* There are more FEMALE defaulters compared to MEN. FEMALE defaulters are 12.5% VS 9.6% MEN
## Married people taking more credits than single?
* No, it’s the other way around. Single Customers are taking more loans than Married customers. MARRIED customers are 45.5% VS 53.2% SINGLE customers.
## Who are more defaulters – Single or Married?
* Single Customers are more defaulters compared to Married Customers. MARRIED 10.69% VS SINGLE 11.14%
## Does Gender and Marital Status has any role on Defaults?
```{r echo=FALSE, fig.width=11}
ggplot(converteddata) +
aes(x = SEX, y = prop.table(stat(count)),fill = DEFAULT,label =scales::percent(prop.table(stat(count)))) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "Pastel2") +
labs(title = "GENDER & MARITAL STATUS VS DEFAULT") +
theme(plot.title = element_text(hjust = 0.5))+geom_text(stat = 'count',
position = position_dodge(.9),
vjust = -0.5,
size = 3) +
facet_wrap(vars(MARRIAGE))
```
* FEMALE customers are more likely to default regardless of marital status.
# NEXT STEPS ( Notes 2)
## Outlier Treatent using winsorizing method.
## Feature creation
## Numerical variables AGE and Other variables are on differnt scales.Normalization or Standardization of data will be done.
## Build classification model based on variable importance.
\newpage

\newpage
# Notes 2 Roadmap.
## Detailed EDA would include several aspects some of those are mentioned below:
1. Renaming of variables
2. Remove the variables that are not required