Credit card companies use models to predict the likelihood that an applicant will default on their Bank Loan. With that in mind, the purpose of this project is to create a model that will predict whether or not an applicant will default on their Bank Loan. A data set with 1000 observations and 16 variables from Applied Analytics through Case Studies Using SAS and R by Deepti Gupta will be used for the project. The data set includes 8 categorical variables, including the outcome variable of interest called “Default,” and 8 numerical variables.
After reviewing the summary statistics, it is apparent that the variables Default , Car_Loan , Personal_loan , Home_loan , and Education_Loan are categorized as numeric variables when they are in fact Categorical variables. They will be converted to Factor variables in addition to Emp_Status , Marital_Status , and Gender for ease of analysis. The summary statistic function was rerun after converting these variables and that output is displayed below.
## Default Checking_amount Term Credit_score Gender
## 0:700 Min. :-665.0 Min. : 9.00 Min. : 376.0 Female:310
## 1:300 1st Qu.: 164.8 1st Qu.:16.00 1st Qu.: 725.8 Male :690
## Median : 351.5 Median :18.00 Median : 770.5
## Mean : 362.4 Mean :17.82 Mean : 760.5
## 3rd Qu.: 553.5 3rd Qu.:20.00 3rd Qu.: 812.0
## Max. :1319.0 Max. :27.00 Max. :1029.0
## Marital_status Car_loan Personal_loan Home_loan Education_loan
## Married:548 0:647 0:526 0:944 0:888
## Single :452 1:353 1:474 1: 56 1:112
##
##
##
##
## Emp_status Amount Saving_amount Emp_duration
## employed :308 Min. : 244 Min. :2082 Min. : 0.00
## unemployed:692 1st Qu.:1016 1st Qu.:2951 1st Qu.: 15.00
## Median :1226 Median :3203 Median : 41.00
## Mean :1219 Mean :3179 Mean : 49.39
## 3rd Qu.:1420 3rd Qu.:3402 3rd Qu.: 85.00
## Max. :2362 Max. :4108 Max. :120.00
## Age No_of_credit_acc
## Min. :18.00 Min. :1.000
## 1st Qu.:29.00 1st Qu.:1.000
## Median :32.00 Median :2.000
## Mean :31.21 Mean :2.546
## 3rd Qu.:34.00 3rd Qu.:3.000
## Max. :42.00 Max. :9.000
What sticks out from the summary table above is that 692 applicants out of 1000 were unemployed. Looking at a table comparing employment status by gender and performing a chi-square test of association, there’s a significant association with employment status and gender, however there is not a significant association between employment status and default, (see uni variate Chi Square analysis section). Looking at marital status by employment status there’s a significant association with married individuals being more unemployed. Another interesting piece of information appeared looking at cross tabulations between categorical variables. Within the data set none of the females are married. Performing a Mantel-Haenszel chi-squared test it can be seen that when controlling for gender there is significant association between employment status and marital status. Therefore, within the data set males are more likely to be married and unemployed compared to the females within the data.
##
## Female Male
## employed 142 166
## unemployed 168 524
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Gender and default$Emp_status
## X-squared = 46.454, df = 1, p-value = 0.000000000009378
statistic | p.value | parameter | method |
|---|---|---|---|
46.5 | 0.0000*** | 1 | Pearson's Chi-squared test with Yates' continuity correction |
Signif. codes: 0 <= '***' < 0.001 < '**' < 0.01 < '*' < 0.05 | |||
##
## Married Single
## employed 106 202
## unemployed 442 250
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Emp_status and default$Marital_status
## X-squared = 73.481, df = 1, p-value < 0.00000000000000022
When looking at No_of_credit_acc, it can be seen that the number of credit accounts declines after five, however, for the time being, No_of_credit_acc will remain numeric and un collapsed. It may prove more advantageous in later stages to convert No_of_credit_acc to a factor variable and collapse 6-9 into a 6+ category.
##
## 1 2 3 4 5 6 7 8 9
## 308 325 119 105 109 6 8 6 14
In addition, Univariate ChiSquare Tests were performed with categorical variables by the default variable to discover any significant association.
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Gender
## X-squared = 5.3485, df = 1, p-value = 0.02074
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Marital_status
## X-squared = 6.1598, df = 1, p-value = 0.01307
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Car_loan
## X-squared = 5.074, df = 1, p-value = 0.02429
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Personal_loan
## X-squared = 45.298, df = 1, p-value = 0.00000000001693
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Home_loan
## X-squared = 7.7909, df = 1, p-value = 0.005251
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Education_loan
## X-squared = 80.093, df = 1, p-value < 0.00000000000000022
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: default$Default and default$Emp_status
## X-squared = 0.080655, df = 1, p-value = 0.7764
All categorical variables with the exception of Emp_status yielded a statistically significant assocation with default. The most significant association occurred between default and Education_Loan where those without student loans did not default. The results are shown in the bar chart below
A correlation matrix was used to assess for any significant correlation between numeric variables. From the Matrix it can be seen that the most significant positive correlation is between Saving_amount and age. As age increases, savings amount increases. In terms of negative correlation, the most significant is between Age and Term. As age increases, term decreases. The squares with X’s indicate that there is no significant correlation between the two varibles at the .05 significance level. All squares without X’s demonstrated significant correlation at the .05 significance level.
In Review of density plots that are the numerical variables crossed by default, a number of things stick out visually. Those who default have a lower Checking amount, greater Terms, lower Credit Scores, greater Amount, lower Savings amount, and a younger age.
Scatter plots were prepared for the following numerical variables with the variable Default creating two different levels. These plots indicate visually there may be some interaction between the variables. For example, Among those who default, there appears to be a negative correlation between credit score and savings amount, whereas among those who do not default, there appears to be a positive correlation between the two variables.
To investigate whether or not someone will default on their loan, three logistic regression models were fit to the data to determine which model performs best in predicting whether or not someone will default. The logistic regression model will also indicate which variables are the most significant in terms of assocation between defaulting on a loan.
The Original data set was split in to a training data set to fit logistic regression models and a test data set to assess the performance of the models.
Next a Full Logistic Regression Model is fit to the training data set with “Default” as the response variable and the other fifteen variables as predictor variables.
| Estimate | Std. Error | z value | Pr(>|z|) | |
|---|---|---|---|---|
| (Intercept) | 39.7502029 | 5.9508357 | 6.6797682 | 0.0000000 |
| Checking_amount | -0.0049581 | 0.0008120 | -6.1058857 | 0.0000000 |
| Term | 0.2278201 | 0.0691138 | 3.2963029 | 0.0009797 |
| Credit_score | -0.0103493 | 0.0025004 | -4.1391019 | 0.0000349 |
| GenderMale | -0.3213695 | 0.6583578 | -0.4881381 | 0.6254520 |
| Marital_statusSingle | 0.1489169 | 0.6523004 | 0.2282949 | 0.8194170 |
| Car_loan1 | -1.3368778 | 3.4979977 | -0.3821837 | 0.7023251 |
| Personal_loan1 | -2.3502813 | 3.4983379 | -0.6718280 | 0.5016932 |
| Home_loan1 | -4.3727755 | 3.5784921 | -1.2219604 | 0.2217226 |
| Education_loan1 | 0.4354401 | 3.5315183 | 0.1233011 | 0.9018687 |
| Emp_statusunemployed | 0.2770684 | 0.4134806 | 0.6700880 | 0.5028017 |
| Amount | 0.0006286 | 0.0006742 | 0.9323768 | 0.3511418 |
| Saving_amount | -0.0047737 | 0.0007390 | -6.4596266 | 0.0000000 |
| Emp_duration | 0.0048010 | 0.0056610 | 0.8480884 | 0.3963887 |
| Age | -0.6587653 | 0.0792082 | -8.3168794 | 0.0000000 |
| No_of_credit_acc | -0.0740906 | 0.1219864 | -0.6073681 | 0.5436067 |
From the table above it can be seen that the variables Checking_amount , Term , Credit_score , Saving_Amount , and Emp_duration have a highly significant assocation regarding whether or not someone will default. These five variables are also the only statistically significant variables at a .05 significance level in terms of association between whether or not someone will default.
In terms of general prediction, a cut off probability first needed to be established. Five fold cross-validation was performed to determine the optimal cut off probability. After performing Five Fold Cross Validation on the training dataset, it was determined that the optimal cut off probability was .33 for the full model. This means that any individual with a probability greater than .33 was predicted to default on their loan. In addition, using the training data set, the full model correctly predicted whether someone would default or not default on their loan 94.07% of the time. Incorporating the same cut off threshold of 0.33, the testing data set yielded an accuracy rate of 93.76947%, indicating the full model correctly predicted whether someone would default or not default on their loan 93.7694% of the time.
| Dataset | Percent.Correct |
|---|---|
| Testing | 93.76947 |
The C-Statistics or Area Under Receiver Operator curve below indicate outstanding discrimination between both the training and testing data sets. The full model does an outstanding job of determining whether someone will default on a loan between both data sets.
| sensitivity | specificity | precision | recall | F1 |
|---|---|---|---|---|
| 0.9101124 | 0.9482759 | 0.8709677 | 0.9101124 | 0.8901099 |
The Full model contained VIF values all below five for numeric variables, indicating there’s no multicollinearity issues.
Vif Values
## Checking_amount Term Credit_score Gender
## 1.175929 1.116214 1.148574 2.934235
## Marital_status Car_loan Personal_loan Home_loan
## 3.131247 88.289725 88.471458 21.014307
## Education_loan Emp_status Amount Saving_amount
## 31.061133 1.099390 1.073358 1.225992
## Emp_duration Age No_of_credit_acc
## 1.265000 1.232210 1.099094
Outliers:
Significant outliers were discovered for observations 766, 391, and 225. None of these outliers appear to be the result of any type of error and thus remained in the model.
To construct a reduced model, a step wise selection algorithm was incorporated to select features for the reduced model. Forward and Backward selection yielded the same features for the model, whereas forward selection chose all but one feature to include in the model. Based on this, the features chosen from backward and foward-backward (both) selection were incorporated in to the reduced, Step AIC model.
| Estimate | Std. Error | z value | Pr(>|z|) | |
|---|---|---|---|---|
| (Intercept) | 40.6805068 | 4.6721917 | 8.706943 | 0.0000000 |
| Checking_amount | -0.0051008 | 0.0008115 | -6.285320 | 0.0000000 |
| Term | 0.2278150 | 0.0679156 | 3.354382 | 0.0007954 |
| Credit_score | -0.0100096 | 0.0024107 | -4.152073 | 0.0000329 |
| Car_loan1 | -1.8854450 | 0.7111762 | -2.651164 | 0.0080215 |
| Personal_loan1 | -2.8634233 | 0.7121041 | -4.021074 | 0.0000579 |
| Home_loan1 | -4.9128915 | 1.0650777 | -4.612707 | 0.0000040 |
| Saving_amount | -0.0047029 | 0.0007248 | -6.488601 | 0.0000000 |
| Age | -0.6578607 | 0.0772661 | -8.514220 | 0.0000000 |
Five-fold cross-validation was performed on the training dataset for the Reduced Stepwise AIC model. The results yielded an optimal cut off point of .29 for this model and an accuacy of 93.93%. The cut of point from cross-validation was then used against the testing data set to determine the accuracy of the Reduced model. The model was accurate 93.76947% in predicting whether someone would default or not default on their loan. This accuracy is identical to that of the full model.
| Dataset | Percent.Correct |
|---|---|
| Testing | 93.76947 |
Although the Sensitivity and Specificity are different between the full model and the Stepwise AIC Model, both models have an identical Area under the Curve of 0.9783. This indicates both models perform identically in terms of discrimination. Furthmore, these results indicate the reduced Stepwise model is not underfit in comparison to the full model.
| sensitivity | specificity | precision | recall | F1 |
|---|---|---|---|---|
| 0.9213483 | 0.9439655 | 0.8631579 | 0.9213483 | 0.8913043 |
The reduced model also possessed outstanding discrimination on whether someone will default on their loan. What stands out is that the reduced model produced almost as well as the full model in terms of discriminating whether or not someone will default on their loan.
VIF values for the reduced model are all below five indicating multicollinearity is not an issue with the model.
Vif Values
## Checking_amount Term Credit_score Car_loan Personal_loan
## 1.179076 1.079779 1.107157 3.729746 3.764884
## Home_loan Saving_amount Age
## 1.839213 1.198554 1.191175
Outliers:
The reduced model produced the same outliers as the full model and again were maintained within the reduced model.
After feature selection was performed using the Step AIC method within the prior section, the selected features in the reduced model were tested for pairwise interactions one at a time. The analysis determined the following terms have a significant interaction at the .05 significance level: Term:Credit_score: 0.00696 , Credit_score:Saving_amount: 0.028013 , Car_loan:Saving_Amount: 0.01270 , Personal_loan:Saving_amount: 0.02896. These interaction terms were then included into a new stepwise AIC algorithm using backward selection. The results are found below.
| Estimate | Std. Error | z value | Pr(>|z|) | |
|---|---|---|---|---|
| (Intercept) | -40.0033587 | 26.6767635 | -1.499558 | 0.1337289 |
| Checking_amount | -0.0054640 | 0.0008952 | -6.103825 | 0.0000000 |
| Term | 2.2058815 | 0.7967328 | 2.768659 | 0.0056287 |
| Credit_score | 0.0936155 | 0.0356803 | 2.623730 | 0.0086973 |
| Car_loan1 | 9.3352690 | 4.9790110 | 1.874924 | 0.0608031 |
| Personal_loan1 | -3.2922717 | 0.7422448 | -4.435561 | 0.0000092 |
| Home_loan1 | -4.9308864 | 1.0534840 | -4.680552 | 0.0000029 |
| Saving_amount | 0.0105865 | 0.0079489 | 1.331814 | 0.1829214 |
| Age | -0.6884882 | 0.0816802 | -8.429075 | 0.0000000 |
| Term:Credit_score | -0.0026054 | 0.0010392 | -2.507165 | 0.0121704 |
| Credit_score:Saving_amount | -0.0000187 | 0.0000105 | -1.780319 | 0.0750237 |
| Car_loan1:Saving_amount | -0.0037327 | 0.0016006 | -2.332038 | 0.0196987 |
Cross validation performed on the interaction terms Model yielded an optimal cut off probability of 0.52 with an accuracy level of 0.9496. In terms of prediction using the cross validation cut off threshold and the testing data sat, the model recorded an accuracy of 93.76947 which is identical to the accuracy of the Reduced Stepwise AIC Model and the Full Model.
| Dataset | Percent.Correct |
|---|---|
| Testing | 93.76947 |
The Interaction Terms model did not perform as well as the full model and reduced model in terms of discrimination within the testing data set. Although the AUC for the reduced interaction terms model was 0.9656, which is still outstanding discrimination, the AUC is 0.0127 less than that of the Full Model and Reduced Stepwise Model.
| sensitivity | specificity | precision | recall | F1 |
|---|---|---|---|---|
| 0.8651685 | 0.9655172 | 0.9058824 | 0.8651685 | 0.8850575 |
Because there are interaction terms within this model, the VIF values are well above the 5-10 range which indicates there is significant multicollinearity issues.
Vif Values
## Checking_amount Term
## 1.259927 132.676772
## Credit_score Car_loan
## 189.910476 158.346819
## Personal_loan Home_loan
## 3.757487 1.972123
## Saving_amount Age
## 141.805124 1.352690
## Term:Credit_score Credit_score:Saving_amount
## 177.177483 265.625764
## Car_loan:Saving_amount
## 160.737466
Outliers:
The interaction model yielded the same outliers as the other two models and the outliers were maintained within the model.
After reviewing the three models, the Reduced Stepwise Model appears to be the most desirable to predict whether someone will default on their loan. The Reduced Stepwise Model performed identically to the full model in terms of accuracy and discrimination as shown through the method of cross-validation and the area under the receiver operator curve. No performance was lost in the Reduced Stepwise Model from paring down from fifteen variables to eight variables. Although the Reduced Stepwise Model with Interaction Terms performed as well as the full model and reduced model in terms of accuracy, it did not perform as well in terms of discrimination. The Reduced Stepwise Model with Interaction terms does not improve upon the performance of the Reduced Stepwise Model by including interaction terms into the Reduced Stepwise Model. A likely explanation is that the introduction of interaction terms may have “over fit” the model to the training data. When incorporating a logistic regression model building approach to determine who will and will not default on their loan, a reduced model incorporating the variables Checking_amount, Term, Credit_score, Car_loan, Personal_loan, Home_loan, Saving_amount, and Age proves to be the most parsimonious and effective model in terms of prediction and association.
The initial step in developing a Neural network is developing a model matrix so the names of all feature variables including implicitly defined dummy variables are defined and extracted. This was performed on both the test and training dataset. Feature engineering in the form of normalization was also performed on all numerical variables to prepare them for building a neural network.
There are some naming issues in the above dummy feature variables for network modeling (although they are good for regular linear and generalized linear regression models). These feature variables were renamed by excluding special characters in order to build the neural network model.
Next we build the neural network model. The neuralnet function was used for this task. A single layer neural network was developed.
| error | 14.8188943 |
| reached.threshold | 0.0091314 |
| steps | 3086.0000000 |
| Intercept.to.1layhid1 | 16.2278057 |
| checkingAmount.to.1layhid1 | -7.9969234 |
| Term.to.1layhid1 | 4.0177702 |
| creditScore.to.1layhid1 | -6.2274119 |
| GenderMale.to.1layhid1 | 0.0354737 |
| maritalStatusSingle.to.1layhid1 | 0.4361611 |
| carLoan1.to.1layhid1 | -0.3472344 |
| personalLoan1.to.1layhid1 | -1.4839978 |
| homeLoan1.to.1layhid1 | -3.1426432 |
| educationLoan1.to.1layhid1 | 0.9044362 |
| empStatusUnemployed.to.1layhid1 | 0.3316258 |
| Amount.to.1layhid1 | 0.2597866 |
| savingAmount.to.1layhid1 | -8.7516956 |
| empDuration.to.1layhid1 | 0.6731758 |
| Age.to.1layhid1 | -14.0420422 |
| noOfCreditAcc.to.1layhid1 | -0.6286136 |
| Intercept.to.Default1 | -0.0062100 |
| 1layhid1.to.Default1 | 1.0193845 |
A diagram of the neural network can be viewed below.
Figure 12. Single-layer backpropagation Neural network model for Default
5-fold cross validation was performed on the Neural Network to determine the optimal cut off point for determining the model’s accuracy. The optimal cut of point for the model was 0.33 with an accuracy of 94.22% for the training data.
In terms of accuracy, the neural network model was accurate 89.41% of the time. Based on the ROC curve the Neural Network performed much better than random guessing. The results are underwhelming compared to predictive and accuracy capabilities of the logistic regression model.
## $confusion.matrix
##
## 0 1
## FALSE 203 5
## TRUE 29 84
##
## $accuracy
## [1] 0.894081
Figure 14: ROC Curve of the neural network model.