The data set Credit Approval is used in credit risk analysis to develop models that can accurately predict credit card approval or denial based on the applicant’s characteristics and financial history. The data set is also used to evaluate the performance of various predictive models and to identify factors that are the most predictive of credit approval.There are a total of 690 observations in the data set.
The data set contains the following variables: A1: Categorical variable Gender (0, 1). A2: Numerical variable Age. A3: Numerical variable Debt. A4: Categorical variable indicating Marital Status (0,1). A5: Categorical variable Bank Customer (0,1). A6: Categorical variable Occupation. A7: Categorical variable Indicating Ethnicity. A8: Numerical variable Years Employed. A9: Categorical variable Prior Default (0,1) A10: Categorical variable Employed (0,1) A11: Numerical variable Credit Score. A12: Categorical variable Drivers License. A13: Categorical variable Citizenship. A14: Numerical variable Zip Code. A15: Numerical variable Income. A16: Binary response variable indicating whether the credit card application was Approved (0,1).
Can a logistic regression model be used to predict whether a credit card application will be approved or not, based on the applicant’s demographic and financial information?
The data set Credit.0 is changed to a working data set Credit. Also Approved is changed from a binary variable into character variable, while income is changed from a integer into a numerical value.
First pairwise scatter plots are created to find potential issues with normality in numerical predictor variables. In this case, all four of the scatter plots show issues.
To fix the issues with the histograms, the cut function is used to group the variables. This will help normalize the histograms distributions.
The code below standardizes the numerical predictor variables. which makes variables comparable and prevents the magnitude of variables from affecting their importance in the analysis. The standardized variables are then combined with the “Approved” variable to create a new data set named “sd.Credit”.
Now, the data is randomly split into two subsets. 80% of the data is used as training data which will be used to search the candidate models, validate them, and identify the final model using cross-validation. The other 20% is used for assesing the performance of the final model.
Since the training data is somewhat small, a 5 fold cross validation is performed to ensure the validation data set has enough cases. Three candidate models are created PE1, PE2, and PE3. In this case, PE3 has a slightly higher average prediction error of 0.3127273, so PE1 and PE2 slightly outperform it. Because PE2 and PE1 have the same prediction error but it is a simpler model, Candidate02 will just be chosen as the final predictive model.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
| PE1 | PE2 | PE3 |
|---|---|---|
| 0.2963636 | 0.2963636 | 0.3236364 |
The code below predicts the outcome of model candidate02 using a threshold of 0.5. It then constructs a confusion matrix to compare the predicted outcomes to the actual outcomes of the test data set. The resulting accuracy is 0.6811594, indicating that the model correctly predicted 68.12% of the outcomes in the test data set.
| x |
|---|
| 0.6956522 |
TPR is the true positive rate, sensitivity and FPR is the false positive rate, 1-specificity. The code estimates the TPR and FPR at each cut-off probability for each of the three candidate models.
A ROC Curve (receiver operating characteristic curve) is used to provide a visual representation of the best candidate model. It is a plot of the true positive rate (TPR) against the false positive rate (FPR). The three candidate models are graphed onto the chart, and while all three are very similar, model Candidate03 slightly outperforms the others.
A better ROC curve indicates that the model has better discriminative power, which means that it can better distinguish between the positive and negative classes. This is particularly useful when the costs of false positives and false negatives are different. However, a lower prediction error indicates that the model is making more accurate predictions, which is useful when the costs of misclassification are higher.
In this case, since all three candidate models are so similar and each have their own positives and negatives, it would be better to allow the individual to use whatever model they deem most appropriate for their own respective needs.
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred