The identification of customers who are more likely to accept financial products represents an important application of predictive analytics within the banking sector. Understanding the characteristics associated with customer responses to personal loan offers can help financial institutions improve customer segmentation and inform the allocation of marketing resources.
The objective of this analysis is to develop and evaluate a multivariable logistic regression model to predict personal loan acceptance using customer-level information from the Universal Bank dataset.
The analysis addresses the following research questions:
universal_bank <- read.csv("UniversalBank.csv")
head(universal_bank,3)
## id Age Experience Income ZIP.Code Family CCAvg Education Mortgage
## 1 1 25 1 49 91107 4 1.6 1 0
## 2 2 45 19 34 90089 3 1.5 1 0
## 3 3 39 15 11 94720 1 1.0 1 0
## PersonalLoan SecuritiesAccount CDAccount Online CreditCard
## 1 0 1 0 0 0
## 2 0 1 0 0 0
## 3 0 0 0 0 0
tail(universal_bank,3)
## id Age Experience Income ZIP.Code Family CCAvg Education Mortgage
## 4998 4998 63 39 24 93023 2 0.3 3 0
## 4999 4999 65 40 49 90034 3 0.5 2 0
## 5000 5000 28 4 83 92612 3 0.8 1 0
## PersonalLoan SecuritiesAccount CDAccount Online CreditCard
## 4998 0 0 0 0 0
## 4999 0 0 0 1 0
## 5000 0 0 0 1 1
str(universal_bank)
## 'data.frame': 5000 obs. of 14 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ Age : int 25 45 39 35 35 37 53 50 35 34 ...
## $ Experience : int 1 19 15 9 8 13 27 24 10 9 ...
## $ Income : int 49 34 11 100 45 29 72 22 81 180 ...
## $ ZIP.Code : int 91107 90089 94720 94112 91330 92121 91711 93943 90089 93023 ...
## $ Family : int 4 3 1 1 4 4 2 1 3 1 ...
## $ CCAvg : num 1.6 1.5 1 2.7 1 0.4 1.5 0.3 0.6 8.9 ...
## $ Education : int 1 1 1 2 2 2 2 3 2 3 ...
## $ Mortgage : int 0 0 0 0 0 155 0 0 104 0 ...
## $ PersonalLoan : int 0 0 0 0 0 0 0 0 0 1 ...
## $ SecuritiesAccount: int 1 1 0 0 0 0 0 0 0 0 ...
## $ CDAccount : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Online : int 0 0 0 0 0 1 1 0 1 0 ...
## $ CreditCard : int 0 0 0 0 1 0 0 1 0 0 ...
summary(universal_bank)
## id Age Experience Income ZIP.Code
## Min. : 1 Min. :23.00 Min. :-3.0 Min. : 8.00 Min. : 9307
## 1st Qu.:1251 1st Qu.:35.00 1st Qu.:10.0 1st Qu.: 39.00 1st Qu.:91911
## Median :2500 Median :45.00 Median :20.0 Median : 64.00 Median :93437
## Mean :2500 Mean :45.34 Mean :20.1 Mean : 73.77 Mean :93153
## 3rd Qu.:3750 3rd Qu.:55.00 3rd Qu.:30.0 3rd Qu.: 98.00 3rd Qu.:94608
## Max. :5000 Max. :67.00 Max. :43.0 Max. :224.00 Max. :96651
## Family CCAvg Education Mortgage
## Min. :1.000 Min. : 0.000 Min. :1.000 Min. : 0.0
## 1st Qu.:1.000 1st Qu.: 0.700 1st Qu.:1.000 1st Qu.: 0.0
## Median :2.000 Median : 1.500 Median :2.000 Median : 0.0
## Mean :2.396 Mean : 1.938 Mean :1.881 Mean : 56.5
## 3rd Qu.:3.000 3rd Qu.: 2.500 3rd Qu.:3.000 3rd Qu.:101.0
## Max. :4.000 Max. :10.000 Max. :3.000 Max. :635.0
## PersonalLoan SecuritiesAccount CDAccount Online
## Min. :0.000 Min. :0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.:0.000 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000
## Median :0.000 Median :0.0000 Median :0.0000 Median :1.0000
## Mean :0.096 Mean :0.1044 Mean :0.0604 Mean :0.5968
## 3rd Qu.:0.000 3rd Qu.:0.0000 3rd Qu.:0.0000 3rd Qu.:1.0000
## Max. :1.000 Max. :1.0000 Max. :1.0000 Max. :1.0000
## CreditCard
## Min. :0.000
## 1st Qu.:0.000
## Median :0.000
## Mean :0.294
## 3rd Qu.:1.000
## Max. :1.000
The Universal Bank dataset contained 5,000 customer records and 17 variables, covering demographic characteristics, financial information, banking product usage and personal loan outcomes. The dataset was stored as a data frame, with variables initially imported in numerical formats. The str() output identified integer variables such as age, professional experience, income, family size and mortgage value, alongside the categorical variables represented by numerical codes.
Inspection of the first six observations demonstrated the range of customer characteristics captured in the dataset. For example, the displayed records included customer ages ranging from 25 to 45 years, professional experience ranging from 1 to 19 years, and annual incomes ranging from $11,000 to $100,000. The records also illustrated variation in family size, credit card expenditure, education level and existing banking relationships.
An important data quality issue was identified in the Experience variable, where some observations contained negative values despite the variable representing years of professional experience. This required correction before model development. In addition, several variables, including Education, Family and the banking account indicators, were numerically coded categories rather than continuous measurements. These variables therefore required conversion to factors to ensure they were appropriately represented in the logistic regression model.
sum(universal_bank$Experience < 0, na.rm = TRUE)
## [1] 52
universal_bank <- universal_bank %>%
mutate(Experience = ifelse(Experience < 0, NA, Experience))
The initial data inspection identified negative values in the Experience variable, which are not logically meaningful when representing years of professional experience. A total of 52 negative observations were identified and recoded as missing values (NA) rather than retained as valid measurements. This avoided introducing implausible values into the regression model while preserving the remaining observations for analysis.
universal_bank$Income_log <- log10(universal_bank$Income + 1)
universal_bank$CCAvg_log <- log10(universal_bank$CCAvg + 1)
universal_bank$Mortgage_log <- log10(universal_bank$Mortgage + 1)
head(universal_bank,3)
## id Age Experience Income ZIP.Code Family CCAvg Education Mortgage
## 1 1 25 1 49 91107 4 1.6 1 0
## 2 2 45 19 34 90089 3 1.5 1 0
## 3 3 39 15 11 94720 1 1.0 1 0
## PersonalLoan SecuritiesAccount CDAccount Online CreditCard Income_log
## 1 0 1 0 0 0 1.698970
## 2 0 1 0 0 0 1.544068
## 3 0 0 0 0 0 1.079181
## CCAvg_log Mortgage_log
## 1 0.4149733 0
## 2 0.3979400 0
## 3 0.3010300 0
Base-10 logarithmic transformations were subsequently applied to annual income, average credit card expenditure and mortgage value. Adding one before taking the logarithm allowed observations with zero values to be retained, since the logarithm of zero is undefined. The transformations also compress the scale of larger observations, reducing the influence of large numerical values on the modelling process.
universal_bank$Family <- as.factor(universal_bank$Family)
universal_bank$Education <- as.factor(universal_bank$Education)
universal_bank$PersonalLoan <- as.factor(universal_bank$PersonalLoan)
universal_bank$SecuritiesAccount <- as.factor(universal_bank$SecuritiesAccount)
universal_bank$CDAccount <- as.factor(universal_bank$CDAccount)
universal_bank$Online <- as.factor(universal_bank$Online)
universal_bank$CreditCard <- as.factor(universal_bank$CreditCard)
str(universal_bank)
## 'data.frame': 5000 obs. of 17 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ Age : int 25 45 39 35 35 37 53 50 35 34 ...
## $ Experience : int 1 19 15 9 8 13 27 24 10 9 ...
## $ Income : int 49 34 11 100 45 29 72 22 81 180 ...
## $ ZIP.Code : int 91107 90089 94720 94112 91330 92121 91711 93943 90089 93023 ...
## $ Family : Factor w/ 4 levels "1","2","3","4": 4 3 1 1 4 4 2 1 3 1 ...
## $ CCAvg : num 1.6 1.5 1 2.7 1 0.4 1.5 0.3 0.6 8.9 ...
## $ Education : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 3 2 3 ...
## $ Mortgage : int 0 0 0 0 0 155 0 0 104 0 ...
## $ PersonalLoan : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 2 ...
## $ SecuritiesAccount: Factor w/ 2 levels "0","1": 2 2 1 1 1 1 1 1 1 1 ...
## $ CDAccount : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## $ Online : Factor w/ 2 levels "0","1": 1 1 1 1 1 2 2 1 2 1 ...
## $ CreditCard : Factor w/ 2 levels "0","1": 1 1 1 1 2 1 1 2 1 1 ...
## $ Income_log : num 1.7 1.54 1.08 2 1.66 ...
## $ CCAvg_log : num 0.415 0.398 0.301 0.568 0.301 ...
## $ Mortgage_log : num 0 0 0 0 0 ...
Categorical variables were converted to factors to ensure that they were treated as discrete groups rather than continuous numerical measurements during model fitting.The response variable, PersonalLoan, was also converted to a factor to represent the two possible loan outcomes: acceptance and non-acceptance.
set.seed(1182026)
split <- rbinom(nrow(universal_bank),1,prob = 0.33)
universal_bank.train <- subset(universal_bank, split == 0)
universal_bank.test <- subset(universal_bank, split == 1)
dim(universal_bank.train)
## [1] 3372 17
dim(universal_bank.test)
## [1] 1628 17
The submitted output reports 3,372 records in the training dataset and 1,628 in the test dataset. The model is fitted and reduced using the training data; the test data are reserved for evaluating classification performance after the model has been selected.
loan_model <- glm(PersonalLoan ~ Age + Experience + ZIP.Code + Family + CCAvg_log +
Education + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log + Mortgage_log,
data = universal_bank.train,family = binomial)
summary(loan_model)
##
## Call:
## glm(formula = PersonalLoan ~ Age + Experience + ZIP.Code + Family +
## CCAvg_log + Education + SecuritiesAccount + CDAccount + Online +
## CreditCard + Income_log + Mortgage_log, family = binomial,
## data = universal_bank.train)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.322e+01 6.539e+00 -6.610 3.85e-11 ***
## Age -2.079e-02 8.990e-02 -0.231 0.817110
## Experience 3.505e-02 8.978e-02 0.390 0.696218
## ZIP.Code -7.308e-06 5.921e-05 -0.123 0.901770
## Family2 -3.868e-01 2.842e-01 -1.361 0.173433
## Family3 2.268e+00 3.313e-01 6.844 7.72e-12 ***
## Family4 1.701e+00 3.066e-01 5.549 2.88e-08 ***
## CCAvg_log 2.083e+00 5.389e-01 3.865 0.000111 ***
## Education2 4.060e+00 3.436e-01 11.818 < 2e-16 ***
## Education3 4.145e+00 3.452e-01 12.008 < 2e-16 ***
## SecuritiesAccount1 -7.732e-01 3.952e-01 -1.957 0.050388 .
## CDAccount1 3.513e+00 4.444e-01 7.905 2.67e-15 ***
## Online1 -8.670e-01 2.237e-01 -3.876 0.000106 ***
## CreditCard1 -9.051e-01 2.761e-01 -3.278 0.001045 **
## Income_log 1.863e+01 1.211e+00 15.391 < 2e-16 ***
## Mortgage_log 1.921e-01 9.447e-02 2.033 0.042054 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2090.56 on 3335 degrees of freedom
## Residual deviance: 659.08 on 3320 degrees of freedom
## (36 observations deleted due to missingness)
## AIC: 691.08
##
## Number of Fisher Scoring iterations: 9
The initial model included all available explanatory variables, including customer demographics, financial characteristics and banking product usage. The model estimates the log-odds of personal loan acceptance as a function of these explanatory variables.
The summary() output was examined to assess the estimated regression coefficients, their standard errors, test statistics and associated p-values. These results provided an initial indication of the contribution of each explanatory variable to the prediction of loan acceptance and informed the subsequent variable selection procedure.
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Age + Experience + ZIP.Code + Family + CCAvg_log +
## Education + SecuritiesAccount + CDAccount + Online + CreditCard +
## Income_log + Mortgage_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 659.08 691.08
## Age 1 659.13 689.13 0.05 0.8166277
## Experience 1 659.23 689.23 0.15 0.6948659
## ZIP.Code 1 659.09 689.09 0.02 0.9017900
## Family 3 752.14 778.14 93.06 < 2.2e-16 ***
## CCAvg_log 1 675.23 705.23 16.16 5.835e-05 ***
## Education 2 934.59 962.59 275.51 < 2.2e-16 ***
## SecuritiesAccount 1 663.27 693.27 4.19 0.0405914 *
## CDAccount 1 732.91 762.91 73.83 < 2.2e-16 ***
## Online 1 674.56 704.56 15.48 8.334e-05 ***
## CreditCard 1 670.84 700.84 11.76 0.0006059 ***
## Income_log 1 1293.70 1323.70 634.63 < 2.2e-16 ***
## Mortgage_log 1 663.18 693.18 4.10 0.0428321 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#dropped ZIP.code
loan_model <- glm(PersonalLoan ~ Age + Experience + Family + CCAvg_log + Education + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log + Mortgage_log, data = universal_bank.train,family = binomial)
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Age + Experience + Family + CCAvg_log + Education +
## SecuritiesAccount + CDAccount + Online + CreditCard + Income_log +
## Mortgage_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 659.09 689.09
## Age 1 659.15 687.15 0.05 0.8168872
## Experience 1 659.25 687.25 0.15 0.6952267
## Family 3 752.26 776.26 93.16 < 2.2e-16 ***
## CCAvg_log 1 675.24 703.24 16.15 5.847e-05 ***
## Education 2 934.69 960.69 275.60 < 2.2e-16 ***
## SecuritiesAccount 1 663.30 691.30 4.21 0.0401792 *
## CDAccount 1 733.26 761.26 74.17 < 2.2e-16 ***
## Online 1 674.59 702.59 15.50 8.262e-05 ***
## CreditCard 1 670.86 698.86 11.76 0.0006045 ***
## Income_log 1 1294.56 1322.56 635.47 < 2.2e-16 ***
## Mortgage_log 1 663.18 691.18 4.09 0.0430927 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#dropped age
loan_model <- glm(PersonalLoan ~ Experience + Family + CCAvg_log + Education + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log + Mortgage_log, data = universal_bank.train,family = binomial)
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Experience + Family + CCAvg_log + Education +
## SecuritiesAccount + CDAccount + Online + CreditCard + Income_log +
## Mortgage_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 659.15 687.15
## Experience 1 661.62 687.62 2.48 0.1156297
## Family 3 752.30 774.30 93.15 < 2.2e-16 ***
## CCAvg_log 1 675.27 701.27 16.12 5.946e-05 ***
## Education 2 945.19 969.19 286.04 < 2.2e-16 ***
## SecuritiesAccount 1 663.33 689.33 4.19 0.0407643 *
## CDAccount 1 733.54 759.54 74.39 < 2.2e-16 ***
## Online 1 674.62 700.62 15.47 8.361e-05 ***
## CreditCard 1 670.88 696.88 11.74 0.0006128 ***
## Income_log 1 1304.22 1330.22 645.07 < 2.2e-16 ***
## Mortgage_log 1 663.19 689.19 4.05 0.0442818 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#dropped experience
loan_model <- glm(PersonalLoan ~ Family + CCAvg_log + Education + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log + Mortgage_log, data = universal_bank.train,family = binomial)
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Family + CCAvg_log + Education + SecuritiesAccount +
## CDAccount + Online + CreditCard + Income_log + Mortgage_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 667.14 693.14
## Family 3 758.58 778.58 91.44 < 2.2e-16 ***
## CCAvg_log 1 681.86 705.86 14.72 0.0001250 ***
## Education 2 949.97 971.97 282.82 < 2.2e-16 ***
## SecuritiesAccount 1 671.30 695.30 4.15 0.0415782 *
## CDAccount 1 743.84 767.84 76.69 < 2.2e-16 ***
## Online 1 681.65 705.65 14.51 0.0001397 ***
## CreditCard 1 680.06 704.06 12.91 0.0003265 ***
## Income_log 1 1309.94 1333.94 642.79 < 2.2e-16 ***
## Mortgage_log 1 670.27 694.27 3.12 0.0772805 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#dropped mortgage_log
loan_model <- glm(PersonalLoan ~ Family + CCAvg_log + Education + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log, data = universal_bank.train,family = binomial)
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Family + CCAvg_log + Education + SecuritiesAccount +
## CDAccount + Online + CreditCard + Income_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 670.27 694.27
## Family 3 760.64 778.64 90.38 < 2.2e-16 ***
## CCAvg_log 1 683.74 705.74 13.47 0.0002421 ***
## Education 2 950.09 970.09 279.82 < 2.2e-16 ***
## SecuritiesAccount 1 674.05 696.05 3.79 0.0516600 .
## CDAccount 1 746.59 768.59 76.32 < 2.2e-16 ***
## Online 1 683.95 705.95 13.69 0.0002162 ***
## CreditCard 1 682.93 704.93 12.66 0.0003731 ***
## Income_log 1 1312.91 1334.91 642.65 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#dropped education
loan_model <- glm(PersonalLoan ~ Family + CCAvg_log + SecuritiesAccount + CDAccount
+ Online + CreditCard + Income_log, data = universal_bank.train,family = binomial)
drop1(loan_model,test="Chi")
## Single term deletions
##
## Model:
## PersonalLoan ~ Family + CCAvg_log + SecuritiesAccount + CDAccount +
## Online + CreditCard + Income_log
## Df Deviance AIC LRT Pr(>Chi)
## <none> 950.09 970.09
## Family 3 1142.17 1156.17 192.08 < 2.2e-16 ***
## CCAvg_log 1 958.59 976.59 8.50 0.003554 **
## SecuritiesAccount 1 956.00 974.00 5.91 0.015027 *
## CDAccount 1 1054.64 1072.64 104.56 < 2.2e-16 ***
## Online 1 959.49 977.49 9.40 0.002172 **
## CreditCard 1 967.98 985.98 17.89 2.335e-05 ***
## Income_log 1 1471.39 1489.39 521.30 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(loan_model)
##
## Call:
## glm(formula = PersonalLoan ~ Family + CCAvg_log + SecuritiesAccount +
## CDAccount + Online + CreditCard + Income_log, family = binomial,
## data = universal_bank.train)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -30.5857 1.7516 -17.462 < 2e-16 ***
## Family2 -0.2850 0.2238 -1.274 0.20282
## Family3 2.5633 0.2821 9.087 < 2e-16 ***
## Family4 2.5324 0.2747 9.218 < 2e-16 ***
## CCAvg_log 1.1258 0.3930 2.865 0.00417 **
## SecuritiesAccount1 -0.7474 0.3201 -2.335 0.01956 *
## CDAccount1 3.2997 0.3523 9.365 < 2e-16 ***
## Online1 -0.5453 0.1785 -3.055 0.00225 **
## CreditCard1 -0.9232 0.2295 -4.022 5.77e-05 ***
## Income_log 13.3371 0.8292 16.084 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2097.69 on 3371 degrees of freedom
## Residual deviance: 950.09 on 3362 degrees of freedom
## AIC: 970.09
##
## Number of Fisher Scoring iterations: 8
Backward variable selection was used to identify a more parsimonious model by sequentially assessing the contribution of individual explanatory variables. The drop1() function was applied using likelihood ratio Chi-squared tests to evaluate the effect of removing each variable from the current model.
Variables were removed sequentially, beginning with ZIP.Code, followed by Age, Experience, Mortgage_log and Education. After each removal, the model was refitted and the remaining variables were reassessed. This process resulted in a final model containing seven explanatory variables:
The final model was examined using summary() to review the estimated coefficients and statistical significance of the retained predictors.
l.p.train<-predict(loan_model)
par(mfrow = c(1, 1))
boxplot(l.p.train ~ universal_bank.train$PersonalLoan,
xlab = "Personal Loan Status",
ylab = "Linear Predictor")
densityplot(
~l.p.train | universal_bank.train$PersonalLoan,
layout = c(1,2),
xlab = "Linear Predictor")
The linear predictions from the final logistic regression model were examined to assess how well the model differentiated between customers who accepted and those who did not accept a personal loan.
The linear predictor represents the estimated log-odds of loan acceptance. Higher values indicate a greater estimated likelihood of acceptance, while lower values indicate a greater estimated likelihood of non-acceptance.
Boxplots were used to compare the distributions of the linear predictions across the two outcome categories. Density plots were also generated to examine the shape and degree of overlap between the predicted values for accepted and non-accepted loans.
The extent of separation between the two distributions provides an indication of the model’s ability to distinguish between the outcome classes. Greater separation suggests stronger discriminatory performance, whereas substantial overlap indicates that some customers may be difficult to classify correctly.
table(l.p.train > -2, universal_bank.train$PersonalLoan)
##
## 0 1
## FALSE 2715 51
## TRUE 341 265
TN <- 2715
FN <- 51
FP <- 341
TP <- 265
Sensitivity <- TP / (TP + FN)
Specificity <- TN / (TN + FP)
CCR <- (TP + TN) / (TP + TN + FP + FN)
Misclassification <- (FP + FN) / (TP + TN + FP + FN)
# Create performance metrics table
performance_table <- data.frame(
Metric = c("Sensitivity", "Specificity",
"Correct Classification Rate (CCR)",
"Misclassification Rate"),
Percentage = round(c(Sensitivity, Specificity, CCR,
Misclassification) *100, 2))
performance_table
## Metric Percentage
## 1 Sensitivity 83.86
## 2 Specificity 88.84
## 3 Correct Classification Rate (CCR) 88.37
## 4 Misclassification Rate 11.63
A linear predictor cut-off of -2 was selected to classify customers into the two loan outcome categories. Observations with predicted linear values greater than -2 were classified as predicted loan acceptances, while values less than or equal to -2 were classified as predicted non-acceptances.
A classification table was generated to compare the predicted outcomes against the actual loan outcomes. The resulting counts were used to calculate sensitivity, specificity, the correct classification rate (CCR) and the misclassification rate.
The results indicate that the model identified approximately 84% of actual loan acceptances and correctly classified approximately 89% of non-acceptances within the training dataset.
#calculate the classification matrix, sensitivity, specificity, and correct classification rate for the test data
l.p.test <- predict(loan_model, newdata = universal_bank.test)
#cut-off of -2
table(l.p.test > -2, universal_bank.test$PersonalLoan)
##
## 0 1
## FALSE 1303 28
## TRUE 161 136
TN <- 1303
FN <- 28
FP <- 161
TP <- 136
Sensitivity <- TP / (TP + FN)
Specificity <- TN / (TN + FP)
CCR <- (TP + TN) / (TP + TN + FP + FN)
Misclassification <- (FP + FN) / (TP + TN + FP + FN)
#create performance metrics table
performance_table_test <- data.frame(
Metric = c("Sensitivity", "Specificity",
"Correct Classification Rate (CCR)",
"Misclassification Rate"),
Percentage = round(c(Sensitivity, Specificity, CCR,
Misclassification) *100, 2))
performance_table_test
## Metric Percentage
## 1 Sensitivity 82.93
## 2 Specificity 89.00
## 3 Correct Classification Rate (CCR) 88.39
## 4 Misclassification Rate 11.61
The final logistic regression model was applied to the independent test dataset to evaluate its predictive performance on observations that were not used during model estimation. The same linear predictor cut-off of -2 was retained to ensure that the classification results could be compared directly with those obtained from the training dataset.
The classification matrix was used to identify the numbers of correctly and incorrectly classified loan outcomes. The resulting counts were then used to calculate sensitivity, specificity, CCR and the misclassification rate.
The test results were very similar to those obtained from the training dataset. Sensitivity decreased slightly from 83.86% to 82.93%, while specificity increased marginally from 88.84% to 89.00%. The CCR remained almost unchanged, increasing slightly from 88.37% to 88.39%.
The similarity between the training and test results suggests that the model’s classification performance was relatively consistent across the two subsets. However, the overall CCR should be interpreted in the context of the imbalanced outcome distribution, as the majority class can achieve a relatively high classification rate even without a predictive model.
comparison_table <- merge(
performance_table,
performance_table_test,
by = "Metric",
suffixes = c("_Training", "_Test"))
colnames(comparison_table) <- c(
"Performance Metric",
"Training Data (%)",
"Test Data (%)")
comparison_table
## Performance Metric Training Data (%) Test Data (%)
## 1 Correct Classification Rate (CCR) 88.37 88.39
## 2 Misclassification Rate 11.63 11.61
## 3 Sensitivity 83.86 82.93
## 4 Specificity 88.84 89.00
The results showed only small differences between the two datasets across all four performance measures. In particular, the CCR and misclassification rate were almost identical, indicating that the overall classification results were stable when the model was applied to the test observations.
The small reduction in sensitivity suggests that the model identified a slightly smaller proportion of actual loan acceptances in the test dataset. However, the marginal increase in specificity indicates that its ability to correctly identify non-acceptances remained consistent.
These findings provide some evidence that the model generalises reasonably consistently to the test dataset, although classification performance must also be considered in relation to the distribution of the two outcome classes.
ROC(l.p.train, universal_bank.train$PersonalLoan, plot = "ROC")
(ROC) analysis was conducted to evaluate the discriminatory ability of the logistic regression model across different classification thresholds. Unlike the earlier classification analysis, which used a specified cut-off of -2, the ROC curve evaluates the trade-off between sensitivity and specificity across a range of possible thresholds.
The ROC curve was generated using the linear predictions and actual loan outcomes from the training dataset. The resulting curve was used to identify an alternative classification threshold and assess the model’s ability to distinguish between customers who accepted and did not accept a personal loan.
The reported area under the ROC curve (AUC) was 0.949, indicating strong discriminatory ability within the training dataset. The ROC analysis identified a threshold of approximately -2.008.
An AUC of 0.949 indicates that the model has a strong ability to rank customers who accepted a loan above those who did not. However, AUC measures discrimination rather than calibration or the proportion of observations correctly classified at a particular threshold.
table(l.p.test > -2.008, universal_bank.test$PersonalLoan)
##
## 0 1
## FALSE 1301 28
## TRUE 163 136
TN <- 1301
FN <- 28
FP <- 163
TP <- 136
Sensitivity <- TP / (TP + FN)
Specificity <- TN / (TN + FP)
CCR <- (TP + TN) / (TP + TN + FP + FN)
Misclassification <- (FP + FN) / (TP + TN + FP + FN)
#create performance metrics table
performance_table_test <- data.frame(
Metric = c("Sensitivity", "Specificity",
"Correct Classification Rate (CCR)",
"Misclassification Rate"),
Percentage = round(c(Sensitivity, Specificity, CCR,
Misclassification) *100, 2))
performance_table_test
## Metric Percentage
## 1 Sensitivity 82.93
## 2 Specificity 88.87
## 3 Correct Classification Rate (CCR) 88.27
## 4 Misclassification Rate 11.73
The ROC-derived threshold of -2.008 was applied to the independent test dataset to examine whether the alternative cut-off improved classification performance. The resulting classification matrix was used to calculate sensitivity, specificity, CCR and the misclassification rate.
The resulting sensitivity was 82.93%, specificity was 88.87%, CCR was 88.27%, and the misclassification rate was 11.73%.
Compared with the original threshold of -2, the ROC-derived threshold produced almost identical sensitivity, while specificity and CCR decreased slightly. The results suggest that changing the threshold from -2 to -2.008 did not materially improve the model’s classification performance on the test dataset.
The model demonstrated relatively consistent classification performance across the training and test datasets. At a linear predictor threshold of -2, the training CCR was 88.37%, compared with 88.39% in the test dataset. Sensitivity and specificity were also similar, suggesting that the model maintained comparable classification behaviour when applied to observations excluded from model fitting.
The ROC analysis produced an AUC of 0.949, indicating strong discriminatory ability in the training dataset. However, applying the ROC-derived threshold of -2.008 to the test data did not improve classification performance relative to the original threshold.
An important consideration is the imbalance between accepted and non-accepted loan outcomes. In the test dataset, 1,464 observations represented non-acceptances, compared with 164 acceptances. A classifier that predicted every observation as a non-acceptance would therefore achieve an accuracy of approximately 89.93%, which is higher than the model’s observed CCR of 88.39%. Consequently, overall classification accuracy alone does not demonstrate that the model provides an effective improvement over a simple majority-class prediction.
Nevertheless, the model identified approximately 83% of actual loan acceptances, which may be useful when the objective is to identify potential customers for targeted marketing or further assessment. The number of false positives also remains important, as these represent customers predicted to accept a loan who did not actually do so.
Overall, the analysis demonstrates how logistic regression, backward variable selection, classification measures and ROC analysis can be combined to investigate the predictive performance of a binary classification model. The findings suggest that the model has strong training-set discrimination and relatively consistent performance across the training and test datasets, although its practical value should be assessed in relation to the costs of false positive and false negative classifications.
Several limitations should be kept in mind when interpreting the reported results:
Imbalanced outcome: The dataset contains substantially more non-acceptances than acceptances. Overall classification rate should be considered alongside sensitivity and specificity.
Variable selection: Backward selection is a data-driven procedure. The retained variables depend on the sample and the sequence of model comparisons.
Generalisation: The findings relate to the supplied Universal Bank dataset. Performance would need to be assessed on more recent customer data before applying the model in a live banking environment.