Analysis of German Credit Data
Analysis of German Credit Data
Analysis of German Credit Data
When a bank receives a loan application, based on the applicants profile the
bank has to make a decision regarding whether to go ahead with the loan approval or not. Two
types of risks are associated with the banks decision
If the applicant is a good credit risk, i.e. is likely to repay the loan, then not approving the
loan to the person results in a loss of business to the bank
If the applicant is a bad credit risk, i.e. is not likely to repay the loan, then approving the
loan to the person results in a financial loss to the bank
Objective of Analysis:
To minimize loss from the banks perspective, the bank needs a decision rule regarding who to
give approval of the loan and who not to. An applicants demographic and socio-economic
profiles are considered by loan managers before a decision is taken regarding his/her loan
application.
The German Credit Data contains data on 20 variables and the classification whether an
applicant is considered a Good or a Bad credit risk for 1000 loan applicants. Here is a link to the
German Credit data (right-click and "save as" ). A predictive model developed on this data is
expected to provide a bank manager guidance for making a decision whether to approve a loan
to a prospective applicant based on his/her profiles.
Data Files for this case (right-click and "save as" ) :
German Credit data - german_credit.csv [1]
Training dataset - Training50.csv [2]
Test dataset - Test.csv [3]
Logistic regression: The response is binary (Good credit risk or Bad) and several predictors
are available.
Discriminant Analysis:
Tree-based method and Random Forest
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 2 of 24
Sample R code for Reading a .csv file
Before getting into any sophisticated analysis, the first step is to do an EDA and data cleaning.
Since both categorical and continuous variables are included in the data set, appropriate tables
and summary statistics are provided.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 3 of 24
Since most of the predictors are categorical with several levels, the full cross-classification of all
variables will lead to zero observations in many cells. Hence we need to reduce the table size.
For details of variable names and classification see Appendix 1.
Depending on the cell proportions given in the one-way table above two or more cells are
merged for several categorical predictors. We present below the final classification for the
predictors that may potentially have any influence on Creditability
Account Balance: No account (1), None (No balance) (2), Some Balance (3)
Payment Status: Some Problems (1), Paid Up (2), No Problems (in this bank) (3)
Savings/Stock Value: None, Below 100 DM, [100, 1000] DM, Above 1000 DM
Employment Length: Below 1 year (including unemployed), [1, 4), [4, 7), Above 7
Sex/Marital Status: Male Divorced/Single, Male Married/Widowed, Female
No of Credits at this bank: 1, More than 1
Guarantor: None, Yes
Concurrent Credits: Other Banks or Dept Stores, None
ForeignWorker variable may be dropped from the study
Purpose of Credit: New car, Used car, Home Related, Other
Cross-tabulation of the 9 predictors as defined above with Creditability is shown below. The
proportions shown in the cells are column proportions and so are the marginal proportions. For
example, 30% of 1000 applicants have no account and another 30% have no balance while
40% have some balance in their account. Among those who have no account 135 are found to
be Creditable and 139 are found to be Non-Creditable. In the group with no balance in their
account, 40% were found to be on-Creditable whereas in the group having some balance only
1% are found to be Non-Creditable.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 4 of 24
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 5 of 24
All the three variables show marked positive skewness. Boxplots bear this out even more
clearly.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 6 of 24
Since the number of predictors in this problem is not very high, it is possible to look into the
dependency of the response (Creditability) on each of them individually. The following table
summarizes the chi-square p-values for each contingency table. Note that among the sample of
size 1000, 700 were Creditable and 300 Non-Creditable. This classification is based on the
Banks opinion on the actual applicants.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 7 of 24
Only significant predictors are to be included in the logistic regression model. Since there are
1000 observations 50:50 cross-validation scheme is tried:
1000 observations are randomly partitioned into two equal sized subsets Training and Test
data. A logistic model is fit to the Training set.
Results are given below, shaded rows indicate variables not significant at 10% level.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 8 of 24
R output:
Null deviance: 598.536 on 499 degrees of freedom
Residual deviance: 464.01 on 477 degrees of freedom
AIC: 510.01
Removing the nonsignificant variables a second logistic regression is fit to the data.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 9 of 24
R output:
Null deviance: 598.53 on 499 degrees of freedom
Residual deviance: 472.12 on 483 degrees of freedom
AIC: 506.12
Need to remove another variable to come up with a model where all predictors are significant at
10% level.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 10 of 24
R output:
Null deviance: 598.53 on 499 degrees of freedom
Residual deviance: 474.67 on 484 degrees of freedom
AIC: 506.67
This model is recommended as the final model based on the Training Data. Final performance
of a model is evaluated by considering the classification power. Following are a few tables
defined at different thresholds of classification.
Following figure shows the performance of the classifier through ROC curve.
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 11 of 24
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 12 of 24
Neither logistic regression nor discriminant analysis is performing well for this data. The reason
DA may not do well is that, most of the predictors are categorical and nominal predictors are not
used in this analysis.
Both categorical and continuous predictors are used for binary classification. Using rpart
{library=rpart}, the following tree is obtained without any pruning.
R output:
n= 500
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 13 of 24
1) root 500 143 1 (0.28600000 0.71400000)
2) Account.Balance=1,2 261 110 1 (0.42145594 0.57854406)
4) Duration.of.Credit..month.>=13 165 79 0 (0.52121212 0.47878788)
8) Value.Savings.Stocks< 1.5 111 43 0 (0.61261261 0.38738739)
16) Purpose=4 45 9 0 (0.80000000 0.20000000)
32) Duration.in.Current.address>=1.5 38 4 0 (0.89473684 0.10526316)
*
33) Duration.in.Current.address< 1.5 7 2 1 (0.28571429 0.71428571) *
17) Purpose=1,2,3 66 32 1 (0.48484848 0.51515152)
34) Duration.of.Credit..month.>=33 26 7 0 (0.73076923 0.26923077) *
35) Duration.of.Credit..month.< 33 40 13 1 (0.32500000 0.67500000)
70) No.of.Credits.at.this.Bank< 1.5 28 12 1 (0.42857143 0.57142857)
140) Instalment.per.cent>=2.5 17 7 0 (0.58823529 0.41176471) *
141) Instalment.per.cent< 2.5 11 2 1 (0.18181818 0.81818182) *
71) No.of.Credits.at.this.Bank>=1.5 12 1 1 (0.08333333 0.91666667) *
9) Value.Savings.Stocks>=1.5 54 18 1 (0.33333333 0.66666667)
18) Length.of.current.employment< 2.5 32 15 1 (0.46875000
0.53125000)
36) Type.of.apartment=1 10 2 0 (0.80000000 0.20000000) *
37) Type.of.apartment=2,3 22 7 1 (0.31818182 0.68181818) *
19) Length.of.current.employment>=2.5 22 3 1 (0.13636364 0.86363636)
*
5) Duration.of.Credit..month.< 13 96 24 1 (0.25000000 0.75000000)
10) Payment.Status.of.Previous.Credit=1 7 2 0 (0.71428571
0.28571429) *
11) Payment.Status.of.Previous.Credit=2,3 89 19 1 (0.21348315
0.78651685) *
3) Account.Balance=3 239 33 1 (0.13807531 0.86192469)
6) Purpose=4 72 18 1 (0.25000000 0.75000000)
12) Concurrent.Credits< 1.5 11 4 0 (0.63636364 0.36363636) *
13) Concurrent.Credits>=1.5 61 11 1 (0.18032787 0.81967213) *
7) Purpose=1,2,3 167 15 1 (0.08982036 0.91017964) *
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 14 of 24
Following is the result for pruning the above tree for cross-validated classification error rate
90%.
n= 500
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 15 of 24
5) Duration.of.Credit..month.< 13 96 24 1 (0.2500000 0.7500000)
10) Payment.Status.of.Previous.Credit=1 7 2 0 (0.7142857 0.2857143)
*
11) Payment.Status.of.Previous.Credit=2,3 89 19 1 (0.2134831
0.7865169) *
3) Account.Balance=3 239 33 1 (0.1380753 0.8619247) *
Conclusion: For this data set tree-based method seems to be working better than logistic
regression or discriminant analysis.
Completely unsupervised random forest method on Training data with ntree = 200 leads to the
following error plot:
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 16 of 24
With judicious choice of more important predictors, further improvement in accuracy is possible.
But as improvement is slight, no attempt is made for supervised random forest.
Ultimately these statistical decisions must be translated into profit consideration for the bank.
Let us assume that a correct decision of the bank would result in 35% profit at the end of 5
years. A correct decision here means that the bank predicts an application to be good or creditworthy and it actually turns out to be credit worthy. When the opposite is true, i.e. bank predicts
the application to be good but it turns out to be bad credit, then the loss is 100%. If the bank
predicts an application to be non-creditworthy, then loan facility is not extended to that applicant
and bank does not incur any loss (opportunity loss is not considered here). The cost matrix,
therefore, is as follows:
Out of 1000 applicants, 70% are creditworthy. A loan manager without any model would incur
[0.7*0.35 + 0.3 (-1)] = - 0.055 or 0.055 unit loss. If the average loan amount is 3200 DM
(approximately), then the total loss will be 1760000 DM and per applicant loss is 176 DM.
Logistic regression model performance:
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 17 of 24
Tree-based classification and random forest show a per unit profit; other methods are not doing
well.
Description
Categories
Score
rel.
frequency
in % for
good
bad
credits credits
kredit
laufkont
Creditability:
1 : credit-worthy
0 : not credit-worthy
Balance of current
account
no balance or debit
35.00 23.43
15.33 49.71
no running account
45.00 19.86
10
3.00 10.43
4.67
7.00
Duration in months
(categorized)
<=6
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 18 of 24
moral
Payment of previous
credits
22.33 30.00
18.67 18.71
22.00 22.57
6.33
5.43
12.67
6.86
1.67
1.71
10.67
3.14
0.33
0.14
> 54
2.33
1.00
56.33 51.57
16.67 34.71
9.33
8.57
hesitant payment of
previous credits
8.33
2.14
problematic running
account / there are further
credits running but at other
banks
9.33
3.00
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 19 of 24
verw
Purpose of credit
new car
5.67 12.29
used car
19.33 17.57
items of furniture
20.67 31.14
radio / television
1.33
1.14
household appliances
2.67
2.00
repair
7.33
4.00
education
0.00
0.00
vacation
0.33
1.14
retraining
11.33
9.00
business
10
1.67
1.00
other
Hoehe
(Credit)
dhoehe
29.67 20.71
10
1.00
2.14
11.33
9.14
17.00 19.86
19.67 24.57
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 20 of 24
sparkont
beszeit
25.00 28.57
11.33
9.71
6.67
3.71
7.00
2.00
1.00
0.29
> 20000
0.00
0.00
< 100,- DM
11.33
9.86
3.67
7.43
2.00
6.00
>= 1000,- DM
10.67 21.57
72.33 55.14
unemployed
<= 1 year
23.33 14.57
34.67 33.57
13.00 19.29
>= 7 years
21.33 27.00
Value of savings or
stocks
7.67
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
5.57
4/3/2016
Page 21 of 24
rate
famges
buerge
wohnzeit
verm
Instalment in % of
available income
Further debtors /
Guarantors
Living in current
household for
>= 35
11.33 14.57
20.67 24.14
15.00 16.00
< 20
53.00 45.29
male: single
36.33 28.72
48.67 57.43
female:
none
Co-Applicant
6.00
3.29
Guarantor
3.33
6.00
< 1 year
12.00 13.43
32.33 30.14
14.33 15.14
>= 7 years
41.33 41.29
22.33 12.43
6.67
8.33
4.29
9.57
90.67 90.71
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 22 of 24
alter
dalter
weitkred
wohn
34.00 32.86
Car / Other
23.67 23.00
20.00 31.71
26.67 15.71
47.33 52.72
21.67 26.14
2.33
3.00
>= 65
2.00
2.43
at other banks
74.67 84.29
rented flat
62.00 75.43
owner-occupied flat
14.67
free apartment
23.33 15.57
Age in years
(categorized)
Type of apartment
19.00 11.71
6.33
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4.00
9.14
4/3/2016
Page 23 of 24
bishkred
beruf
pers
telef
gastarb
Number of previous
credits at this bank
(including the running
one)
Occupation
Number of persons
entitled to maintenance
Telephone
Foreign worker
one
66.67 61.86
two or three
30.67 34.43
four or five
2.00
3.14
six or more
0.67
0.57
unemployed / unskilled
with no permanent
residence
2.33
2.14
18.67 20.57
62.00 63.43
executive / self-employed /
higher civil servant
17.00 13.86
0 to 2
84.67 84.43
3 and more
15.33 15.57
no
62.33 58.43
yes
37.67 41.57
yes
no
1.33
4.71
98.67 95.29
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016
Page 24 of 24
http://www.stat.uni-muenchen.de/service/datenarchiv/kredit/kredit_e.html [4]
Source URL: https://onlinecourses.science.psu.edu/stat857/node/215
Links:
[1]
https://onlinecourses.science.psu.edu/stat857/sites/onlinecourses.science.psu.edu.stat857/files/german_credit.csv
[2]
https://onlinecourses.science.psu.edu/stat857/sites/onlinecourses.science.psu.edu.stat857/files/Training50.csv
[3] https://onlinecourses.science.psu.edu/stat857/sites/onlinecourses.science.psu.edu.stat857/files/Test50.csv
[4] http://www.stat.uni-muenchen.de/service/datenarchiv/kredit/kredit_e.html
https://onlinecourses.science.psu.edu/stat857/print/book/export/html/215
4/3/2016