The word “Churn” means to move or to change. Churning in the telecom industry means customers changing the service providers. For example Before the service provider " Reliance Jio" people used to depend on the service providers like Airtel,Vodafone,Idea,Docomo etc. But After the starting of new service provider in the telecom industry named “Jio” as it initially provided free internet to the newly joined ones,people from the other network providers churned towards Jio. This is churning in telecom industry. This project is all about prediction of the possibilities of churning in the telecom industry.

step 1: Load the given Dataset.

library(knitr)
library(readr)
Churn <- read_csv("Churn.csv")
## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   `Day Mins` = col_double(),
##   `Eve Mins` = col_double(),
##   `Night Mins` = col_double(),
##   `Intl Mins` = col_double(),
##   `Day Charge` = col_double(),
##   `Eve Charge` = col_double(),
##   `Night Charge` = col_double(),
##   `Intl Charge` = col_double(),
##   State = col_character(),
##   Phone = col_character()
## )
## See spec(...) for full column specifications.

step 2: plot the sturcture of the dataset.

library(DataExplorer)
str(Churn)
## Classes 'tbl_df', 'tbl' and 'data.frame':    3333 obs. of  21 variables:
##  $ Account Length: int  128 107 137 84 75 118 121 147 117 141 ...
##  $ VMail Message : int  25 26 0 0 0 0 24 0 0 37 ...
##  $ Day Mins      : num  265 162 243 299 167 ...
##  $ Eve Mins      : num  197.4 195.5 121.2 61.9 148.3 ...
##  $ Night Mins    : num  245 254 163 197 187 ...
##  $ Intl Mins     : num  10 13.7 12.2 6.6 10.1 6.3 7.5 7.1 8.7 11.2 ...
##  $ CustServ Calls: int  1 1 0 2 3 0 3 0 1 0 ...
##  $ Churn         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Int'l Plan    : int  0 0 0 1 1 1 0 1 0 1 ...
##  $ VMail Plan    : int  1 1 0 0 0 0 1 0 0 1 ...
##  $ Day Calls     : int  110 123 114 71 113 98 88 79 97 84 ...
##  $ Day Charge    : num  45.1 27.5 41.4 50.9 28.3 ...
##  $ Eve Calls     : int  99 103 110 88 122 101 108 94 80 111 ...
##  $ Eve Charge    : num  16.78 16.62 10.3 5.26 12.61 ...
##  $ Night Calls   : int  91 103 104 89 121 118 118 96 90 97 ...
##  $ Night Charge  : num  11.01 11.45 7.32 8.86 8.41 ...
##  $ Intl Calls    : int  3 3 5 7 3 6 7 6 4 5 ...
##  $ Intl Charge   : num  2.7 3.7 3.29 1.78 2.73 1.7 2.03 1.92 2.35 3.02 ...
##  $ State         : chr  "KS" "OH" "NJ" "OH" ...
##  $ Area Code     : int  415 415 415 408 415 510 510 415 408 415 ...
##  $ Phone         : chr  "382-4657" "371-7191" "358-1921" "375-9999" ...
##  - attr(*, "spec")=List of 2
##   ..$ cols   :List of 21
##   .. ..$ Account Length: list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ VMail Message : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Day Mins      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Eve Mins      : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Night Mins    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Intl Mins     : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ CustServ Calls: list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Churn         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Int'l Plan    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ VMail Plan    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Day Calls     : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Day Charge    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Eve Calls     : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Eve Charge    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Night Calls   : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Night Charge  : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ Intl Calls    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Intl Charge   : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ State         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   .. ..$ Area Code     : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ Phone         : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   ..$ default: list()
##   .. ..- attr(*, "class")= chr  "collector_guess" "collector"
##   ..- attr(*, "class")= chr "col_spec"

Step 3: Find out the total number of churned customers in the given dataset for better understanding.

text(barplot(table(Churn$Churn),col=c('green','red'),main='Bar plot of Churn')
     ,0,table(Churn$Churn),cex=2,pos=3)

The above plot says that 483 customers have churned and 2850 customers have not churned. Now the main aim of this project is to find out the probability of the customers who will churn from 2850 existing customers.

Step 4:Check for the missing values.

anyNA(Churn)
## [1] FALSE

Fortunately there are no missing values.If present then we had to remove all the missing values.

Step 5: Plot the corelated variables.

library(corrplot)
corrplot(cor(Churn[sapply(Churn, is.numeric)]))

keep the highly correlated variables. correlation means how the variables are dependent on each other. Remove the non correlated variables.Then remove the unnecessary variables which are not required.

Churn$State <-NULL
Churn$Phone<-NULL
Churn$`Area Code`<-NULL
Churn$`Account Length`<-NULL
Churn$`VMail Message`<-NULL
Churn$`Day Mins`<-NULL
Churn$`Eve Mins`<-NULL
Churn$`Night Mins`<-NULL
Churn$`Intl Mins`<-NULL
Churn$`CustServ Calls`<-NULL
Churn$`Int'l Plan`<-NULL
Churn$`Day Calls`<-NULL
Churn$`Eve Calls`<-NULL
Churn$`Night Calls`<-NULL
Churn$`Intl Calls`<-NULL

The above variables are set to NULL means they are not required further.

Step 6: perform Logistic Regression. As this is the prediction problem we have to perform logistic regression.

library(caTools)
set.seed(101)
split<-sample.split(Churn,SplitRatio = 0.75)
split
## [1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE

In the above chunk of codes the dataset is split into two parts in the ratio 75% :25%

Whichever values are TRUE in the split, make it as a training dataset. and whichever values are FALSE make it as a testing dataset.

training<-subset(Churn,split=="TRUE")
testing<-subset(Churn,split=="FALSE")

Now create the model using glm function keeping Churn as the target variable in the training dataset.

model<-glm(Churn~.,training,family ="binomial")
summary(model)
## 
## Call:
## glm(formula = Churn ~ ., family = "binomial", data = training)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.0486  -0.6075  -0.4594  -0.3015   3.0245  
## 
## Coefficients:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)    -6.522755   0.528319 -12.346  < 2e-16 ***
## `VMail Plan`   -0.884941   0.166876  -5.303 1.14e-07 ***
## `Day Charge`    0.072218   0.007054  10.238  < 2e-16 ***
## `Eve Charge`    0.073121   0.014916   4.902 9.47e-07 ***
## `Night Charge`  0.053603   0.027041   1.982 0.047451 *  
## `Intl Charge`   0.306474   0.083973   3.650 0.000263 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1877.5  on 2221  degrees of freedom
## Residual deviance: 1692.4  on 2216  degrees of freedom
## AIC: 1704.4
## 
## Number of Fisher Scoring iterations: 5

optimize the model by removing independent variables. After removing the independent variables from the model make sure the residual deviance should not increase and AIC value should decrease.

Now predict the values for testing dataset and predict the accuracy of the model type=reponse means we want the probability of the testing dataset.

res<-predict(model,testing,type = "response")
res
##           1           2           3           4           5           6 
## 0.200918872 0.191265769 0.303435839 0.242278658 0.174106082 0.592439230 
##           7           8           9          10          11          12 
## 0.148235326 0.023586557 0.084947587 0.079832809 0.121672450 0.441144390 
##          13          14          15          16          17          18 
## 0.067707131 0.149773747 0.091311300 0.029282099 0.218868374 0.207840452 
##          19          20          21          22          23          24 
## 0.054969650 0.026967445 0.123522712 0.087897132 0.173694261 0.145032173 
##          25          26          27          28          29          30 
## 0.230826253 0.094243005 0.369180187 0.290812042 0.075754822 0.238105088 
##          31          32          33          34          35          36 
## 0.065506576 0.292110913 0.144838522 0.336888235 0.139995126 0.268929092 
##          37          38          39          40          41          42 
## 0.174814593 0.216867425 0.093883991 0.377777789 0.155015364 0.085438520 
##          43          44          45          46          47          48 
## 0.046937748 0.087263665 0.168943097 0.088709421 0.184211843 0.109428810 
##          49          50          51          52          53          54 
## 0.137973317 0.358038696 0.112466116 0.215005457 0.197885828 0.034507778 
##          55          56          57          58          59          60 
## 0.103606485 0.176451231 0.289765632 0.055007257 0.113593051 0.232951542 
##          61          62          63          64          65          66 
## 0.036151355 0.282276106 0.087787831 0.232684868 0.148959037 0.053364996 
##          67          68          69          70          71          72 
## 0.071716263 0.325666487 0.191487692 0.176257790 0.057212479 0.045490667 
##          73          74          75          76          77          78 
## 0.413078051 0.113342434 0.049188767 0.165394145 0.379226871 0.145874906 
##          79          80          81          82          83          84 
## 0.053622256 0.043782322 0.285503109 0.167456581 0.157177779 0.094448468 
##          85          86          87          88          89          90 
## 0.150536296 0.080136691 0.048780371 0.102777991 0.101656449 0.118161478 
##          91          92          93          94          95          96 
## 0.103935206 0.243566200 0.106818051 0.223708892 0.150362870 0.068710831 
##          97          98          99         100         101         102 
## 0.138353457 0.032485264 0.060026210 0.132565121 0.352036053 0.193149587 
##         103         104         105         106         107         108 
## 0.172688577 0.278952632 0.177629031 0.072296293 0.176153268 0.041533864 
##         109         110         111         112         113         114 
## 0.020955744 0.136700880 0.084659523 0.177634170 0.298458468 0.291096059 
##         115         116         117         118         119         120 
## 0.029577174 0.215099004 0.179462702 0.137101157 0.286039337 0.033978331 
##         121         122         123         124         125         126 
## 0.063247887 0.201598467 0.044224577 0.323973172 0.170024631 0.078649134 
##         127         128         129         130         131         132 
## 0.350093661 0.130090470 0.181233170 0.160552208 0.213595648 0.204989396 
##         133         134         135         136         137         138 
## 0.088901759 0.154432372 0.159880785 0.263229320 0.094127081 0.054403274 
##         139         140         141         142         143         144 
## 0.076121348 0.236222875 0.320988049 0.119958828 0.148950747 0.140134704 
##         145         146         147         148         149         150 
## 0.198477649 0.083537721 0.184897074 0.169834037 0.105997284 0.243700020 
##         151         152         153         154         155         156 
## 0.135258228 0.165188862 0.059048439 0.096686791 0.091053401 0.150740861 
##         157         158         159         160         161         162 
## 0.251118208 0.054991151 0.301711764 0.032280669 0.096217122 0.185793997 
##         163         164         165         166         167         168 
## 0.156290454 0.144672124 0.236898924 0.105967191 0.039187960 0.155473693 
##         169         170         171         172         173         174 
## 0.063756759 0.193873418 0.142708438 0.089760043 0.169959729 0.113284144 
##         175         176         177         178         179         180 
## 0.201475385 0.025727262 0.050608815 0.114808929 0.059104498 0.038090568 
##         181         182         183         184         185         186 
## 0.249134698 0.175839652 0.028065797 0.129275724 0.157757957 0.059231361 
##         187         188         189         190         191         192 
## 0.167860503 0.065812478 0.063315989 0.114169056 0.056305654 0.129074610 
##         193         194         195         196         197         198 
## 0.060725152 0.228852959 0.361161799 0.029501353 0.342044004 0.101501290 
##         199         200         201         202         203         204 
## 0.074725204 0.069513980 0.093212020 0.068004129 0.215614948 0.120362934 
##         205         206         207         208         209         210 
## 0.116665283 0.055869448 0.220754973 0.057635412 0.061920483 0.237857515 
##         211         212         213         214         215         216 
## 0.022750092 0.037975847 0.176400443 0.065428582 0.136822600 0.108091955 
##         217         218         219         220         221         222 
## 0.303460958 0.196607289 0.130795586 0.142669682 0.307766072 0.076355955 
##         223         224         225         226         227         228 
## 0.269887316 0.119450978 0.137116672 0.164848509 0.192294170 0.066591195 
##         229         230         231         232         233         234 
## 0.224204928 0.195205399 0.169673104 0.045153112 0.197633039 0.212128267 
##         235         236         237         238         239         240 
## 0.168878165 0.039076500 0.246903546 0.189869906 0.151516359 0.175743352 
##         241         242         243         244         245         246 
## 0.213971390 0.154240770 0.190792385 0.094655084 0.067536806 0.032966916 
##         247         248         249         250         251         252 
## 0.096917406 0.042770858 0.055094489 0.136403608 0.058043602 0.046256753 
##         253         254         255         256         257         258 
## 0.197435372 0.074565091 0.066305515 0.139193054 0.165003542 0.023363644 
##         259         260         261         262         263         264 
## 0.141491544 0.030559201 0.110817936 0.037749637 0.135596772 0.075907515 
##         265         266         267         268         269         270 
## 0.253642182 0.240074694 0.188583092 0.263059499 0.096407836 0.035380411 
##         271         272         273         274         275         276 
## 0.056154303 0.280054319 0.230090820 0.139931897 0.137821950 0.155066515 
##         277         278         279         280         281         282 
## 0.100632277 0.242678568 0.098595968 0.027495793 0.082841153 0.223238591 
##         283         284         285         286         287         288 
## 0.239339384 0.195759221 0.136663229 0.215459759 0.134194865 0.150613400 
##         289         290         291         292         293         294 
## 0.146105843 0.066404984 0.091027970 0.182913233 0.131626014 0.209902497 
##         295         296         297         298         299         300 
## 0.291059418 0.134798501 0.189286959 0.040541436 0.090223975 0.147381116 
##         301         302         303         304         305         306 
## 0.125875962 0.141659363 0.200580885 0.013099284 0.576002277 0.035591297 
##         307         308         309         310         311         312 
## 0.049359355 0.050109023 0.153907572 0.035161508 0.279580499 0.117155584 
##         313         314         315         316         317         318 
## 0.116085365 0.070390460 0.050429152 0.130758378 0.063653229 0.148387946 
##         319         320         321         322         323         324 
## 0.068660323 0.158958522 0.139679304 0.050183698 0.099573257 0.180184963 
##         325         326         327         328         329         330 
## 0.055458009 0.524254416 0.166411164 0.034612034 0.025130334 0.203172570 
##         331         332         333         334         335         336 
## 0.010398565 0.064128598 0.225388568 0.103011915 0.065191493 0.142396416 
##         337         338         339         340         341         342 
## 0.234803580 0.155462191 0.067047428 0.160155826 0.078734019 0.068117602 
##         343         344         345         346         347         348 
## 0.129416878 0.333161345 0.075268747 0.164015202 0.183948889 0.202286385 
##         349         350         351         352         353         354 
## 0.229280270 0.121275205 0.023471041 0.128136021 0.137378220 0.192950076 
##         355         356         357         358         359         360 
## 0.043610496 0.121581337 0.112619261 0.159496968 0.008860066 0.112822173 
##         361         362         363         364         365         366 
## 0.242123315 0.234681562 0.042236606 0.217182162 0.201850470 0.262128597 
##         367         368         369         370         371         372 
## 0.114276457 0.138760696 0.167007713 0.071295245 0.077216438 0.233621587 
##         373         374         375         376         377         378 
## 0.137915938 0.244615757 0.168350047 0.083302096 0.035238131 0.122612807 
##         379         380         381         382         383         384 
## 0.279481195 0.073950965 0.050728214 0.111806340 0.075285528 0.050427924 
##         385         386         387         388         389         390 
## 0.075721991 0.093740995 0.022103004 0.123839588 0.075312041 0.151608569 
##         391         392         393         394         395         396 
## 0.129540383 0.290168131 0.063270473 0.091322487 0.212392442 0.222229721 
##         397         398         399         400         401         402 
## 0.041888048 0.111682754 0.144497619 0.311761409 0.096424858 0.056057533 
##         403         404         405         406         407         408 
## 0.174088361 0.098071244 0.083652871 0.193657243 0.153616353 0.108946387 
##         409         410         411         412         413         414 
## 0.154125158 0.064218674 0.334823878 0.025726176 0.131111332 0.116446217 
##         415         416         417         418         419         420 
## 0.105059438 0.120765570 0.044996200 0.121144754 0.087265874 0.219715124 
##         421         422         423         424         425         426 
## 0.151833747 0.052100872 0.257213940 0.037021654 0.139570976 0.031022435 
##         427         428         429         430         431         432 
## 0.112648692 0.108094591 0.024814422 0.095185271 0.248977082 0.234209102 
##         433         434         435         436         437         438 
## 0.156250057 0.423381407 0.052694714 0.117189436 0.034339381 0.154649742 
##         439         440         441         442         443         444 
## 0.151526198 0.104485050 0.056331604 0.197552242 0.199504060 0.069187889 
##         445         446         447         448         449         450 
## 0.399892473 0.145855506 0.205849919 0.150527124 0.083975943 0.238218079 
##         451         452         453         454         455         456 
## 0.031864916 0.094739705 0.330314225 0.277570391 0.457377357 0.186861320 
##         457         458         459         460         461         462 
## 0.106576516 0.160282979 0.275225841 0.035477631 0.177307083 0.043456664 
##         463         464         465         466         467         468 
## 0.139186025 0.268453691 0.345082746 0.118739993 0.037309543 0.173103997 
##         469         470         471         472         473         474 
## 0.119130177 0.036468695 0.047263360 0.066988191 0.070815234 0.033468419 
##         475         476         477         478         479         480 
## 0.118808064 0.063175591 0.106983665 0.224566679 0.124313002 0.151299848 
##         481         482         483         484         485         486 
## 0.161231115 0.148693039 0.190671970 0.360080437 0.094323367 0.125166860 
##         487         488         489         490         491         492 
## 0.129180127 0.042337695 0.028985650 0.127498627 0.465648540 0.315513487 
##         493         494         495         496         497         498 
## 0.290959759 0.087216485 0.108985618 0.108773444 0.234545147 0.188013457 
##         499         500         501         502         503         504 
## 0.050655713 0.121147821 0.076667860 0.128847360 0.142947030 0.105960386 
##         505         506         507         508         509         510 
## 0.124755015 0.072468869 0.050303990 0.177085581 0.123310180 0.087613679 
##         511         512         513         514         515         516 
## 0.041559266 0.404433915 0.026916181 0.163996003 0.097432712 0.080824081 
##         517         518         519         520         521         522 
## 0.035590060 0.173012052 0.201664746 0.078897420 0.141080096 0.050893013 
##         523         524         525         526         527         528 
## 0.046240413 0.081729196 0.154555612 0.035049476 0.244919578 0.056525432 
##         529         530         531         532         533         534 
## 0.032007470 0.211329945 0.052520936 0.522022718 0.025656695 0.217936324 
##         535         536         537         538         539         540 
## 0.112313802 0.104510509 0.279876107 0.022131911 0.157170120 0.103178218 
##         541         542         543         544         545         546 
## 0.168854150 0.143904182 0.064485973 0.101487773 0.179371822 0.096099891 
##         547         548         549         550         551         552 
## 0.214630633 0.248406356 0.395326978 0.183283159 0.130424244 0.095430802 
##         553         554         555         556         557         558 
## 0.100651002 0.075393073 0.079377549 0.051135038 0.044131146 0.213871345 
##         559         560         561         562         563         564 
## 0.057253348 0.139496415 0.034874750 0.132152555 0.040034880 0.030410201 
##         565         566         567         568         569         570 
## 0.101490568 0.264774494 0.059282290 0.529139911 0.309269238 0.049555878 
##         571         572         573         574         575         576 
## 0.141489215 0.065822680 0.316537649 0.168551851 0.032005767 0.138894680 
##         577         578         579         580         581         582 
## 0.122257182 0.476114531 0.332533675 0.095475057 0.039973520 0.285288343 
##         583         584         585         586         587         588 
## 0.138719774 0.086080035 0.193813089 0.044462809 0.236679122 0.138908469 
##         589         590         591         592         593         594 
## 0.114764899 0.044277294 0.114276620 0.097846485 0.030188136 0.194257388 
##         595         596         597         598         599         600 
## 0.181688368 0.041627121 0.164472038 0.102088967 0.089245858 0.045496492 
##         601         602         603         604         605         606 
## 0.183950791 0.177136170 0.304741621 0.187843842 0.200804872 0.067748354 
##         607         608         609         610         611         612 
## 0.064250188 0.263638681 0.119813943 0.160196767 0.227770471 0.241238116 
##         613         614         615         616         617         618 
## 0.068889346 0.178835725 0.059177062 0.265917533 0.071450576 0.113282002 
##         619         620         621         622         623         624 
## 0.197912742 0.398319434 0.323734752 0.147046282 0.193732505 0.474605936 
##         625         626         627         628         629         630 
## 0.097079654 0.128071475 0.146603566 0.377523015 0.043665058 0.039006844 
##         631         632         633         634         635         636 
## 0.190725493 0.382485140 0.308911322 0.029071242 0.071997589 0.115398916 
##         637         638         639         640         641         642 
## 0.043773120 0.161744226 0.121145020 0.132101631 0.210994930 0.299256795 
##         643         644         645         646         647         648 
## 0.092685934 0.143112952 0.503601727 0.044916606 0.111587909 0.122529878 
##         649         650         651         652         653         654 
## 0.113754719 0.153949932 0.114566013 0.248821298 0.060136922 0.136515694 
##         655         656         657         658         659         660 
## 0.138413761 0.243984888 0.173516929 0.116799584 0.121076101 0.352196422 
##         661         662         663         664         665         666 
## 0.239059648 0.051024053 0.118097757 0.078456008 0.087211138 0.237129745 
##         667         668         669         670         671         672 
## 0.104098985 0.378424273 0.047537255 0.243438342 0.068820850 0.162369726 
##         673         674         675         676         677         678 
## 0.062945843 0.070793416 0.060507907 0.132819657 0.136205062 0.136777119 
##         679         680         681         682         683         684 
## 0.186900997 0.044656427 0.182334948 0.053282486 0.046736452 0.075843647 
##         685         686         687         688         689         690 
## 0.069488427 0.136933422 0.109218757 0.168600324 0.124126103 0.131547194 
##         691         692         693         694         695         696 
## 0.061482149 0.173758405 0.037485398 0.321569871 0.051171428 0.080867502 
##         697         698         699         700         701         702 
## 0.120442882 0.135013840 0.097701175 0.105966553 0.339148785 0.427786893 
##         703         704         705         706         707         708 
## 0.096433395 0.070440026 0.322422199 0.231431809 0.168903554 0.091835097 
##         709         710         711         712         713         714 
## 0.277509006 0.201010498 0.045194924 0.090104799 0.198855533 0.387277265 
##         715         716         717         718         719         720 
## 0.075798676 0.197405106 0.407052903 0.076749913 0.245262066 0.122133852 
##         721         722         723         724         725         726 
## 0.125368381 0.289152987 0.118160401 0.154281923 0.037086528 0.080701241 
##         727         728         729         730         731         732 
## 0.057421297 0.150448507 0.451893708 0.139443964 0.100277679 0.308714830 
##         733         734         735         736         737         738 
## 0.159233614 0.234782103 0.055360188 0.090118833 0.417578953 0.118221854 
##         739         740         741         742         743         744 
## 0.266566057 0.069774373 0.068919723 0.140599919 0.157509511 0.190959962 
##         745         746         747         748         749         750 
## 0.197273301 0.072743061 0.124094176 0.006073360 0.103142727 0.214490794 
##         751         752         753         754         755         756 
## 0.019157956 0.041932407 0.307859227 0.208202584 0.163695054 0.238172205 
##         757         758         759         760         761         762 
## 0.277550896 0.120326512 0.093876387 0.153260979 0.150735039 0.089973831 
##         763         764         765         766         767         768 
## 0.109789929 0.225249578 0.088809128 0.054987487 0.171605690 0.157781550 
##         769         770         771         772         773         774 
## 0.218417582 0.190149836 0.119057246 0.273970848 0.199264250 0.208751847 
##         775         776         777         778         779         780 
## 0.102824300 0.418295114 0.115872960 0.134846903 0.117061388 0.238766204 
##         781         782         783         784         785         786 
## 0.131074962 0.160478452 0.201316148 0.214926043 0.430280056 0.337034196 
##         787         788         789         790         791         792 
## 0.200027212 0.039514601 0.046212928 0.245984385 0.129751427 0.268843693 
##         793         794         795         796         797         798 
## 0.169518979 0.164654025 0.246585861 0.355751135 0.196703031 0.056486741 
##         799         800         801         802         803         804 
## 0.202051204 0.436353127 0.056559994 0.064657098 0.209412500 0.031754720 
##         805         806         807         808         809         810 
## 0.036712729 0.090703131 0.108124058 0.126400510 0.121323361 0.122482557 
##         811         812         813         814         815         816 
## 0.115707981 0.245503548 0.227521449 0.163757878 0.208841311 0.177880285 
##         817         818         819         820         821         822 
## 0.105151361 0.372336968 0.233770845 0.085217550 0.123458007 0.062112618 
##         823         824         825         826         827         828 
## 0.049307132 0.074394894 0.053781996 0.080508574 0.198018436 0.185093030 
##         829         830         831         832         833         834 
## 0.061704786 0.073028349 0.123885195 0.059668417 0.070575613 0.376661948 
##         835         836         837         838         839         840 
## 0.100468527 0.133418783 0.219868799 0.058820952 0.040389941 0.254635393 
##         841         842         843         844         845         846 
## 0.078201233 0.068178767 0.171409596 0.160590744 0.135463511 0.049925332 
##         847         848         849         850         851         852 
## 0.020084062 0.100821790 0.165867743 0.143918238 0.239561592 0.331319337 
##         853         854         855         856         857         858 
## 0.063068994 0.113685795 0.122213347 0.075366796 0.018483676 0.172284498 
##         859         860         861         862         863         864 
## 0.106374708 0.148278492 0.135858374 0.140410168 0.070448522 0.156977090 
##         865         866         867         868         869         870 
## 0.618484569 0.394824094 0.230497689 0.082398949 0.490310104 0.157538571 
##         871         872         873         874         875         876 
## 0.246291479 0.141824565 0.065222987 0.055843090 0.239881647 0.122524245 
##         877         878         879         880         881         882 
## 0.160868305 0.074210941 0.094487612 0.136569608 0.035782261 0.052138723 
##         883         884         885         886         887         888 
## 0.111268486 0.213441694 0.174393552 0.171226278 0.552423442 0.256965901 
##         889         890         891         892         893         894 
## 0.319072045 0.072415536 0.317917969 0.243736228 0.372194876 0.122634742 
##         895         896         897         898         899         900 
## 0.191655896 0.197197024 0.230225580 0.149095796 0.588597459 0.115991624 
##         901         902         903         904         905         906 
## 0.042761829 0.028397586 0.427025228 0.011948856 0.068989114 0.179601026 
##         907         908         909         910         911         912 
## 0.120959036 0.287165035 0.135191581 0.251670823 0.523604049 0.095901039 
##         913         914         915         916         917         918 
## 0.084661415 0.051845209 0.074873932 0.023346518 0.069723067 0.178499474 
##         919         920         921         922         923         924 
## 0.063416256 0.198958549 0.024729316 0.039103444 0.030412056 0.081521361 
##         925         926         927         928         929         930 
## 0.154421193 0.118379875 0.212901075 0.205171856 0.042362433 0.061211904 
##         931         932         933         934         935         936 
## 0.051479718 0.318435264 0.035346766 0.145643976 0.049920380 0.081746769 
##         937         938         939         940         941         942 
## 0.123307392 0.097944650 0.464781266 0.036504212 0.175188793 0.226092493 
##         943         944         945         946         947         948 
## 0.045158915 0.210514692 0.161244972 0.068076979 0.042372342 0.067066306 
##         949         950         951         952         953         954 
## 0.223597917 0.081927329 0.049817619 0.046901224 0.248859976 0.018178264 
##         955         956         957         958         959         960 
## 0.233596750 0.031443510 0.060651184 0.232898127 0.272788647 0.102291429 
##         961         962         963         964         965         966 
## 0.074088094 0.252128635 0.025327560 0.337961932 0.177013822 0.061269459 
##         967         968         969         970         971         972 
## 0.063254728 0.024445965 0.026403920 0.304171086 0.067606721 0.121562442 
##         973         974         975         976         977         978 
## 0.091987318 0.160771435 0.469314281 0.158519306 0.091614885 0.259794950 
##         979         980         981         982         983         984 
## 0.359704204 0.032986663 0.454227910 0.069172821 0.173720351 0.212275852 
##         985         986         987         988         989         990 
## 0.113452399 0.071089402 0.095045244 0.037237646 0.177234893 0.064906634 
##         991         992         993         994         995         996 
## 0.059482791 0.039791860 0.279050642 0.088794942 0.123988010 0.279742823 
##         997         998         999        1000        1001        1002 
## 0.037267382 0.063659391 0.010816458 0.139471275 0.359250641 0.070641244 
##        1003        1004        1005        1006        1007        1008 
## 0.137779294 0.117082885 0.109410910 0.039175171 0.066642387 0.053752091 
##        1009        1010        1011        1012        1013        1014 
## 0.105003929 0.159943333 0.029322444 0.172711323 0.016709988 0.093755391 
##        1015        1016        1017        1018        1019        1020 
## 0.112369311 0.383107868 0.146703903 0.227248641 0.282474382 0.067252277 
##        1021        1022        1023        1024        1025        1026 
## 0.108162742 0.047395140 0.049124335 0.042402454 0.028353768 0.044179448 
##        1027        1028        1029        1030        1031        1032 
## 0.160822834 0.131173626 0.204257748 0.196251460 0.043198008 0.315032099 
##        1033        1034        1035        1036        1037        1038 
## 0.150109433 0.119741336 0.084674069 0.280727122 0.088400208 0.087625029 
##        1039        1040        1041        1042        1043        1044 
## 0.167821232 0.148382588 0.196711390 0.101759057 0.129755046 0.022644817 
##        1045        1046        1047        1048        1049        1050 
## 0.057935493 0.214502864 0.414580353 0.139289718 0.248587987 0.183737398 
##        1051        1052        1053        1054        1055        1056 
## 0.243048552 0.179935826 0.161036122 0.198640508 0.274487740 0.088236277 
##        1057        1058        1059        1060        1061        1062 
## 0.082362766 0.191360026 0.051716691 0.044862992 0.129378096 0.086356195 
##        1063        1064        1065        1066        1067        1068 
## 0.178868462 0.350667368 0.058381396 0.094023713 0.029669337 0.091078408 
##        1069        1070        1071        1072        1073        1074 
## 0.098385008 0.284521939 0.010762035 0.155828896 0.093748024 0.084687340 
##        1075        1076        1077        1078        1079        1080 
## 0.379783517 0.265799495 0.083017648 0.060939205 0.103577175 0.108777129 
##        1081        1082        1083        1084        1085        1086 
## 0.081867152 0.050040930 0.134108730 0.274096843 0.156930471 0.358227758 
##        1087        1088        1089        1090        1091        1092 
## 0.302291869 0.084360879 0.070305576 0.205389869 0.527151764 0.370288633 
##        1093        1094        1095        1096        1097        1098 
## 0.264875388 0.104685533 0.059118031 0.079588390 0.029064663 0.083671881 
##        1099        1100        1101        1102        1103        1104 
## 0.164164818 0.110298668 0.089903449 0.038916740 0.239162338 0.306253567 
##        1105        1106        1107        1108        1109        1110 
## 0.141333005 0.019773547 0.076480228 0.117512870 0.144256913 0.101678060 
##        1111 
## 0.238450062
testing
## # A tibble: 1,111 x 6
##    Churn `VMail Plan` `Day Charge` `Eve Charge` `Night Charge`
##    <int>        <int>        <dbl>        <dbl>          <dbl>
##  1     0            0         41.4        10.3            7.32
##  2     0            0         50.9         5.26           8.86
##  3     0            0         31.4        29.9            9.71
##  4     0            1         44.0        18.9           14.7 
##  5     0            0         20.5        26.1            9.14
##  6     1            0         56.6        27.0            7.23
##  7     0            0         26.4        20.4            9.4 
##  8     1            0         10.6        14.4            9.43
##  9     0            1         36.2        16.2            8.22
## 10     0            0         22.8        13.2            4.59
## # ... with 1,101 more rows, and 1 more variable: `Intl Charge` <dbl>

Now find the threshold using ROC curve.

library(ROCR)
res<-predict(model,training,type = "response")
ROCRpred=prediction(res,training$Churn)
ROCRperf<-performance(ROCRpred,"tpr","fpr")
plot(ROCRperf,colorize=TRUE,print.cutoffs.at=seq(0.1,by=0.1))

Now the graph says that threshold value is 0.3

Step 7: Now create the confusion matrix.

res<-predict(model,testing,type = "response")
table(Actualvalue=testing$Churn,Predictedvalue=res>0.3)
##            Predictedvalue
## Actualvalue FALSE TRUE
##           0   927   34
##           1    88   62

Now calculate the accuracy using confusion matrix.

(927+62)/(927+62+34+88)
## [1] 0.890189

Now our model is 89% accurate.

Step 8: Now calculate the odds ratio.

exp(confint(model))
## Waiting for profiling to be done...
##                       2.5 %      97.5 %
## (Intercept)    0.0005137012 0.004079338
## `VMail Plan`   0.2947008932 0.567543719
## `Day Charge`   1.0602898664 1.090035788
## `Eve Charge`   1.0450357900 1.107992300
## `Night Charge` 1.0006600997 1.112618431
## `Intl Charge`  1.1534444863 1.603326299

The odds ratio says,“what are the odd of an outcome happening as a result of a change in some variable.

For each unit increase in international charge, there is probability 15% increase in the likelihood of churning.

Churning might be more than 15% or less than 15% .Because this prediction is based on statistics.

“Statistics is approximate Science but not exact Science.”.