forked from reonho/Default-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ipynb
5358 lines (5358 loc) · 409 KB
/
.ipynb
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
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "-4Rm0wjQMUHi"
},
"source": [
"# BUILDING A DEFUALT DETECTION MODEL\n",
"\n",
"---\n",
"\n",
"\n",
"\n",
"## Table of Contents\n",
"1. Problem Description (Brief Write Up)\n",
"2. Exploratory Data Analysis (EDA)\n",
"3. Data Pre-processing\n",
"4. Model Selection\n",
"5. Evaluation\n",
"6. Discussion and Possible Improvements\n",
"\n",
"## 1. Problem Description\n",
"\n",
"The data set we will be working on contains payment information of 30,000 credit card holders obtained from a bank in Taiwan. \n",
"\n",
"Each data sample is described by 23 feature attributes and a binary target feature (default or not) valued 0 (= not default) or 1 (= default). \n",
"\n",
"The 23 explanatory attributes and their explanations (from the data provider) are as follows:\n",
"\n",
"### X1 - X5: Indivual attributes of customer\n",
"\n",
"X1: Amount of the given credit (NT dollar): it includes both the individual consumer credit and his/her family (supplementary) credit. \n",
"\n",
"X2: Gender (1 = male; 2 = female). \n",
"\n",
"X3: Education (1 = graduate school; 2 = university; 3 = high school; 4 = others). \n",
"\n",
"X4: Marital status (1 = married; 2 = single; 3 = others). \n",
"\n",
"X5: Age (year). \n",
"\n",
"### X6 - X11: Repayment history from April to Septemeber 2005\n",
"The measurement scale for the repayment status is: -1 = pay duly; 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.\n",
"\n",
"\n",
"X6 = the repayment status in September, 2005\n",
"\n",
"X7 = the repayment status in August, 2005\n",
"\n",
"X8 = the repayment status in July, 2005\n",
"\n",
"X9 = the repayment status in June, 2005\n",
"\n",
"X10 = the repayment status in May, 2005\n",
"\n",
"X11 = the repayment status in April, 2005. \n",
"\n",
"### X12 - X17: Amount of bill statement (NT dollar) from April to September 2005\n",
"\n",
"X12 = amount of bill statement in September, 2005; \n",
"\n",
"X13 = amount of bill statement in August, 2005\n",
"\n",
". . .\n",
"\n",
"X17 = amount of bill statement in April, 2005. \n",
"\n",
"### X18 - X23: Amount of previous payment (NT dollar)\n",
"X18 = amount paid in September, 2005\n",
"\n",
"X19 = amount paid in August, 2005\n",
"\n",
". . .\n",
"\n",
"X23 = amount paid in April, 2005. \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "aM_aIU6UPHe4"
},
"source": [
"## EDA\n",
"\n",
"In this section we will explore the data set, its shape and its features to get an idea of the data.\n",
"\n",
"### Importing packages and the dataset"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Is0wEkk3LJCt"
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "x_Z7u_9vRC5m"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "KhmX9KWWyrUW"
},
"outputs": [],
"source": [
"url = 'https://raw.githubusercontent.com/reonho/bt2101disrudy/master/card.csv'\n",
"df = pd.read_csv(url, header = 1, index_col = 0)\n",
"# Dataset is now stored in a Pandas Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 255
},
"colab_type": "code",
"id": "FhJ2eAxVQhBm",
"outputId": "7f79bb40-f08f-4709-e7d4-1f747bb8af2f"
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>LIMIT_BAL</th>\n",
" <th>SEX</th>\n",
" <th>EDUCATION</th>\n",
" <th>MARRIAGE</th>\n",
" <th>AGE</th>\n",
" <th>PAY_0</th>\n",
" <th>PAY_2</th>\n",
" <th>PAY_3</th>\n",
" <th>PAY_4</th>\n",
" <th>PAY_5</th>\n",
" <th>...</th>\n",
" <th>BILL_AMT4</th>\n",
" <th>BILL_AMT5</th>\n",
" <th>BILL_AMT6</th>\n",
" <th>PAY_AMT1</th>\n",
" <th>PAY_AMT2</th>\n",
" <th>PAY_AMT3</th>\n",
" <th>PAY_AMT4</th>\n",
" <th>PAY_AMT5</th>\n",
" <th>PAY_AMT6</th>\n",
" <th>Y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ID</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>20000</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>24</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>-1</td>\n",
" <td>-1</td>\n",
" <td>-2</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>689</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>120000</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>26</td>\n",
" <td>-1</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>3272</td>\n",
" <td>3455</td>\n",
" <td>3261</td>\n",
" <td>0</td>\n",
" <td>1000</td>\n",
" <td>1000</td>\n",
" <td>1000</td>\n",
" <td>0</td>\n",
" <td>2000</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>90000</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>34</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>14331</td>\n",
" <td>14948</td>\n",
" <td>15549</td>\n",
" <td>1518</td>\n",
" <td>1500</td>\n",
" <td>1000</td>\n",
" <td>1000</td>\n",
" <td>1000</td>\n",
" <td>5000</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>50000</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>37</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>28314</td>\n",
" <td>28959</td>\n",
" <td>29547</td>\n",
" <td>2000</td>\n",
" <td>2019</td>\n",
" <td>1200</td>\n",
" <td>1100</td>\n",
" <td>1069</td>\n",
" <td>1000</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>50000</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>57</td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>20940</td>\n",
" <td>19146</td>\n",
" <td>19131</td>\n",
" <td>2000</td>\n",
" <td>36681</td>\n",
" <td>10000</td>\n",
" <td>9000</td>\n",
" <td>689</td>\n",
" <td>679</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 24 columns</p>\n",
"</div>"
],
"text/plain": [
" LIMIT_BAL SEX EDUCATION MARRIAGE AGE PAY_0 PAY_2 PAY_3 PAY_4 \\\n",
"ID \n",
"1 20000 2 2 1 24 2 2 -1 -1 \n",
"2 120000 2 2 2 26 -1 2 0 0 \n",
"3 90000 2 2 2 34 0 0 0 0 \n",
"4 50000 2 2 1 37 0 0 0 0 \n",
"5 50000 1 2 1 57 -1 0 -1 0 \n",
"\n",
" PAY_5 ... BILL_AMT4 BILL_AMT5 BILL_AMT6 PAY_AMT1 PAY_AMT2 PAY_AMT3 \\\n",
"ID ... \n",
"1 -2 ... 0 0 0 0 689 0 \n",
"2 0 ... 3272 3455 3261 0 1000 1000 \n",
"3 0 ... 14331 14948 15549 1518 1500 1000 \n",
"4 0 ... 28314 28959 29547 2000 2019 1200 \n",
"5 0 ... 20940 19146 19131 2000 36681 10000 \n",
"\n",
" PAY_AMT4 PAY_AMT5 PAY_AMT6 Y \n",
"ID \n",
"1 0 0 0 1 \n",
"2 1000 0 2000 1 \n",
"3 1000 1000 5000 0 \n",
"4 1100 1069 1000 0 \n",
"5 9000 689 679 0 \n",
"\n",
"[5 rows x 24 columns]"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#rename the target variable to \"Y\" for convenience\n",
"df[\"Y\"] = df[\"default payment next month\"] \n",
"df = df.drop(\"default payment next month\", axis = 1)\n",
"df0 = df #backup of df\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"colab_type": "code",
"id": "zcuPyfM86AKj",
"outputId": "89bb2e37-a3ba-43e5-99a7-6917f24acc3f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data has 24 Columns and 30000 Rows\n"
]
}
],
"source": [
"size = df.shape\n",
"print(\"Data has {} Columns and {} Rows\".format(size[1], size[0]))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"colab_type": "code",
"id": "QVaSnvJP3VbO",
"outputId": "4bf72e64-2d0c-41c3-85b5-3bd6e70920d3"
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#check for null values\n",
"df.isnull().any().sum() "
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "eVYXnIGH9Zq6"
},
"source": [
"There are no null values in the data.\n",
"\n",
"We can also calculate some summary statistics for each attribute."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 317
},
"colab_type": "code",
"id": "HgdgYfpR6hUM",
"outputId": "0e6655d1-3872-448d-864b-786a54b7cf70"
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>LIMIT_BAL</th>\n",
" <th>SEX</th>\n",
" <th>EDUCATION</th>\n",
" <th>MARRIAGE</th>\n",
" <th>AGE</th>\n",
" <th>PAY_0</th>\n",
" <th>PAY_2</th>\n",
" <th>PAY_3</th>\n",
" <th>PAY_4</th>\n",
" <th>PAY_5</th>\n",
" <th>...</th>\n",
" <th>BILL_AMT4</th>\n",
" <th>BILL_AMT5</th>\n",
" <th>BILL_AMT6</th>\n",
" <th>PAY_AMT1</th>\n",
" <th>PAY_AMT2</th>\n",
" <th>PAY_AMT3</th>\n",
" <th>PAY_AMT4</th>\n",
" <th>PAY_AMT5</th>\n",
" <th>PAY_AMT6</th>\n",
" <th>Y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>count</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>...</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>3.000000e+04</td>\n",
" <td>30000.00000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" <td>30000.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>mean</td>\n",
" <td>167484.322667</td>\n",
" <td>1.603733</td>\n",
" <td>1.853133</td>\n",
" <td>1.551867</td>\n",
" <td>35.485500</td>\n",
" <td>-0.016700</td>\n",
" <td>-0.133767</td>\n",
" <td>-0.166200</td>\n",
" <td>-0.220667</td>\n",
" <td>-0.266200</td>\n",
" <td>...</td>\n",
" <td>43262.948967</td>\n",
" <td>40311.400967</td>\n",
" <td>38871.760400</td>\n",
" <td>5663.580500</td>\n",
" <td>5.921163e+03</td>\n",
" <td>5225.68150</td>\n",
" <td>4826.076867</td>\n",
" <td>4799.387633</td>\n",
" <td>5215.502567</td>\n",
" <td>0.221200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>std</td>\n",
" <td>129747.661567</td>\n",
" <td>0.489129</td>\n",
" <td>0.790349</td>\n",
" <td>0.521970</td>\n",
" <td>9.217904</td>\n",
" <td>1.123802</td>\n",
" <td>1.197186</td>\n",
" <td>1.196868</td>\n",
" <td>1.169139</td>\n",
" <td>1.133187</td>\n",
" <td>...</td>\n",
" <td>64332.856134</td>\n",
" <td>60797.155770</td>\n",
" <td>59554.107537</td>\n",
" <td>16563.280354</td>\n",
" <td>2.304087e+04</td>\n",
" <td>17606.96147</td>\n",
" <td>15666.159744</td>\n",
" <td>15278.305679</td>\n",
" <td>17777.465775</td>\n",
" <td>0.415062</td>\n",
" </tr>\n",
" <tr>\n",
" <td>min</td>\n",
" <td>10000.000000</td>\n",
" <td>1.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>21.000000</td>\n",
" <td>-2.000000</td>\n",
" <td>-2.000000</td>\n",
" <td>-2.000000</td>\n",
" <td>-2.000000</td>\n",
" <td>-2.000000</td>\n",
" <td>...</td>\n",
" <td>-170000.000000</td>\n",
" <td>-81334.000000</td>\n",
" <td>-339603.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.00000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>25%</td>\n",
" <td>50000.000000</td>\n",
" <td>1.000000</td>\n",
" <td>1.000000</td>\n",
" <td>1.000000</td>\n",
" <td>28.000000</td>\n",
" <td>-1.000000</td>\n",
" <td>-1.000000</td>\n",
" <td>-1.000000</td>\n",
" <td>-1.000000</td>\n",
" <td>-1.000000</td>\n",
" <td>...</td>\n",
" <td>2326.750000</td>\n",
" <td>1763.000000</td>\n",
" <td>1256.000000</td>\n",
" <td>1000.000000</td>\n",
" <td>8.330000e+02</td>\n",
" <td>390.00000</td>\n",
" <td>296.000000</td>\n",
" <td>252.500000</td>\n",
" <td>117.750000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>50%</td>\n",
" <td>140000.000000</td>\n",
" <td>2.000000</td>\n",
" <td>2.000000</td>\n",
" <td>2.000000</td>\n",
" <td>34.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>...</td>\n",
" <td>19052.000000</td>\n",
" <td>18104.500000</td>\n",
" <td>17071.000000</td>\n",
" <td>2100.000000</td>\n",
" <td>2.009000e+03</td>\n",
" <td>1800.00000</td>\n",
" <td>1500.000000</td>\n",
" <td>1500.000000</td>\n",
" <td>1500.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>75%</td>\n",
" <td>240000.000000</td>\n",
" <td>2.000000</td>\n",
" <td>2.000000</td>\n",
" <td>2.000000</td>\n",
" <td>41.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>...</td>\n",
" <td>54506.000000</td>\n",
" <td>50190.500000</td>\n",
" <td>49198.250000</td>\n",
" <td>5006.000000</td>\n",
" <td>5.000000e+03</td>\n",
" <td>4505.00000</td>\n",
" <td>4013.250000</td>\n",
" <td>4031.500000</td>\n",
" <td>4000.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>max</td>\n",
" <td>1000000.000000</td>\n",
" <td>2.000000</td>\n",
" <td>6.000000</td>\n",
" <td>3.000000</td>\n",
" <td>79.000000</td>\n",
" <td>8.000000</td>\n",
" <td>8.000000</td>\n",
" <td>8.000000</td>\n",
" <td>8.000000</td>\n",
" <td>8.000000</td>\n",
" <td>...</td>\n",
" <td>891586.000000</td>\n",
" <td>927171.000000</td>\n",
" <td>961664.000000</td>\n",
" <td>873552.000000</td>\n",
" <td>1.684259e+06</td>\n",
" <td>896040.00000</td>\n",
" <td>621000.000000</td>\n",
" <td>426529.000000</td>\n",
" <td>528666.000000</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>8 rows × 24 columns</p>\n",
"</div>"
],
"text/plain": [
" LIMIT_BAL SEX EDUCATION MARRIAGE AGE \\\n",
"count 30000.000000 30000.000000 30000.000000 30000.000000 30000.000000 \n",
"mean 167484.322667 1.603733 1.853133 1.551867 35.485500 \n",
"std 129747.661567 0.489129 0.790349 0.521970 9.217904 \n",
"min 10000.000000 1.000000 0.000000 0.000000 21.000000 \n",
"25% 50000.000000 1.000000 1.000000 1.000000 28.000000 \n",
"50% 140000.000000 2.000000 2.000000 2.000000 34.000000 \n",
"75% 240000.000000 2.000000 2.000000 2.000000 41.000000 \n",
"max 1000000.000000 2.000000 6.000000 3.000000 79.000000 \n",
"\n",
" PAY_0 PAY_2 PAY_3 PAY_4 PAY_5 \\\n",
"count 30000.000000 30000.000000 30000.000000 30000.000000 30000.000000 \n",
"mean -0.016700 -0.133767 -0.166200 -0.220667 -0.266200 \n",
"std 1.123802 1.197186 1.196868 1.169139 1.133187 \n",
"min -2.000000 -2.000000 -2.000000 -2.000000 -2.000000 \n",
"25% -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 \n",
"50% 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"75% 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"max 8.000000 8.000000 8.000000 8.000000 8.000000 \n",
"\n",
" ... BILL_AMT4 BILL_AMT5 BILL_AMT6 PAY_AMT1 \\\n",
"count ... 30000.000000 30000.000000 30000.000000 30000.000000 \n",
"mean ... 43262.948967 40311.400967 38871.760400 5663.580500 \n",
"std ... 64332.856134 60797.155770 59554.107537 16563.280354 \n",
"min ... -170000.000000 -81334.000000 -339603.000000 0.000000 \n",
"25% ... 2326.750000 1763.000000 1256.000000 1000.000000 \n",
"50% ... 19052.000000 18104.500000 17071.000000 2100.000000 \n",
"75% ... 54506.000000 50190.500000 49198.250000 5006.000000 \n",
"max ... 891586.000000 927171.000000 961664.000000 873552.000000 \n",
"\n",
" PAY_AMT2 PAY_AMT3 PAY_AMT4 PAY_AMT5 \\\n",
"count 3.000000e+04 30000.00000 30000.000000 30000.000000 \n",
"mean 5.921163e+03 5225.68150 4826.076867 4799.387633 \n",
"std 2.304087e+04 17606.96147 15666.159744 15278.305679 \n",
"min 0.000000e+00 0.00000 0.000000 0.000000 \n",
"25% 8.330000e+02 390.00000 296.000000 252.500000 \n",
"50% 2.009000e+03 1800.00000 1500.000000 1500.000000 \n",
"75% 5.000000e+03 4505.00000 4013.250000 4031.500000 \n",
"max 1.684259e+06 896040.00000 621000.000000 426529.000000 \n",
"\n",
" PAY_AMT6 Y \n",
"count 30000.000000 30000.000000 \n",
"mean 5215.502567 0.221200 \n",
"std 17777.465775 0.415062 \n",
"min 0.000000 0.000000 \n",
"25% 117.750000 0.000000 \n",
"50% 1500.000000 0.000000 \n",
"75% 4000.000000 0.000000 \n",
"max 528666.000000 1.000000 \n",
"\n",
"[8 rows x 24 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "W6hhPNl1Slau"
},
"source": [
"### Exploring the features"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "1Sp2F3gzXX2F"
},
"source": [
"**1) Exploring target attribute:**\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 51
},
"colab_type": "code",
"id": "DCSEICWwXWgX",
"outputId": "9545da56-f31b-48f2-a271-db0e18677beb"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"defaults : 22.12 %\n",
"non defaults : 77.88000000000001 %\n"
]
}
],
"source": [
"All = df.shape[0]\n",
"default = df[df['Y'] == 1]\n",
"nondefault = df[df['Y'] == 0]\n",
"\n",
"x = len(default)/All\n",
"y = len(nondefault)/All\n",
"\n",
"print('defaults :',x*100,'%')\n",
"print('non defaults :',y*100,'%')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 312
},
"colab_type": "code",
"id": "W4TWo-gkYTql",
"outputId": "0f7d6129-f6f2-448a-9236-9f9ef7ae1bb4"
},
"outputs": [
{
"data": {
"text/plain": [
"Text(0, 0.5, 'Frequency')"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEWCAYAAACnlKo3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAapElEQVR4nO3deZxcZZ3v8c+XgALjAg6LCEhQo4iMsgTEcQNRBBwFRhz16oBeFHVwvDqLouOIG3fQGZfBBQcxF3BUFBFFQTGgiNcrSFBkEZWIKDEBoiyyKYu/+0c9LWWnOl056Uqn6c/79apXn/Oc55zzO51Kffs8p+pUqgpJkrpYZ7oLkCTNXIaIJKkzQ0SS1JkhIknqzBCRJHVmiEiSOjNEpNWU5NAkX27T6yepJFtNd10ASY5OcnybfnSSm6Zw2yckeWOb3ifJ4inc9jOT/HCqtqfRMUTUWZJb+x5/SHJH3/xL1nAtq/3ineTaJE/pm98uyd2TrVdVn6iq53bd77gazk/y0qnY1nhV9dOq2miIGl6d5Owhtveyqnrv6tY16N+uqs6uqies7rY1eutOdwGauarqAWPTSa4GXlFVk774DJJk3aqa9AV7bTNT615dSeZU1T3TXYemn2ciGpkkT05yQZKbkyxN8oEk67ZlY399vibJz4DLWvtzklyZ5KYkHxz/l3mSVyX5SZIbkpyRZMu26Lz28yftTOiAAfVsl+Tctu7yJCcmeWBbdgqwGfD1tv7r2jbn9J1d7dT+Sv9Gko8kuRE4YoK/3A9IcnXbz1FJ0vbzx+GlvprubtPvA3YFjm/7e19r36Ht88YkVww6tr7tPSrJd5LckuSrwMaD9tXmX9lqvCXJVUlekGQn4IPAHq2Ga1vfk5Mck+TrSW4DntTa3jpu/+9ov9+rkrygr338v2P/72yFf7vxw2NJ/iLJt9vz4pIk+/YtO7k9V85qx/KdJNtM9Dv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kFeOAq1KuZ7zzgwHZ944HAc4HbgZ8neQH88VrdEwas+yDgNuDmJJvT+76hMVcDu7Tp5zOYz7dVYIjMHofQu1h4CbAj8M5VWPc04Ep611KOpQVQ+w6Xg4D3JPkhcDHtesk4XwPWbft+F3B+37IjgK8A32DiobATgI95YX32qKrvA5+l95w6FRh7x9VLgEPb8+1yBnx/UFX9EPhBW74A+E7f4ncA/5nk2/TOvAc5Gfjnrm9Pn2287YkkqTPPRCRJnRkikqTODBFJUmeGiCSpM0NEktSZISKNSJKHJjk5yc/afcfOTPLoJJdNd23SVPET69IIpHdfjtOAE6vqRa1tR2DzaS1MmmKeiUijsSdwV1V9bKyh3dPsmrH5dtflbyf5fnuM3dhyiyTntQ9XXpbkqe1uASe0+UuTvGHNH5K0Is9EpNHYgd4NLVfmeuBZVfW7JPOAz9C7y/H/AM6qqqOSzAE2pHeXgS2rageAJBuNrnRpeIaINH3WAz7chrnuAR7d2i8EFrRb7X+xqi5OchXwiCQfAs4Avj4tFUvjOJwljcbl3Hujv4m8AbgOeAK9M5D7AVTVefRuv/8r4JNJDq6qG1u/c4HDgeNHU7a0agwRaTS+Adw/ySvHGpLsCmzT1+fBwLKq+gO9OyvPaf22Aa6vqo8DnwB2bt/Gt05VnQr8K7DzmjkMaeUczpJGoKqqfQnXB5McAfyO3m3IX9/X7aPAqe3W5t+kd/tygD3o3UX2LuBW4GBgS+D/tFvmA7x55AchDcG7+EqSOnM4S5LUmSEiSerMEJEkdWaISJI6M0QkSZ0ZIpKkzgwRSVJn/x+T6PNo2DnX9gAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# plotting target attribute against frequency\n",
"labels = ['non default','default']\n",
"classes = pd.value_counts(df['Y'], sort = True)\n",
"classes.plot(kind = 'bar', rot=0)\n",
"plt.title(\"Target attribute distribution\")\n",
"plt.xticks(range(2), labels)\n",
"plt.xlabel(\"Class\")\n",
"plt.ylabel(\"Frequency\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "tysR0WHw4SGU"
},
"source": [
"**2) Exploring categorical attributes**\n",
"\n",
"Categorical attributes are:\n",
"- Sex\n",
"- Education\n",
"- Marriage"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "oxsZ8GTGarMC"
},
"source": [
"**2a) Checking formatting for categorical attributes:**\n",
"\n",
"Since all categorical attributes are in numerical format, there is no need to convert them into numerical factors."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "TSiH-BxjyJ_e"
},
"source": [
"**2b) Analysis of categorical data groups**\n",
"\n",
"- Sex\n",
"- Education\n",
"- Marriage"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 323
},
"colab_type": "code",
"id": "s61SSRII00UB",
"outputId": "69df981f-8c36-43a9-d155-a6553adbba0b"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 60.373333\n",
"1 39.626667\n",
"Name: SEX, dtype: float64\n",
"--------------------------------------------------------\n",
"2 46.766667\n",
"1 35.283333\n",
"3 16.390000\n",
"5 0.933333\n",
"4 0.410000\n",
"6 0.170000\n",
"0 0.046667\n",
"Name: EDUCATION, dtype: float64\n",
"--------------------------------------------------------\n",
"2 53.213333\n",
"1 45.530000\n",
"3 1.076667\n",
"0 0.180000\n",
"Name: MARRIAGE, dtype: float64\n"
]
}
],
"source": [
"print(df[\"SEX\"].value_counts().apply(lambda r: r/All*100))\n",
"print(\"--------------------------------------------------------\")\n",
"print(df[\"EDUCATION\"].value_counts().apply(lambda r: r/All*100))\n",
"print(\"--------------------------------------------------------\")\n",
"print(df[\"MARRIAGE\"].value_counts().apply(lambda r: r/All*100))"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Uudv5XE828nb"
},
"source": [
"**Conclusion**\n",
"\n",
"- Categorical variable SEX does not seem to have any missing/extra groups, and it is separated into Male = 1 and Female = 2\n",
"- Categorical variable MARRIAGE seems to have unknown group = 0, which could be assumed to be missing data, with other groups being Married = 1, Single = 2, Others = 3\n",
"- Categorical variable EDUCATION seems to have unknown group = 0,5,6, with other groups being graduate school = 1, university = 2, high school = 3, others = 4 "
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Z92LGXPKetjL"
},
"source": [
"**2c) Analysing the relationship between categorical attributes and default payment (target attribute)**\n",
"\n",
"- Sex\n",
"- Education\n",
"- Marriage\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",