February 10, 2017
Targeting Current Customers
Identifying Customer Targets
## Loading required package: grid
## Loading required package: gplots
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
Let’s go ahead and examine the structure of the bank data frame.
## 'data.frame': 4521 obs. of 17 variables:
## $ age : int 30 33 35 30 59 35 36 39 41 43 ...
## $ job : chr "unemployed" "services" "management" "management" ...
## $ marital : chr "married" "married" "single" "married" ...
## $ education: chr "primary" "secondary" "tertiary" "tertiary" ...
## $ default : chr "no" "no" "no" "no" ...
## $ balance : int 1787 4789 1350 1476 0 747 307 147 221 -88 ...
## $ housing : chr "no" "yes" "yes" "yes" ...
## $ loan : chr "no" "yes" "no" "yes" ...
## $ contact : chr "cellular" "cellular" "cellular" "unknown" ...
## $ day : int 19 11 16 3 5 23 14 6 14 17 ...
## $ month : chr "oct" "may" "apr" "jun" ...
## $ duration : int 79 220 185 199 226 141 341 151 57 313 ...
## $ campaign : int 1 1 1 4 1 2 1 2 2 1 ...
## $ pdays : int -1 339 330 -1 -1 176 330 -1 -1 147 ...
## $ previous : int 0 4 1 0 0 3 2 0 0 2 ...
## $ poutcome : chr "unknown" "failure" "failure" "unknown" ...
## $ response : chr "no" "no" "no" "no" ...
## NULL
## age job marital education default balance housing loan contact
## 1 30 unemployed married primary no 1787 no no cellular
## 2 33 services married secondary no 4789 yes yes cellular
## 3 35 management single tertiary no 1350 yes no cellular
## 4 30 management married tertiary no 1476 yes yes unknown
## 5 59 blue-collar married secondary no 0 yes no unknown
## 6 35 management single tertiary no 747 no no cellular
## day month duration campaign pdays previous poutcome response
## 1 19 oct 79 1 -1 0 unknown no
## 2 11 may 220 1 339 4 failure no
## 3 16 apr 185 1 330 1 failure no
## 4 3 jun 199 4 -1 0 unknown no
## 5 5 may 226 1 -1 0 unknown no
## 6 23 feb 141 2 176 3 failure no
## [1] "age" "job" "marital" "education" "default"
## [6] "balance" "housing" "loan" "contact" "day"
## [11] "month" "duration" "campaign" "pdays" "previous"
## [16] "poutcome" "response"
## [1] "integer"
## NULL
##
## admin. blue-collar entrepreneur housemaid management
## 478 946 168 112 969
## retired self-employed services student technician
## 230 183 417 84 768
## unemployed unknown <NA>
## 128 38 0
##
## divorced married single <NA>
## 528 2797 1196 0
##
## primary secondary tertiary unknown <NA>
## 678 2306 1350 187 0
##
## no yes <NA>
## 4445 76 0
##
## no yes <NA>
## 1962 2559 0
##
## no yes <NA>
## 3830 691 0
## jobtype
## job White Collar Blue Collar Other/Unknown <NA>
## admin. 478 0 0 0
## blue-collar 0 946 0 0
## entrepreneur 168 0 0 0
## housemaid 0 0 112 0
## management 969 0 0 0
## retired 0 0 230 0
## self-employed 183 0 0 0
## services 0 417 0 0
## student 0 0 84 0
## technician 0 768 0 0
## unemployed 0 0 128 0
## unknown 0 0 38 0
## <NA> 0 0 0 0
## 'data.frame': 3705 obs. of 9 variables:
## $ response : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 2 1 ...
## $ age : int 30 30 59 39 41 39 43 36 20 40 ...
## $ jobtype : Factor w/ 3 levels "White Collar",..: 3 1 2 2 1 2 1 2 3 1 ...
## $ marital : Factor w/ 3 levels "Divorced","Married",..: 2 2 2 2 2 2 2 2 3 2 ...
## $ education: Factor w/ 4 levels "Primary","Secondary",..: 1 3 2 2 3 2 2 3 2 3 ...
## $ default : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
## $ balance : int 1787 1476 0 147 221 9374 264 1109 502 194 ...
## $ housing : Factor w/ 2 levels "No","Yes": 1 2 2 2 2 2 2 1 1 1 ...
## $ loan : Factor w/ 2 levels "No","Yes": 1 2 1 1 1 1 1 1 1 2 ...
## NULL
## response age jobtype marital education default balance housing
## 1 No 30 Other/Unknown Married Primary No 1787 No
## 4 No 30 White Collar Married Tertiary No 1476 Yes
## 5 No 59 Blue Collar Married Secondary No 0 Yes
## 8 No 39 Blue Collar Married Secondary No 147 Yes
## 9 No 41 White Collar Married Tertiary No 221 Yes
## 11 No 39 Blue Collar Married Secondary No 9374 Yes
## loan
## 1 No
## 4 Yes
## 5 No
## 8 No
## 9 No
## 11 No
## response age jobtype marital
## No :3368 Min. :19.00 White Collar :1453 Divorced: 443
## Yes: 337 1st Qu.:33.00 Blue Collar :1776 Married :2305
## Median :39.00 Other/Unknown: 476 Single : 957
## Mean :41.08
## 3rd Qu.:49.00
## Max. :87.00
## education default balance housing loan
## Primary : 580 No :3634 Min. :-3313 No :1662 No :3113
## Secondary:1891 Yes: 71 1st Qu.: 60 Yes:2043 Yes: 592
## Tertiary :1084 Median : 415
## Unknown : 150 Mean : 1375
## 3rd Qu.: 1412
## Max. :71188
## png
## 2
## response
## education No Yes <NA>
## Primary 532 48 0
## Secondary 1735 156 0
## Tertiary 962 122 0
## Unknown 139 11 0
## <NA> 0 0 0
## png
## 2
## response
## jobtype No Yes <NA>
## White Collar 1313 140 0
## Blue Collar 1648 128 0
## Other/Unknown 407 69 0
## <NA> 0 0 0
## png
## 2
## response
## marital No Yes <NA>
## Divorced 387 56 0
## Married 2135 170 0
## Single 846 111 0
## <NA> 0 0 0
## png
## 2
## response
## default No Yes <NA>
## No 3305 329 0
## Yes 63 8 0
## <NA> 0 0 0
## png
## 2
## png
## 2
## response
## housing No Yes <NA>
## No 1468 194 0
## Yes 1900 143 0
## <NA> 0 0 0
## png
## 2
## response
## loan No Yes <NA>
## No 2806 307 0
## Yes 562 30 0
## <NA> 0 0 0
## png
## 2
##
## Call:
## glm(formula = bank_spec, family = binomial, data = bankwork)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.8546 -0.4787 -0.3985 -0.3247 2.7165
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.250e+00 4.072e-01 -5.526 3.27e-08 ***
## age 1.004e-02 6.315e-03 1.591 0.111702
## jobtypeBlue Collar -1.435e-01 1.447e-01 -0.992 0.321168
## jobtypeOther/Unknown 4.139e-01 1.771e-01 2.337 0.019443 *
## educationSecondary 1.036e-01 1.820e-01 0.569 0.569413
## educationTertiary 3.025e-01 2.043e-01 1.481 0.138716
## educationUnknown -3.338e-01 3.527e-01 -0.946 0.344041
## maritalMarried -5.717e-01 1.668e-01 -3.428 0.000608 ***
## maritalSingle -3.509e-02 1.939e-01 -0.181 0.856376
## defaultYes 3.461e-01 3.876e-01 0.893 0.371917
## balance 4.783e-06 1.736e-05 0.276 0.782918
## housingYes -4.058e-01 1.221e-01 -3.324 0.000888 ***
## loanYes -6.961e-01 1.997e-01 -3.485 0.000491 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2258.2 on 3704 degrees of freedom
## Residual deviance: 2177.6 on 3692 degrees of freedom
## AIC: 2203.6
##
## Number of Fisher Scoring iterations: 5
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: response
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 3704 2258.2
## age 1 3.4257 3703 2254.8 0.0641901 .
## jobtype 2 20.1014 3701 2234.7 4.316e-05 ***
## education 3 8.0101 3698 2226.7 0.0458042 *
## marital 2 23.4978 3696 2203.2 7.898e-06 ***
## default 1 0.2848 3695 2202.9 0.5935650
## balance 1 0.2644 3694 2202.6 0.6071299
## housing 1 10.7676 3693 2191.8 0.0010329 **
## loan 1 14.2114 3692 2177.6 0.0001634 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## png
## 2
##
## Confusion Matrix (rows=Predicted Response, columns=Actual Choice
##
## No Yes
## NO 3368 337
## YES 0 0
##
## Percent Accuracy: 90.9
##
## Confusion Matrix (rows=Predicted Response, columns=Actual Choice
##
## No Yes
## NO 2262 159
## YES 1106 178
##
## Percent Accuracy: 65.9
## response
## Predict_Response No Yes <NA>
## NO 2262 159 0
## YES 1106 178 0
## <NA> 0 0 0
## png
## 2
## png
## 2
##
## Lift Chart Values by Decile:
## bankwork$decile: Decile_10
## [1] 0.4741376
## --------------------------------------------------------
## bankwork$decile: Decile_9
## [1] 0.5348464
## --------------------------------------------------------
## bankwork$decile: Decile_8
## [1] 0.592672
## --------------------------------------------------------
## bankwork$decile: Decile_7
## [1] 0.8022696
## --------------------------------------------------------
## bankwork$decile: Decile_6
## [1] 0.8593744
## --------------------------------------------------------
## bankwork$decile: Decile_5
## [1] 0.861697
## --------------------------------------------------------
## bankwork$decile: Decile_4
## [1] 1.218261
## --------------------------------------------------------
## bankwork$decile: Decile_3
## [1] 1.303878
## --------------------------------------------------------
## bankwork$decile: Decile_2
## [1] 1.12912
## --------------------------------------------------------
## bankwork$decile: Decile_1
## [1] 2.22252