Setup

bank = read_rds("/Users/rochellerafn/RStudio Files/BankChurners.rds")

Feature Engineering

Here we are implementing our new skill of “Principal Component Analysis” to decide what features to use to engineer our predictions for Churn. Based on the plot, it looks as though the “elbow” occurs around 3. We see the most change around the 3rd component which means the variance of the components following become less significant.
# create some cool features. Make sure you add comments so I know what you are trying to accomplish!
banko <- bank %>%
  mutate(Churn = Churn=="yes") %>%
  dummy_cols(remove_selected_columns = T)

pr_churn <- prcomp(x = select(banko,-Churn), scale = T, center = T)

screeplot(pr_churn, type = "lines")

Here we are taking a look at the first two components in a biplot to see which variables are most significant. If you zoom in on the plot, it’s clear that gender seems clearly significant. We opted not to use gender in our engineering just to be safe, in case there could be ethical issues of discrimination based on gender. Since we’re analyzing ‘churn’ (whether a customer will leave), perhaps it would be ok? Provide insentives for people identifying as female to stay… But again, to play it safe, we’re leaving gender out of it. Aside from that we can see that on the other ends, variables like total transaction amount, total transaction count and income less thank $40k seem to stand out. We also chose not to use the “blue card” feature because we discussed how humans tend to be easier to predict based on their habits rather than demographics. The type of card they have is given, it’s not an action. However, how much they spend and how often they spend are habits and actions.
biplot(pr_churn)
biplot(pr_churn, choices = c(1,2))

print(ncol(bank)) # Only 5 features allowed for project 2! Not counting the dependent variable.
## [1] 20
pr_churn$rotation
##                                         PC1           PC2          PC3
## Customer_Age                   -0.010813997  0.0757547936 -0.433019360
## Dependent_count                 0.036907819 -0.0377317629  0.112719183
## Months_on_book                 -0.005699747  0.0713462802 -0.427853027
## Total_Relationship_Count       -0.049689093  0.2001415587 -0.102343109
## Months_Inactive_12_mon         -0.012256624  0.0265776928 -0.114586464
## Contacts_Count_12_mon           0.016040264  0.0909043204 -0.123300916
## Credit_Limit                    0.413014059 -0.1184647817 -0.115635228
## Total_Revolving_Bal            -0.034971577 -0.0010124303  0.216509638
## Avg_Open_To_Buy                 0.416062573 -0.1183491437 -0.135021215
## Total_Amt_Chng_Q4_Q1            0.007772271  0.0026333373  0.174348201
## Total_Trans_Amt                 0.100869534 -0.3699279277  0.289883802
## Total_Trans_Ct                  0.044317988 -0.3805716862  0.303259402
## Total_Ct_Chng_Q4_Q1            -0.006905845 -0.0442536169  0.199821499
## Avg_Utilization_Ratio          -0.268875657  0.0348746106  0.211170707
## Gender_F                       -0.355263483 -0.3216570306 -0.190336830
## Gender_M                        0.355263483  0.3216570306  0.190336830
## Education_Level_College         0.004373639  0.0003329777  0.009695587
## Education_Level_Doctorate      -0.005706353 -0.0036269274 -0.059093066
## Education_Level_Graduate       -0.004115878 -0.0106117409 -0.017928153
## Education_Level_High School     0.003513914  0.0246190879  0.029106238
## Education_Level_Post-Graduate   0.005114198  0.0010958051  0.033172039
## Education_Level_Uneducated      0.001962101 -0.0105707065 -0.010319114
## Education_Level_Unknown        -0.004074645 -0.0021657338  0.006458350
## Marital_Status_Divorced         0.007488559 -0.0248339495  0.033151739
## Marital_Status_Married         -0.030806901  0.1738945600 -0.049881916
## Marital_Status_Single           0.017599981 -0.1478152617  0.008531959
## Marital_Status_Unknown          0.018419018 -0.0310883855  0.046009444
## Income_Category_$40K - $60K    -0.049031167  0.0263133355  0.084110862
## Income_Category_$60K - $80K     0.139209300  0.1755923344  0.163215027
## Income_Category_$80K - $120K    0.213389458  0.1521782046  0.054029597
## Income_Category_$120K +         0.172705565  0.0621837568 -0.062625192
## Income_Category_Less than $40K -0.284878123 -0.2090096715 -0.089170360
## Income_Category_Unknown        -0.046235765 -0.1327596236 -0.157001203
## Card_Category_Blue             -0.257857151  0.3513883431  0.159134939
## Card_Category_Gold              0.113877056 -0.1500641047 -0.035769610
## Card_Category_Platinum          0.047305369 -0.0797260734 -0.029431473
## Card_Category_Silver            0.223199987 -0.3035764523 -0.153834541
##                                         PC4          PC5          PC6
## Customer_Age                    0.443499234 -0.266842219  0.003345576
## Dependent_count                -0.081193438  0.109100516  0.097514325
## Months_on_book                  0.439072869 -0.274734380  0.006509941
## Total_Relationship_Count       -0.147836648  0.115075283 -0.293862484
## Months_Inactive_12_mon         -0.001921710 -0.059288100  0.039294366
## Contacts_Count_12_mon          -0.163137334  0.035553306 -0.047800261
## Credit_Limit                   -0.003755843  0.080990599 -0.052492125
## Total_Revolving_Bal             0.334555958  0.062542679 -0.459716873
## Avg_Open_To_Buy                -0.033748268  0.075366592 -0.011267112
## Total_Amt_Chng_Q4_Q1            0.117915538  0.139278369 -0.163881656
## Total_Trans_Amt                 0.262444253 -0.149981471  0.275895881
## Total_Trans_Ct                  0.225273171 -0.183203010  0.245451826
## Total_Ct_Chng_Q4_Q1             0.182273387  0.067487809 -0.156661702
## Avg_Utilization_Ratio           0.257176086  0.025783374 -0.392825422
## Gender_F                       -0.067697739  0.113851814  0.023559659
## Gender_M                        0.067697739 -0.113851814 -0.023559659
## Education_Level_College        -0.024100754  0.014402905  0.022332369
## Education_Level_Doctorate      -0.008318849 -0.025293962  0.046743197
## Education_Level_Graduate        0.016036359  0.047124906 -0.020742580
## Education_Level_High School     0.031582327 -0.018024493 -0.012086005
## Education_Level_Post-Graduate  -0.010007543  0.026901088 -0.014524292
## Education_Level_Uneducated     -0.018053749 -0.023400278  0.019641146
## Education_Level_Unknown        -0.006932294 -0.031694456 -0.015945692
## Marital_Status_Divorced        -0.072002664  0.002107928  0.030005373
## Marital_Status_Married          0.320106969  0.536301770  0.257409204
## Marital_Status_Single          -0.266356421 -0.548948741 -0.292834274
## Marital_Status_Unknown         -0.041657024 -0.001109133  0.025184945
## Income_Category_$40K - $60K     0.019636144 -0.044926389 -0.032068162
## Income_Category_$60K - $80K     0.025995880 -0.075116106 -0.014035928
## Income_Category_$80K - $120K    0.028692459 -0.018811267  0.010896864
## Income_Category_$120K +         0.038971138 -0.017014774  0.018740391
## Income_Category_Less than $40K -0.005177428  0.061605305 -0.075558313
## Income_Category_Unknown        -0.109854134  0.079331308  0.142053374
## Card_Category_Blue             -0.022247279 -0.209020498  0.278774578
## Card_Category_Gold              0.032067496  0.060138308 -0.086741539
## Card_Category_Platinum          0.023654477  0.017904628  0.003559924
## Card_Category_Silver            0.005039861  0.199955899 -0.268982568
##                                        PC7          PC8          PC9
## Customer_Age                   -0.03336354  0.036362109  0.034871555
## Dependent_count                 0.04081514 -0.044681645 -0.076070481
## Months_on_book                 -0.02940410  0.041067875  0.044670014
## Total_Relationship_Count       -0.10860198  0.119361902 -0.002946349
## Months_Inactive_12_mon          0.04268363 -0.010710413 -0.042706255
## Contacts_Count_12_mon           0.05699464 -0.062727730  0.018184995
## Credit_Limit                   -0.08112809  0.054445251 -0.094530295
## Total_Revolving_Bal             0.02699446 -0.098915085 -0.078540266
## Avg_Open_To_Buy                -0.08353113  0.063301638 -0.087469248
## Total_Amt_Chng_Q4_Q1           -0.35981356  0.384838953  0.056653514
## Total_Trans_Amt                 0.03854855 -0.011702758 -0.010484331
## Total_Trans_Ct                  0.01691837  0.009851743 -0.014565211
## Total_Ct_Chng_Q4_Q1            -0.35909704  0.395611732  0.033996975
## Avg_Utilization_Ratio           0.08621415 -0.121938678 -0.054130302
## Gender_F                       -0.07901224  0.042123098  0.019427834
## Gender_M                        0.07901224 -0.042123098 -0.019427834
## Education_Level_College        -0.09527680 -0.077086143  0.001828881
## Education_Level_Doctorate      -0.06062482 -0.043666086  0.004242611
## Education_Level_Graduate        0.59788110  0.573743969  0.056813175
## Education_Level_High School    -0.27902010 -0.314964137  0.041218032
## Education_Level_Post-Graduate  -0.01778466 -0.089634858  0.072376302
## Education_Level_Uneducated     -0.22224984 -0.056704358 -0.065748883
## Education_Level_Unknown        -0.11544485 -0.188968978 -0.102969462
## Marital_Status_Divorced        -0.02137404  0.012848235  0.033203519
## Marital_Status_Married          0.03995022 -0.070870852  0.006221875
## Marital_Status_Single          -0.03607840  0.082890741 -0.014349066
## Marital_Status_Unknown          0.01246608 -0.032253389 -0.018302586
## Income_Category_$40K - $60K     0.08572588 -0.136438725  0.734077625
## Income_Category_$60K - $80K     0.08865545 -0.077504469  0.062202222
## Income_Category_$80K - $120K   -0.01252546  0.108829575 -0.248231448
## Income_Category_$120K +        -0.06450217 -0.020313601 -0.178653732
## Income_Category_Less than $40K  0.12865975 -0.067686509 -0.472721598
## Income_Category_Unknown        -0.33139538  0.247399566  0.189816987
## Card_Category_Blue             -0.11104710  0.134914611 -0.121375625
## Card_Category_Gold              0.03367939 -0.075707427 -0.013790893
## Card_Category_Platinum          0.01518487  0.013319676 -0.005984434
## Card_Category_Silver            0.10431618 -0.116668449  0.142082446
##                                        PC10          PC11          PC12
## Customer_Age                   -0.023887483 -0.0375348089 -3.807232e-02
## Dependent_count                 0.121909790 -0.0083398450  2.454218e-02
## Months_on_book                 -0.028999572 -0.0393308764 -4.986042e-02
## Total_Relationship_Count       -0.018561680 -0.0235615607 -4.594087e-02
## Months_Inactive_12_mon         -0.012540239 -0.0013706112 -1.011301e-01
## Contacts_Count_12_mon           0.003772090  0.0022648757  1.355260e-02
## Credit_Limit                    0.133579110  0.0453632150  4.621317e-02
## Total_Revolving_Bal             0.372081021  0.0945571332  1.438395e-02
## Avg_Open_To_Buy                 0.100193697  0.0368765666  4.491394e-02
## Total_Amt_Chng_Q4_Q1           -0.255030489 -0.0794835388  1.713273e-02
## Total_Trans_Amt                -0.008204847 -0.0008039531  1.713456e-03
## Total_Trans_Ct                  0.017181356  0.0029799793 -6.095045e-03
## Total_Ct_Chng_Q4_Q1            -0.217597424 -0.0772250040 -5.816621e-05
## Avg_Utilization_Ratio           0.216176106  0.0371202721 -9.359374e-03
## Gender_F                        0.046024757  0.0273077248  3.044897e-02
## Gender_M                       -0.046024757 -0.0273077248 -3.044897e-02
## Education_Level_College         0.021306318 -0.1600044233  2.440679e-02
## Education_Level_Doctorate       0.039409654 -0.0151677577 -1.879981e-02
## Education_Level_Graduate        0.031491886  0.1485308774 -1.989404e-03
## Education_Level_High School    -0.152550043  0.7052984729 -8.087349e-02
## Education_Level_Post-Graduate   0.023220419 -0.0983960551 -1.595789e-02
## Education_Level_Uneducated      0.210994839 -0.3764480062 -4.511000e-01
## Education_Level_Unknown        -0.134369635 -0.4035127644  5.402949e-01
## Marital_Status_Divorced         0.217180866 -0.1681771923 -4.059675e-01
## Marital_Status_Married         -0.105266686  0.0249520173  1.334302e-01
## Marital_Status_Single          -0.091623344  0.0768742408  1.710238e-01
## Marital_Status_Unknown          0.154221170 -0.0226955219 -1.671455e-01
## Income_Category_$40K - $60K     0.108071982 -0.1284467039  1.743917e-01
## Income_Category_$60K - $80K    -0.440442868 -0.0231697758 -3.730729e-01
## Income_Category_$80K - $120K    0.227239778  0.0498123505  1.830153e-01
## Income_Category_$120K +         0.188203522  0.0022667258  1.177377e-01
## Income_Category_Less than $40K -0.230667615 -0.0495692381 -6.830731e-02
## Income_Category_Unknown         0.290916777  0.1990088092 -3.473403e-03
## Card_Category_Blue              0.140714586  0.0456475063  6.310396e-02
## Card_Category_Gold             -0.063947660  0.0636351666  2.788938e-02
## Card_Category_Platinum          0.035229132 -0.0066209603  2.193321e-03
## Card_Category_Silver           -0.132865947 -0.0790316257 -8.337767e-02
##                                        PC13         PC14          PC15
## Customer_Age                   -0.061163984  0.063176059  0.0064948431
## Dependent_count                -0.026389358  0.116420168  0.0016736072
## Months_on_book                 -0.078965996  0.062895401  0.0028303063
## Total_Relationship_Count       -0.022549609  0.047412293  0.0487814012
## Months_Inactive_12_mon         -0.011089981 -0.026357799 -0.0495525093
## Contacts_Count_12_mon           0.074693689 -0.100881187  0.0724740773
## Credit_Limit                    0.044046467  0.016109699 -0.0071859771
## Total_Revolving_Bal             0.153593279  0.070310645 -0.1033196081
## Avg_Open_To_Buy                 0.030267456  0.009802910  0.0020782186
## Total_Amt_Chng_Q4_Q1           -0.075680809 -0.021373231  0.0510257380
## Total_Trans_Amt                 0.017618170 -0.048788365  0.0259664638
## Total_Trans_Ct                  0.016129173 -0.027736366  0.0052639284
## Total_Ct_Chng_Q4_Q1            -0.098040486  0.010668876  0.0567337499
## Avg_Utilization_Ratio           0.086800353  0.025473868 -0.0662771727
## Gender_F                        0.001589306  0.020910812 -0.0004545378
## Gender_M                       -0.001589306 -0.020910812  0.0004545378
## Education_Level_College        -0.316110988 -0.138549707 -0.7430049560
## Education_Level_Doctorate       0.136610188  0.068790444 -0.2285129758
## Education_Level_Graduate        0.056504862  0.042640927  0.0662496412
## Education_Level_High School    -0.126385707  0.005381515  0.1905506292
## Education_Level_Post-Graduate  -0.073813589  0.023485936 -0.0374425208
## Education_Level_Uneducated      0.171165227 -0.411251305  0.3207080577
## Education_Level_Unknown         0.130636883  0.408679029  0.1628156043
## Marital_Status_Divorced        -0.111981873  0.270098061 -0.0798117535
## Marital_Status_Married          0.133768025 -0.204663293 -0.0275176301
## Marital_Status_Single           0.123027511 -0.210766377 -0.0596786780
## Marital_Status_Unknown         -0.372168811  0.512694944  0.2433819710
## Income_Category_$40K - $60K    -0.125992271 -0.137852787  0.1527616458
## Income_Category_$60K - $80K     0.288212031  0.255853247 -0.1892007085
## Income_Category_$80K - $120K   -0.463352798 -0.165797095  0.0468355335
## Income_Category_$120K +         0.334388218 -0.023627185  0.0771084498
## Income_Category_Less than $40K -0.116041471 -0.071192617  0.0617878484
## Income_Category_Unknown         0.267954392  0.203973168 -0.1891345923
## Card_Category_Blue              0.040171121  0.009809729  0.0064236817
## Card_Category_Gold              0.080244792  0.065038445 -0.1153709541
## Card_Category_Platinum          0.166425328  0.062287897 -0.0058996636
## Card_Category_Silver           -0.114485430 -0.053426125  0.0479749451
##                                        PC16          PC17         PC18
## Customer_Age                    0.009436493  0.0046260131  0.014744864
## Dependent_count                 0.055360500  0.1146010390  0.154788127
## Months_on_book                  0.003837683  0.0001919797  0.012622455
## Total_Relationship_Count       -0.041637320 -0.0408216142  0.016862859
## Months_Inactive_12_mon          0.051869876  0.0824836888 -0.014483388
## Contacts_Count_12_mon          -0.005302043  0.0407699668 -0.027262253
## Credit_Limit                   -0.035246631 -0.0090690595  0.008332373
## Total_Revolving_Bal             0.082337506  0.0314775853 -0.043426637
## Avg_Open_To_Buy                -0.042620855 -0.0118891465  0.012223857
## Total_Amt_Chng_Q4_Q1           -0.114400317 -0.0377113911  0.058518589
## Total_Trans_Amt                 0.005331819 -0.0250995871 -0.038653751
## Total_Trans_Ct                 -0.006877850 -0.0187466983 -0.034472390
## Total_Ct_Chng_Q4_Q1            -0.085508181  0.0072578249  0.063946518
## Avg_Utilization_Ratio           0.057254894  0.0230179777 -0.018297788
## Gender_F                        0.001036912  0.0091368264  0.008978226
## Gender_M                       -0.001036912 -0.0091368264 -0.008978226
## Education_Level_College        -0.176478050  0.2811322063  0.073969070
## Education_Level_Doctorate       0.078759206 -0.3233753320  0.141512911
## Education_Level_Graduate       -0.060667954  0.0573014053 -0.037206940
## Education_Level_High School    -0.130376033 -0.0114860519 -0.114380679
## Education_Level_Post-Graduate   0.142026280 -0.6208536012  0.475490015
## Education_Level_Uneducated      0.170822496  0.2232478403  0.024520732
## Education_Level_Unknown         0.070215927  0.0503370409 -0.285064713
## Marital_Status_Divorced        -0.378507416 -0.3371320083 -0.484402888
## Marital_Status_Married          0.082503901  0.0075712712 -0.008370833
## Marital_Status_Single           0.086885500  0.0031526986  0.043437903
## Marital_Status_Unknown          0.059202335  0.3166257032  0.419121584
## Income_Category_$40K - $60K    -0.176092973  0.0317640687  0.051307221
## Income_Category_$60K - $80K     0.210520849  0.0897480023 -0.016855971
## Income_Category_$80K - $120K    0.325132497 -0.1189858661 -0.180565700
## Income_Category_$120K +        -0.612244381  0.0332329831  0.246594426
## Income_Category_Less than $40K -0.126658973 -0.0716059210  0.045418353
## Income_Category_Unknown         0.308307390  0.0805019013 -0.109834498
## Card_Category_Blue             -0.056252178 -0.0156373224  0.018349150
## Card_Category_Gold             -0.062146510  0.2343788364  0.163351732
## Card_Category_Platinum          0.073561700 -0.1988542231  0.211928028
## Card_Category_Silver            0.077026353 -0.0534683834 -0.138041607
##                                        PC19         PC20          PC21
## Customer_Age                    0.017839119 -0.007356427 -0.0655883337
## Dependent_count                -0.058970425  0.074815354 -0.5079683342
## Months_on_book                  0.021953939  0.015122347 -0.0684529664
## Total_Relationship_Count        0.013482133 -0.018687486 -0.1058093787
## Months_Inactive_12_mon          0.110595550  0.277638094  0.2158482520
## Contacts_Count_12_mon           0.065626205  0.146390167  0.5203790465
## Credit_Limit                    0.029909019  0.004536405 -0.0190005846
## Total_Revolving_Bal             0.032376866 -0.017011422  0.0318339084
## Avg_Open_To_Buy                 0.027000127  0.006060540 -0.0218505310
## Total_Amt_Chng_Q4_Q1           -0.023550215  0.084626380  0.1340621474
## Total_Trans_Amt                 0.020907382 -0.006301436  0.0946399533
## Total_Trans_Ct                  0.017355748 -0.024749760  0.0294383735
## Total_Ct_Chng_Q4_Q1            -0.058632129  0.041378237 -0.0209592084
## Avg_Utilization_Ratio           0.001294720 -0.003687047  0.0358501172
## Gender_F                        0.022388941  0.016355059 -0.0360462392
## Gender_M                       -0.022388941 -0.016355059  0.0360462392
## Education_Level_College         0.112951731 -0.171014835  0.0957997392
## Education_Level_Doctorate      -0.834392611  0.115103181  0.0619659894
## Education_Level_Graduate        0.022962014 -0.006898671 -0.0159230533
## Education_Level_High School     0.029925479 -0.011723531  0.0108438741
## Education_Level_Post-Graduate   0.431635241  0.069397212 -0.1529273384
## Education_Level_Uneducated     -0.013896247  0.035752198 -0.0421521071
## Education_Level_Unknown         0.071911693  0.021057918  0.0281508297
## Marital_Status_Divorced         0.072306962  0.184913173 -0.0007937136
## Marital_Status_Married          0.009071313 -0.009299559 -0.0133691503
## Marital_Status_Single           0.011678124 -0.020447851 -0.0848604860
## Marital_Status_Unknown         -0.111303917 -0.128983813  0.1843741114
## Income_Category_$40K - $60K    -0.080570568  0.100573644  0.0059548893
## Income_Category_$60K - $80K     0.066297259 -0.061665088 -0.0584517467
## Income_Category_$80K - $120K   -0.053735148  0.134427472  0.0434374965
## Income_Category_$120K +         0.001943384 -0.175477924 -0.0377880933
## Income_Category_Less than $40K -0.029349186  0.007605949  0.0248822493
## Income_Category_Unknown         0.129922247 -0.075514161  0.0006786573
## Card_Category_Blue              0.032977612 -0.026253661 -0.0132296939
## Card_Category_Gold              0.051975261  0.778517841 -0.0648669859
## Card_Category_Platinum          0.095282505 -0.092621087  0.5240837791
## Card_Category_Silver           -0.079421413 -0.316836679 -0.0572455070
##                                         PC22         PC23          PC24
## Customer_Age                   -0.0635120941 -0.010646478  0.1024420656
## Dependent_count                 0.0200129806 -0.505646941  0.5719209556
## Months_on_book                 -0.0427591174 -0.026572200  0.1239861759
## Total_Relationship_Count       -0.0365115735  0.030682392 -0.1217489426
## Months_Inactive_12_mon          0.7809691560 -0.401650465 -0.2026134929
## Contacts_Count_12_mon           0.0921055343  0.274494668  0.7165355288
## Credit_Limit                    0.0011512860  0.004717453 -0.0022020304
## Total_Revolving_Bal             0.0515680517  0.026597577  0.0461699403
## Avg_Open_To_Buy                -0.0034720736  0.002331968 -0.0063407408
## Total_Amt_Chng_Q4_Q1            0.0591480451 -0.017335674  0.0971976407
## Total_Trans_Amt                 0.0575260139  0.102080591  0.0529468968
## Total_Trans_Ct                  0.0509677727  0.082037901  0.0334475666
## Total_Ct_Chng_Q4_Q1             0.0516100296 -0.087256174  0.0987317233
## Avg_Utilization_Ratio           0.0454243011 -0.007964092  0.0236114964
## Gender_F                       -0.0153108649 -0.014645755  0.0291509344
## Gender_M                        0.0153108649  0.014645755 -0.0291509344
## Education_Level_College        -0.0518197633 -0.020232043  0.0339583145
## Education_Level_Doctorate       0.0949800591  0.052175125  0.0078561779
## Education_Level_Graduate       -0.0075923961  0.005373742 -0.0001288012
## Education_Level_High School    -0.0234451057 -0.093441864  0.0218381184
## Education_Level_Post-Graduate   0.1389208791  0.190469428  0.0328137326
## Education_Level_Uneducated     -0.0915630923 -0.008386306 -0.0520310712
## Education_Level_Unknown         0.0299075626 -0.024647130 -0.0259471307
## Marital_Status_Divorced        -0.0776791592 -0.065570087  0.0558229027
## Marital_Status_Married          0.0131178217  0.011870066 -0.0271034675
## Marital_Status_Single           0.0009131781 -0.052776874  0.0331149200
## Marital_Status_Unknown          0.0509373523  0.141246611 -0.0658485167
## Income_Category_$40K - $60K    -0.0191400679 -0.107852750 -0.0234909204
## Income_Category_$60K - $80K    -0.0263249858  0.009106933  0.0665576208
## Income_Category_$80K - $120K   -0.0720407582 -0.031990320 -0.0157525933
## Income_Category_$120K +         0.1488695158  0.039554606 -0.0261164055
## Income_Category_Less than $40K -0.0334813027  0.006286889  0.0057202115
## Income_Category_Unknown         0.0632829483  0.115964878 -0.0139656819
## Card_Category_Blue              0.0184858720  0.035518394  0.0295226752
## Card_Category_Gold             -0.2379112293  0.136589919 -0.1383986467
## Card_Category_Platinum         -0.4312532374 -0.596399052 -0.0795837952
## Card_Category_Silver            0.1748757390  0.013125450  0.0475240334
##                                         PC25          PC26         PC27
## Customer_Age                   -0.0204351527  0.0233675064 -0.018369091
## Dependent_count                -0.0669788538  0.1036475314 -0.073862975
## Months_on_book                 -0.0366332380  0.0551419417 -0.015721295
## Total_Relationship_Count       -0.8595542301  0.0983712090  0.012247228
## Months_Inactive_12_mon         -0.0626953676 -0.0100011833  0.032628165
## Contacts_Count_12_mon          -0.1133172891 -0.0839821092 -0.008385573
## Credit_Limit                    0.0039256059 -0.0371181015  0.443276941
## Total_Revolving_Bal             0.0450753731  0.0044223470  0.250511060
## Avg_Open_To_Buy                -0.0001162621 -0.0375067752  0.420725351
## Total_Amt_Chng_Q4_Q1            0.1879939478  0.6726205077  0.031686498
## Total_Trans_Amt                -0.2186772541  0.0858158852  0.007445360
## Total_Trans_Ct                 -0.3587886997  0.0395023320 -0.049171353
## Total_Ct_Chng_Q4_Q1             0.0193112184 -0.7073090297 -0.062965780
## Avg_Utilization_Ratio           0.0301852735  0.0144075899 -0.122653345
## Gender_F                        0.0022939619 -0.0077918529  0.219078537
## Gender_M                       -0.0022939619  0.0077918529 -0.219078537
## Education_Level_College        -0.0514030788  0.0016143908  0.011132820
## Education_Level_Doctorate      -0.0335030226  0.0015129714  0.020449022
## Education_Level_Graduate        0.0171609325  0.0028502686  0.002270450
## Education_Level_High School    -0.0091883952  0.0006689748 -0.004009590
## Education_Level_Post-Graduate   0.0483801465 -0.0277039896 -0.019143581
## Education_Level_Uneducated      0.0310516158  0.0130128589 -0.003384217
## Education_Level_Unknown        -0.0099627834 -0.0025037360 -0.004480537
## Marital_Status_Divorced         0.0458682609 -0.0111046265 -0.040580692
## Marital_Status_Married         -0.0643513974 -0.0225223942  0.020842855
## Marital_Status_Single           0.0309011170  0.0213273882 -0.002536524
## Marital_Status_Unknown          0.0191911399  0.0142719735  0.005570973
## Income_Category_$40K - $60K    -0.0312638370 -0.0186732490  0.209963928
## Income_Category_$60K - $80K    -0.0073987912 -0.0092679589  0.209332420
## Income_Category_$80K - $120K   -0.0087083205  0.0138837268 -0.129221741
## Income_Category_$120K +         0.0241946636  0.0108523102 -0.274286150
## Income_Category_Less than $40K  0.0125864991 -0.0077806924  0.105333142
## Income_Category_Unknown         0.0171079374  0.0200189219 -0.273598935
## Card_Category_Blue             -0.0103199890 -0.0098764714  0.288894786
## Card_Category_Gold             -0.0080312103 -0.0058678082 -0.170765294
## Card_Category_Platinum         -0.0683504772 -0.0148153613 -0.073944557
## Card_Category_Silver            0.0285207852  0.0165751479 -0.225791406
##                                         PC28          PC29          PC30
## Customer_Age                    1.445410e-01 -0.6355155995  2.615395e-01
## Dependent_count                -6.476359e-02 -0.0260860527  3.226946e-02
## Months_on_book                 -1.656818e-01  0.6364612109 -2.343061e-01
## Total_Relationship_Count       -2.977542e-02 -0.0391477751 -2.596917e-02
## Months_Inactive_12_mon          3.588938e-03 -0.0196577624 -5.034916e-03
## Contacts_Count_12_mon           2.473470e-02  0.0015697110  3.087043e-03
## Credit_Limit                    1.866537e-02  0.0797214793  2.068137e-01
## Total_Revolving_Bal            -2.833686e-01 -0.1886168103 -4.088080e-01
## Avg_Open_To_Buy                 4.406568e-02  0.0966143915  2.434203e-01
## Total_Amt_Chng_Q4_Q1            1.955655e-02 -0.0020066827  1.947556e-02
## Total_Trans_Amt                -1.468859e-01 -0.1976948001 -1.408634e-01
## Total_Trans_Ct                  1.681964e-01  0.1836003210  1.512690e-01
## Total_Ct_Chng_Q4_Q1            -1.341042e-02 -0.0025419594 -1.695475e-02
## Avg_Utilization_Ratio           3.421800e-01  0.2504618557  5.313303e-01
## Gender_F                        3.252925e-01 -0.0077437800 -2.105569e-01
## Gender_M                       -3.252925e-01  0.0077437800  2.105569e-01
## Education_Level_College        -7.878981e-03 -0.0062368678  2.840905e-03
## Education_Level_Doctorate      -2.025649e-03 -0.0004670800  8.626003e-05
## Education_Level_Graduate        4.313880e-03 -0.0020435177 -2.336165e-03
## Education_Level_High School     2.297664e-03  0.0005813492  4.924471e-03
## Education_Level_Post-Graduate   1.901083e-03 -0.0031950825 -5.391779e-04
## Education_Level_Uneducated      1.852245e-03  0.0023957380 -6.210991e-03
## Education_Level_Unknown        -3.365971e-03  0.0070980352  1.570699e-03
## Marital_Status_Divorced         4.772085e-03 -0.0120571068  5.712439e-04
## Marital_Status_Married          9.264557e-05  0.0166336837  1.343018e-02
## Marital_Status_Single          -5.034506e-03 -0.0117525636 -1.411913e-02
## Marital_Status_Unknown          4.434467e-03  0.0022554545  1.476420e-04
## Income_Category_$40K - $60K    -7.054356e-02  0.0040842006  7.252694e-02
## Income_Category_$60K - $80K     3.032757e-01  0.0087968907 -1.507979e-01
## Income_Category_$80K - $120K    3.349033e-01 -0.0088669199 -2.152424e-01
## Income_Category_$120K +         2.495079e-01 -0.0117007061 -1.974813e-01
## Income_Category_Less than $40K -3.927259e-01 -0.0028712229  2.152282e-01
## Income_Category_Unknown        -2.393050e-01  0.0095155348  1.593219e-01
## Card_Category_Blue             -2.416119e-02  0.0141091152  5.418619e-02
## Card_Category_Gold              7.107344e-03 -0.0112720742 -2.666170e-02
## Card_Category_Platinum          1.134564e-03 -0.0005754741 -1.900828e-02
## Card_Category_Silver            2.322294e-02 -0.0102485204 -4.385746e-02
##                                         PC31          PC32          PC33
## Customer_Age                   -0.0987750530 -9.835442e-16  0.000000e+00
## Dependent_count                 0.0151794297  1.799684e-16  1.538879e-16
## Months_on_book                  0.0913927754  9.473709e-17 -3.153204e-16
## Total_Relationship_Count        0.0841916368 -2.278656e-16 -9.234225e-17
## Months_Inactive_12_mon         -0.0106667566  1.616785e-16 -5.829859e-17
## Contacts_Count_12_mon          -0.0241074922 -1.136391e-16  3.232837e-18
## Credit_Limit                    0.0442614425 -2.275309e-02  6.511029e-02
## Total_Revolving_Bal            -0.2278670827  2.040262e-03 -5.838416e-03
## Avg_Open_To_Buy                 0.0646806187  2.275787e-02 -6.512396e-02
## Total_Amt_Chng_Q4_Q1           -0.0419554121  3.471735e-16  4.039525e-16
## Total_Trans_Amt                 0.6575921876  1.908735e-16 -5.130727e-16
## Total_Trans_Ct                 -0.6190960363 -7.491127e-16  5.624206e-16
## Total_Ct_Chng_Q4_Q1             0.0265892400  5.895447e-17 -4.922604e-17
## Avg_Utilization_Ratio           0.2972450231 -2.232494e-16  2.104148e-16
## Gender_F                        0.0395933681 -5.742222e-03  8.143242e-03
## Gender_M                       -0.0395933681 -5.742222e-03  8.143242e-03
## Education_Level_College         0.0125293675 -1.942735e-02  5.260492e-02
## Education_Level_Doctorate       0.0015230198 -1.335643e-02  3.616624e-02
## Education_Level_Graduate       -0.0017171667 -2.991615e-02  8.100625e-02
## Education_Level_High School     0.0003882791 -2.584007e-02  6.996914e-02
## Education_Level_Post-Graduate  -0.0055983669 -1.423847e-02  3.855461e-02
## Education_Level_Uneducated     -0.0041144862 -2.291747e-02  6.205539e-02
## Education_Level_Unknown        -0.0020939113 -2.311981e-02  6.260329e-02
## Marital_Status_Divorced         0.0071782566 -2.745413e-01 -1.836317e-01
## Marital_Status_Married         -0.0226423944 -5.233902e-01 -3.500786e-01
## Marital_Status_Single           0.0185362598 -5.118312e-01 -3.423472e-01
## Marital_Status_Unknown          0.0014292971 -2.747101e-01 -1.837446e-01
## Income_Category_$40K - $60K    -0.0079783205  2.360289e-01 -3.342751e-01
## Income_Category_$60K - $80K     0.0288883971  2.136931e-01 -3.026421e-01
## Income_Category_$80K - $120K    0.0224204022  2.218887e-01 -3.142490e-01
## Income_Category_$120K +         0.0246681275  1.597221e-01 -2.262058e-01
## Income_Category_Less than $40K -0.0490032017  2.954406e-01 -4.184167e-01
## Income_Category_Unknown         0.0065780371  1.934501e-01 -2.739730e-01
## Card_Category_Blue              0.0164132467 -6.262752e-02  1.662485e-01
## Card_Category_Gold             -0.0084468490 -2.643017e-02  7.016048e-02
## Card_Category_Platinum         -0.0082165822 -1.102703e-02  2.927190e-02
## Card_Category_Silver           -0.0126315772 -5.653014e-02  1.500627e-01
##                                         PC34          PC35          PC36
## Customer_Age                    0.000000e+00  0.000000e+00  0.000000e+00
## Dependent_count                -2.480264e-16 -1.191855e-16 -2.143204e-16
## Months_on_book                  1.061491e-16  5.956080e-17 -7.922438e-18
## Total_Relationship_Count        3.528702e-17 -1.381530e-16 -3.714609e-17
## Months_Inactive_12_mon         -5.262477e-17 -1.598883e-16  1.316486e-16
## Contacts_Count_12_mon           6.862563e-17  1.173288e-16 -5.213234e-17
## Credit_Limit                    6.020853e-02  6.210231e-01 -2.713703e-01
## Total_Revolving_Bal            -5.398878e-03 -5.568692e-02  2.433368e-02
## Avg_Open_To_Buy                -6.022118e-02 -6.211535e-01  2.714273e-01
## Total_Amt_Chng_Q4_Q1           -2.124368e-16 -1.565931e-16 -1.700961e-17
## Total_Trans_Amt                -3.540520e-16  1.912286e-16  2.482142e-16
## Total_Trans_Ct                  6.892297e-17  2.659650e-17 -1.591570e-16
## Total_Ct_Chng_Q4_Q1             3.102295e-17  2.024023e-17  5.042840e-17
## Avg_Utilization_Ratio          -3.302595e-16  2.472077e-16 -3.264259e-16
## Gender_F                       -1.267843e-02 -1.170858e-01  1.653820e-01
## Gender_M                       -1.267843e-02 -1.170858e-01  1.653820e-01
## Education_Level_College         1.135369e-02  1.357383e-01  2.957994e-01
## Education_Level_Doctorate       7.805739e-03  9.332097e-02  2.033641e-01
## Education_Level_Graduate        1.748353e-02  2.090232e-01  4.555010e-01
## Education_Level_High School     1.510140e-02  1.805437e-01  3.934390e-01
## Education_Level_Post-Graduate   8.321219e-03  9.948376e-02  2.167939e-01
## Education_Level_Uneducated      1.339338e-02  1.601236e-01  3.489397e-01
## Education_Level_Unknown         1.351163e-02  1.615374e-01  3.520206e-01
## Marital_Status_Divorced        -1.917182e-02  1.480013e-02  8.568116e-03
## Marital_Status_Married         -3.654949e-02  2.821522e-02  1.633440e-02
## Marital_Status_Single          -3.574230e-02  2.759209e-02  1.597366e-02
## Marital_Status_Unknown         -1.918361e-02  1.480923e-02  8.573384e-03
## Income_Category_$40K - $60K    -1.015261e-01  7.238445e-02  4.651016e-02
## Income_Category_$60K - $80K    -9.191852e-02  6.553459e-02  4.210883e-02
## Income_Category_$80K - $120K   -9.544378e-02  6.804797e-02  4.372379e-02
## Income_Category_$120K +        -6.870328e-02  4.898296e-02  3.147368e-02
## Income_Category_Less than $40K -1.270816e-01  9.060461e-02  5.821741e-02
## Income_Category_Unknown        -8.321116e-02  5.932655e-02  3.811989e-02
## Card_Category_Blue             -6.786905e-01  3.611279e-02 -2.469439e-02
## Card_Category_Gold             -2.864221e-01  1.524038e-02 -1.042157e-02
## Card_Category_Platinum         -1.194992e-01  6.358492e-03 -4.348018e-03
## Card_Category_Silver           -6.126136e-01  3.259687e-02 -2.229015e-02
##                                         PC37
## Customer_Age                    0.000000e+00
## Dependent_count                -1.870400e-17
## Months_on_book                 -1.284589e-17
## Total_Relationship_Count        2.121911e-16
## Months_Inactive_12_mon         -4.156710e-17
## Contacts_Count_12_mon          -3.473322e-17
## Credit_Limit                   -1.737817e-01
## Total_Revolving_Bal             1.558294e-02
## Avg_Open_To_Buy                 1.738182e-01
## Total_Amt_Chng_Q4_Q1            1.883076e-16
## Total_Trans_Amt                 4.385981e-17
## Total_Trans_Ct                 -1.897359e-16
## Total_Ct_Chng_Q4_Q1            -4.768376e-17
## Avg_Utilization_Ratio          -1.023139e-16
## Gender_F                       -6.772589e-01
## Gender_M                       -6.772589e-01
## Education_Level_College         4.935020e-02
## Education_Level_Doctorate       3.392860e-02
## Education_Level_Graduate        7.599431e-02
## Education_Level_High School     6.564008e-02
## Education_Level_Post-Graduate   3.616920e-02
## Education_Level_Uneducated      5.821596e-02
## Education_Level_Unknown         5.872996e-02
## Marital_Status_Divorced         1.227884e-05
## Marital_Status_Married          2.340859e-05
## Marital_Status_Single           2.289162e-05
## Marital_Status_Unknown          1.228639e-05
## Income_Category_$40K - $60K    -5.276363e-03
## Income_Category_$60K - $80K    -4.777052e-03
## Income_Category_$80K - $120K   -4.960262e-03
## Income_Category_$120K +        -3.570544e-03
## Income_Category_Less than $40K -6.604496e-03
## Income_Category_Unknown        -4.324526e-03
## Card_Category_Blue              2.961726e-03
## Card_Category_Gold              1.249913e-03
## Card_Category_Platinum          5.214805e-04
## Card_Category_Silver            2.673374e-03
head(pr_churn$x)
##             PC1        PC2       PC3       PC4       PC5        PC6        PC7
## [1,]  1.4991047  2.3816917 1.2061287 0.8965607 1.5324615 -0.7452821 -2.9891210
## [2,] -1.3634485 -0.6525061 1.5190587 1.4605792 0.9063029 -3.5810956 -4.9434915
## [3,]  0.9430949  2.2516219 2.3751092 2.2864274 2.4988199 -1.3576559 -4.4120845
## [4,] -2.5046912 -0.2083894 2.3492849 1.3856533 1.7282835 -3.1940012 -3.8275982
## [5,]  0.8411591  2.1366291 3.8216460 0.5588208 2.9101460 -1.3432339 -5.6052130
## [6,] -0.1145821  2.2172736 0.9176018 0.7205818 1.5060464 -0.7306351  0.3933491
##           PC8        PC9       PC10       PC11       PC12        PC13
## [1,] 1.567650  0.5894549 -3.4650349  1.0845553 -0.9353536  0.03695702
## [2,] 8.011098 -0.1858311 -4.0692093 -1.0322340  0.3241670 -1.75684897
## [3,] 7.613060  0.4016536 -3.8732515 -1.0277678  0.8400688 -2.83108730
## [4,] 2.319265 -0.8169938 -1.2438990  1.0305130 -1.0588062 -2.66128310
## [5,] 5.198788  0.7194805 -4.8022156 -2.3977562 -1.9266328 -0.03912897
## [6,] 1.869738  2.3727741 -0.6822284 -0.3334129  0.7702467 -0.28100631
##            PC14      PC15       PC16         PC17      PC18       PC19
## [1,]  0.5662105 0.4140922 -0.4327398  0.068779578 0.2660919 -0.1957914
## [2,]  0.2698623 1.1873703 -1.8234877  0.007137635 1.6569228 -1.0645323
## [3,] -0.4653215 1.1153690 -0.8125954 -0.648642503 0.6624920 -1.1526232
## [4,]  2.4200909 1.5256875 -0.8660267  1.375442440 2.2290439 -0.8703956
## [5,] -0.6327165 1.1519419 -0.3991568  0.492429597 1.1702627 -0.9454862
## [6,] -0.5265218 0.6013645 -0.8558381  0.015422879 0.2995518 -0.5281009
##             PC20         PC21       PC22        PC23       PC24      PC25
## [1,] -0.10791987 -0.367440380 -0.8836780 -0.24567744  1.5008726 0.2390350
## [2,]  0.56404982 -1.931416490 -0.5501501 -2.04357111  2.7475257 0.4437751
## [3,]  0.70139821 -0.802962463 -0.8229375 -1.32181396  0.1654824 2.5271509
## [4,]  0.42961227  0.128351692  1.8633014 -2.20794121  0.2604017 2.2280835
## [5,]  0.09595182 -1.324047088 -0.8745157 -1.18859514 -0.3194066 1.7258709
## [6,]  0.05399539  0.007003597 -0.9675322  0.02289997 -0.0740152 1.8153898
##            PC26        PC27         PC28        PC29       PC30         PC31
## [1,] -1.0546456  0.47296426 -0.004411802  0.38876167 -0.1271152 -0.004201762
## [2,] -6.1827731 -0.10603680 -0.758221526  0.10725396 -0.5180684  0.583206267
## [3,]  0.9837203 -1.48617141  0.194312158 -0.64272935 -0.2934515  0.480992995
## [4,] -2.7440947  0.12634688 -0.419938441  0.11856959 -0.3122945  0.732234493
## [5,] -0.9296224 -0.47207806  0.293953216 -0.77778703  0.0332695  0.208334166
## [6,]  1.2708393 -0.07502082 -0.948163483  0.09269952  0.2923200  0.166142469
##               PC32          PC33          PC34          PC35          PC36
## [1,] -4.803438e-15  2.840301e-15 -1.899910e-15 -1.213371e-15 -1.353816e-15
## [2,]  5.993481e-15  2.632135e-15 -1.261532e-15  3.563024e-17  9.568352e-16
## [3,]  1.524833e-15 -2.683230e-16 -9.839758e-16  6.046195e-16  1.768686e-15
## [4,]  9.046594e-15  2.743157e-15 -1.513085e-16 -7.137703e-16 -6.807438e-16
## [5,] -2.138903e-15  4.394614e-15 -1.483576e-15 -1.712971e-15 -2.186484e-15
## [6,] -5.290797e-16 -1.045479e-15 -1.317043e-15  1.506676e-15  1.171941e-15
##              PC37
## [1,] 4.519022e-16
## [2,] 1.357428e-15
## [3,] 1.431154e-15
## [4,] 1.136311e-16
## [5,] 3.165938e-16
## [6,] 8.578275e-16
Looking at the principal components side by side, we can see in PC2 our findings from the plot are verified with total transaction amount and total transaction count as the most significant variables.
rownames_to_column(as.data.frame(pr_churn$rotation)) %>% 
  select(1:5) %>% 
  filter(abs(PC1) >= 0.25 | abs(PC2) >= 0.25 | abs(PC3) >= 0.25 | abs(PC4) >= 0.25)
##                           rowname          PC1         PC2          PC3
## 1                    Customer_Age -0.010813997  0.07575479 -0.433019360
## 2                  Months_on_book -0.005699747  0.07134628 -0.427853027
## 3                    Credit_Limit  0.413014059 -0.11846478 -0.115635228
## 4             Total_Revolving_Bal -0.034971577 -0.00101243  0.216509638
## 5                 Avg_Open_To_Buy  0.416062573 -0.11834914 -0.135021215
## 6                 Total_Trans_Amt  0.100869534 -0.36992793  0.289883802
## 7                  Total_Trans_Ct  0.044317988 -0.38057169  0.303259402
## 8           Avg_Utilization_Ratio -0.268875657  0.03487461  0.211170707
## 9                        Gender_F -0.355263483 -0.32165703 -0.190336830
## 10                       Gender_M  0.355263483  0.32165703  0.190336830
## 11         Marital_Status_Married -0.030806901  0.17389456 -0.049881916
## 12          Marital_Status_Single  0.017599981 -0.14781526  0.008531959
## 13 Income_Category_Less than $40K -0.284878123 -0.20900967 -0.089170360
## 14             Card_Category_Blue -0.257857151  0.35138834  0.159134939
## 15           Card_Category_Silver  0.223199987 -0.30357645 -0.153834541
##             PC4
## 1   0.443499234
## 2   0.439072869
## 3  -0.003755843
## 4   0.334555958
## 5  -0.033748268
## 6   0.262444253
## 7   0.225273171
## 8   0.257176086
## 9  -0.067697739
## 10  0.067697739
## 11  0.320106969
## 12 -0.266356421
## 13 -0.005177428
## 14 -0.022247279
## 15  0.005039861
Here we renamed and graphed the factors based on our findings in the prior table. From this we determined PC2 (or “modest users”) to show a slightly higher likelihood to churn. This made intuitive sense to us, because the less people use their credit cards, the less incentive they have to stay. Low usage will generally increase the likelihood to leave because, well… they don’t use it.
prc <- bind_cols(select(banko,Churn),as.data.frame(pr_churn$x)) %>% 
  select(1:5) %>% 
  rename("rich_dudes"=PC1, "modest_users"=PC2, "young_spenders"=PC3, "veterans"=PC4)


prc %>% 
  select(Churn, rich_dudes,modest_users) %>% 
  pivot_longer(cols = -Churn,names_to = "component",values_to = "loading") %>% 
  ggplot(aes(loading, fill=Churn))+
  geom_density(alpha=0.5)+
  facet_grid(.~component)

prc %>% 
  select(Churn, young_spenders, modest_users) %>% 
  pivot_longer(cols = -Churn,names_to = "component",values_to = "loading") %>% 
  ggplot(aes(loading, fill=Churn))+
  geom_density(alpha=0.5)+
    facet_grid(.~component)

Putting it all together

Here we are engineering the features that we previously discussed.
banko1 <- banko %>%
  select(Total_Trans_Amt, Total_Trans_Ct, Credit_Limit, `Income_Category_Less than $40K`, Marital_Status_Married, Churn)

names(banko1)[4] <- "LessThan40k"

Specification

Here is our final model. We were able to get a Kappa of 0.65 and an AUC of 95%
# specify the model to be used (i.e. KNN, Naive Bayes, decision tree, random forest, bagged trees) and the tuning parameters used


banko1$Churn <- as.factor(banko1$Churn)

ctrl <- trainControl(method = "cv", number = 3, classProbs=TRUE, summaryFunction = twoClassSummary)
set.seed(504) 

bank_index <- createDataPartition(banko1$Churn, p = 0.80, list = FALSE)
train <- banko1[ bank_index, ]
test <- banko1[-bank_index, ]

# example spec for rf
fit <- train(make.names(Churn) ~ .,
             data = train, 
             method = "rf",
             metric = "ROC",
             trControl = ctrl)

fit
## Random Forest 
## 
## 8102 samples
##    5 predictor
##    2 classes: 'FALSE.', 'TRUE.' 
## 
## No pre-processing
## Resampling: Cross-Validated (3 fold) 
## Summary of sample sizes: 5401, 5402, 5401 
## Resampling results across tuning parameters:
## 
##   mtry  ROC        Sens       Spec     
##   2     0.9458957  0.9579419  0.6582181
##   3     0.9450691  0.9525008  0.6705069
##   5     0.9425693  0.9508834  0.6628264
## 
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
confusionMatrix(predict(fit, test),factor(make.names(test$Churn)))
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction FALSE. TRUE.
##     FALSE.   1646   121
##     TRUE.      54   204
##                                           
##                Accuracy : 0.9136          
##                  95% CI : (0.9005, 0.9255)
##     No Information Rate : 0.8395          
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.6501          
##                                           
##  Mcnemar's Test P-Value : 6.065e-07       
##                                           
##             Sensitivity : 0.9682          
##             Specificity : 0.6277          
##          Pos Pred Value : 0.9315          
##          Neg Pred Value : 0.7907          
##              Prevalence : 0.8395          
##          Detection Rate : 0.8128          
##    Detection Prevalence : 0.8726          
##       Balanced Accuracy : 0.7980          
##                                           
##        'Positive' Class : FALSE.          
## 
myRoc <- roc(test$Churn, predict(fit, test, type="prob")[,2])

plot(myRoc)

auc(myRoc)
## Area under the curve: 0.9557