Actually I tend to make the most of this clear-format data to practice my skills of EDA and model building,since it’s been a while that I haven’t work on data mining project.
library(tidyverse)
library(corrplot)
library(pROC)
library(caret)
library(RColorBrewer)
library(ggalluvial)
library(xgboost)
churn<-suppressMessages(read_csv("WA_Fn-UseC_-Telco-Customer-Churn.csv"))
glimpse(churn)
## Observations: 7,043
## Variables: 21
## $ customerID <chr> "7590-VHVEG", "5575-GNVDE", "3668-QPYBK", "77...
## $ gender <chr> "Female", "Male", "Male", "Male", "Female", "...
## $ SeniorCitizen <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ Partner <chr> "Yes", "No", "No", "No", "No", "No", "No", "N...
## $ Dependents <chr> "No", "No", "No", "No", "No", "No", "Yes", "N...
## $ tenure <int> 1, 34, 2, 45, 2, 8, 22, 10, 28, 62, 13, 16, 5...
## $ PhoneService <chr> "No", "Yes", "Yes", "No", "Yes", "Yes", "Yes"...
## $ MultipleLines <chr> "No phone service", "No", "No", "No phone ser...
## $ InternetService <chr> "DSL", "DSL", "DSL", "DSL", "Fiber optic", "F...
## $ OnlineSecurity <chr> "No", "Yes", "Yes", "Yes", "No", "No", "No", ...
## $ OnlineBackup <chr> "Yes", "No", "Yes", "No", "No", "No", "Yes", ...
## $ DeviceProtection <chr> "No", "Yes", "No", "Yes", "No", "Yes", "No", ...
## $ TechSupport <chr> "No", "No", "No", "Yes", "No", "No", "No", "N...
## $ StreamingTV <chr> "No", "No", "No", "No", "No", "Yes", "Yes", "...
## $ StreamingMovies <chr> "No", "No", "No", "No", "No", "Yes", "No", "N...
## $ Contract <chr> "Month-to-month", "One year", "Month-to-month...
## $ PaperlessBilling <chr> "Yes", "No", "Yes", "No", "Yes", "Yes", "Yes"...
## $ PaymentMethod <chr> "Electronic check", "Mailed check", "Mailed c...
## $ MonthlyCharges <dbl> 29.85, 56.95, 53.85, 42.30, 70.70, 99.65, 89....
## $ TotalCharges <dbl> 29.85, 1889.50, 108.15, 1840.75, 151.65, 820....
## $ Churn <chr> "No", "No", "Yes", "No", "Yes", "Yes", "No", ...
There are 7043 observations and 21 variables,the response variable we want to predict is Churn and clearly we can observe from the glimpse info that the class of value of many variables is character, so we want to switch them to factor – the category value in R.
churn<- churn %>% mutate_if(is.character,as.factor) %>% select(-customerID)
churn$SeniorCitizen<-if_else(churn$SeniorCitizen==1,"Yes","No") %>% as.factor()
glimpse(churn)
## Observations: 7,043
## Variables: 20
## $ gender <fct> Female, Male, Male, Male, Female, Female, Mal...
## $ SeniorCitizen <fct> No, No, No, No, No, No, No, No, No, No, No, N...
## $ Partner <fct> Yes, No, No, No, No, No, No, No, Yes, No, Yes...
## $ Dependents <fct> No, No, No, No, No, No, Yes, No, No, Yes, Yes...
## $ tenure <int> 1, 34, 2, 45, 2, 8, 22, 10, 28, 62, 13, 16, 5...
## $ PhoneService <fct> No, Yes, Yes, No, Yes, Yes, Yes, No, Yes, Yes...
## $ MultipleLines <fct> No phone service, No, No, No phone service, N...
## $ InternetService <fct> DSL, DSL, DSL, DSL, Fiber optic, Fiber optic,...
## $ OnlineSecurity <fct> No, Yes, Yes, Yes, No, No, No, Yes, No, Yes, ...
## $ OnlineBackup <fct> Yes, No, Yes, No, No, No, Yes, No, No, Yes, N...
## $ DeviceProtection <fct> No, Yes, No, Yes, No, Yes, No, No, Yes, No, N...
## $ TechSupport <fct> No, No, No, Yes, No, No, No, No, Yes, No, No,...
## $ StreamingTV <fct> No, No, No, No, No, Yes, Yes, No, Yes, No, No...
## $ StreamingMovies <fct> No, No, No, No, No, Yes, No, No, Yes, No, No,...
## $ Contract <fct> Month-to-month, One year, Month-to-month, One...
## $ PaperlessBilling <fct> Yes, No, Yes, No, Yes, Yes, Yes, No, Yes, No,...
## $ PaymentMethod <fct> Electronic check, Mailed check, Mailed check,...
## $ MonthlyCharges <dbl> 29.85, 56.95, 53.85, 42.30, 70.70, 99.65, 89....
## $ TotalCharges <dbl> 29.85, 1889.50, 108.15, 1840.75, 151.65, 820....
## $ Churn <fct> No, No, Yes, No, Yes, Yes, No, No, Yes, No, N...
churn %>% ggplot(aes(x=Churn))+geom_bar(fill = c("#FC4E07", "#E7B800"))
churn %>% group_by(Churn,gender) %>% count() %>% ggplot(aes(x=Churn,y=n,fill=gender))+geom_col()+
ggrepel::geom_label_repel(aes(label=n))+labs(title="gender & churn",y="Number")
table(churn$Churn)/nrow(churn)
##
## No Yes
## 0.7346301 0.2653699
It appears that some missing values are mixed in the data which cause some warning messages when I executed the R codes,maybe we should look at it
sapply(churn, function(x){
return(sum(is.na(x)))
})
## gender SeniorCitizen Partner Dependents
## 0 0 0 0
## tenure PhoneService MultipleLines InternetService
## 0 0 0 0
## OnlineSecurity OnlineBackup DeviceProtection TechSupport
## 0 0 0 0
## StreamingTV StreamingMovies Contract PaperlessBilling
## 0 0 0 0
## PaymentMethod MonthlyCharges TotalCharges Churn
## 0 0 11 0
Only TotalCharges variable has missing ones,replacing 11 NAs with the median value would be a reasonal solution to that.
churn$TotalCharges<-if_else(is.na(churn$TotalCharges),median(churn$TotalCharges,na.rm = T),churn$TotalCharges)
churn %>% ggplot(aes(x=Churn,y=tenure,fill=Churn))+geom_boxplot()+ggtitle("tenure & churn")+stat_summary(fun.y = mean,geom = "point")+ggthemes::theme_economist_white()+scale_fill_brewer(palette = "RdGy")
churn %>% ggplot(aes(x=PaymentMethod,y=MonthlyCharges,fill=Churn))+geom_boxplot()+scale_fill_brewer(palette = "Set3")+ggthemes::theme_solarized()+ggtitle("Monthly Charges & PaymentMethods")
churn %>% ggplot(aes(x=Contract,y=MonthlyCharges,fill=Churn))+geom_boxplot()+scale_fill_brewer(palette = "OrRd")+ggtitle("Monthly Charges & PaymentMethods")+ggthemes::theme_tufte()
churn %>% select_if(is.numeric) %>% cor() %>% corrplot.mixed()
p1<-churn %>% ggplot(aes(x=TotalCharges,y=Churn,fill=Churn))+ggridges::geom_density_ridges()+ggridges::theme_ridges()+scale_fill_brewer(palette = "Set2")
p2<-churn %>% ggplot(aes(x=MonthlyCharges,y=Churn,fill=Churn))+ggridges::geom_density_ridges()+ggridges::theme_ridges()+scale_fill_brewer(palette = "Set3")
gridExtra::grid.arrange(p1,p2)
At first we realize that this churn data contains three quantitive features and the other is categorical,but are they all important?clearly not.To get the preliminary feature importance,we build a simple model with rpart function,which is a well-known CART decision tree algorithm.
rp.model<-rpart::rpart(Churn~.,data = churn,method = "class")
rpart.plot::rpart.plot(rp.model)
varImp(rp.model) %>% rownames_to_column(var="feature") %>% filter(Overall != 0) %>% arrange(desc(Overall)) %>% ggplot(aes(x=reorder(feature,Overall),y=Overall,fill=feature))+geom_col()+coord_flip()+ggtitle("Feature Importances")+theme_bw()+scale_fill_brewer(palette = "Paired")+theme(legend.position = "none")
churn$TechSupport<-gsub("No internet service","No",churn$TechSupport)
churn$OnlineSecurity<-gsub("No internet service","No",churn$OnlineSecurity)
churn$MultipleLines<-gsub("No phone service","No",churn$MultipleLines)
churn$OnlineBackup<-gsub("No internet service","No",churn$OnlineBackup)
churn$DeviceProtection<-gsub("No internet service","No",churn$DeviceProtection)
churn$StreamingTV<-gsub("No internet service","No",churn$StreamingTV)
churn$StreamingMovies<-gsub("No internet service","No",churn$StreamingMovies)
churn$PaymentMethod<-as.factor(sapply(churn$PaymentMethod, function(x){x=unlist(str_split(x," "))[1]}))
churn %>% group_by(OnlineSecurity,Contract,TechSupport,InternetService,PaymentMethod,Churn) %>% count() %>% rename(Freq=n) %>% ggplot(aes(axis1=OnlineSecurity,axis2=Contract,axis3=TechSupport,axis4=InternetService,axis5=PaymentMethod,y=Freq))+scale_x_discrete(limits = c("OnlineSecurity","Contract","TechSupport","InternetService","PaymentMethod"), expand = c(.1, .05))+geom_alluvium(aes(fill=Churn))+geom_stratum()+theme_minimal()+geom_text(stat = "stratum",label.strata = TRUE)+coord_flip()
churn<-churn %>% select(-gender)
churn[,c("MonthlyCharges","TotalCharges")]<-sapply(churn[,c("MonthlyCharges","TotalCharges")],function(x){
return((x-min(x))/max(x))
})
trans.churn<-as.data.frame(sapply(churn %>% select(-c(MonthlyCharges,TotalCharges,tenure,Churn)), function(x){
return(model.matrix(~x-1,data = churn %>% select(-c(MonthlyCharges,TotalCharges,tenure,Churn))))
})) %>% bind_cols(churn %>% select(MonthlyCharges,TotalCharges,tenure,Churn))
glimpse(trans.churn)
## Observations: 7,043
## Variables: 38
## $ SeniorCitizen.xNo <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
## $ SeniorCitizen.xYes <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ Partner.xNo <dbl> 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, ...
## $ Partner.xYes <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, ...
## $ Dependents.xNo <dbl> 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, ...
## $ Dependents.xYes <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, ...
## $ PhoneService.xNo <dbl> 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, ...
## $ PhoneService.xYes <dbl> 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, ...
## $ MultipleLines.xNo <dbl> 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, ...
## $ MultipleLines.xYes <dbl> 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, ...
## $ InternetService.xDSL <dbl> 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, ...
## $ InternetService.xFiber.optic <dbl> 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, ...
## $ InternetService.xNo <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ OnlineSecurity.xNo <dbl> 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, ...
## $ OnlineSecurity.xYes <dbl> 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, ...
## $ OnlineBackup.xNo <dbl> 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, ...
## $ OnlineBackup.xYes <dbl> 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, ...
## $ DeviceProtection.xNo <dbl> 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, ...
## $ DeviceProtection.xYes <dbl> 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, ...
## $ TechSupport.xNo <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, ...
## $ TechSupport.xYes <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, ...
## $ StreamingTV.xNo <dbl> 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, ...
## $ StreamingTV.xYes <dbl> 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, ...
## $ StreamingMovies.xNo <dbl> 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, ...
## $ StreamingMovies.xYes <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, ...
## $ Contract.xMonth.to.month <dbl> 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, ...
## $ Contract.xOne.year <dbl> 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, ...
## $ Contract.xTwo.year <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ PaperlessBilling.xNo <dbl> 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, ...
## $ PaperlessBilling.xYes <dbl> 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, ...
## $ PaymentMethod.xBank <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, ...
## $ PaymentMethod.xCredit <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, ...
## $ PaymentMethod.xElectronic <dbl> 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, ...
## $ PaymentMethod.xMailed <dbl> 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, ...
## $ MonthlyCharges <dbl> 0.097684211, 0.325894737, 0.29978...
## $ TotalCharges <dbl> 0.001272338, 0.215399318, 0.01028...
## $ tenure <int> 1, 34, 2, 45, 2, 8, 22, 10, 28, 6...
## $ Churn <fct> No, No, Yes, No, Yes, Yes, No, No...
ind<-sample(2,nrow(trans.churn),replace = T,prob = c(0.7,0.3))
train.churn<-trans.churn[ind==1,]
test.churn<-trans.churn[ind==2,]
rf.model<-train(Churn~.,data = train.churn,method="rf",tuneGrid=expand.grid(mtry=c(2,3)),importance=T,metric = "ROC",ntree=500,trControl=trainControl(classProbs = T))
rf.model
## Random Forest
##
## 4874 samples
## 37 predictor
## 2 classes: 'No', 'Yes'
##
## No pre-processing
## Resampling: Bootstrapped (25 reps)
## Summary of sample sizes: 4874, 4874, 4874, 4874, 4874, 4874, ...
## Resampling results across tuning parameters:
##
## mtry Accuracy Kappa
## 2 0.7927319 0.4068291
## 3 0.7926069 0.4314928
##
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 2.
varImp(rf.model) %>% plot(main="Features of random forest")
rf.pred<-predict(rf.model,test.churn)
confusionMatrix(rf.pred,reference = test.churn$Churn,mode="everything",positive = "Yes")
## Confusion Matrix and Statistics
##
## Reference
## Prediction No Yes
## No 1492 305
## Yes 121 251
##
## Accuracy : 0.8036
## 95% CI : (0.7862, 0.8201)
## No Information Rate : 0.7437
## P-Value [Acc > NIR] : 2.889e-11
##
## Kappa : 0.4222
## Mcnemar's Test P-Value : < 2.2e-16
##
## Sensitivity : 0.4514
## Specificity : 0.9250
## Pos Pred Value : 0.6747
## Neg Pred Value : 0.8303
## Precision : 0.6747
## Recall : 0.4514
## F1 : 0.5409
## Prevalence : 0.2563
## Detection Rate : 0.1157
## Detection Prevalence : 0.1715
## Balanced Accuracy : 0.6882
##
## 'Positive' Class : Yes
##
rf.roc<-roc(test.churn$Churn,predict(rf.model,test.churn,type = "prob")[,2],levels = levels(test.churn$Churn))
xg.train<-xgb.DMatrix(train.churn %>% select(-Churn) %>% as.matrix(),label=train.churn$Churn)
xg.test<-xgb.DMatrix(as.matrix(test.churn %>% select(-Churn)),label=test.churn$Churn)
xg.model<-xgb.train(params = list(max_depth=7,eval_metric="error"),data = xg.train,watchlist = list(validation=xg.test),nrounds = 500,print_every_n = 50,early_stopping_rounds = 200)
## [1] validation-error:-0.256339
## Will train until validation_error hasn't improved in 200 rounds.
##
## [51] validation-error:-0.256339
## [101] validation-error:-0.256339
## [151] validation-error:-0.256339
## [201] validation-error:-0.256339
## Stopping. Best iteration:
## [1] validation-error:-0.256339
xg.pred<-predict(xg.model,xg.test)
xg.roc<-roc(test.churn$Churn,xg.pred)
confusionMatrix(as.factor(ifelse(xg.pred >= 0.5,"Yes","No")),reference = test.churn$Churn,positive = "Yes",mode = "everything")
## Confusion Matrix and Statistics
##
## Reference
## Prediction No Yes
## No 0 0
## Yes 1613 556
##
## Accuracy : 0.2563
## 95% CI : (0.2381, 0.2753)
## No Information Rate : 0.7437
## P-Value [Acc > NIR] : 1
##
## Kappa : 0
## Mcnemar's Test P-Value : <2e-16
##
## Sensitivity : 1.0000
## Specificity : 0.0000
## Pos Pred Value : 0.2563
## Neg Pred Value : NaN
## Precision : 0.2563
## Recall : 1.0000
## F1 : 0.4081
## Prevalence : 0.2563
## Detection Rate : 0.2563
## Detection Prevalence : 1.0000
## Balanced Accuracy : 0.5000
##
## 'Positive' Class : Yes
##
xgb.plot.importance(xgb.importance(colnames(xg.train),model=xg.model),xlab = "Relative importance")
glm.model<-glm(Churn~.,data = train.churn,family = "binomial")
glm.model %>% summary()
##
## Call:
## glm(formula = Churn ~ ., family = "binomial", data = train.churn)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.9571 -0.6828 -0.3016 0.7377 3.3010
##
## Coefficients: (15 not defined because of singularities)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.052510 1.814597 -0.580 0.561898
## SeniorCitizen.xNo -0.367257 0.100976 -3.637 0.000276 ***
## SeniorCitizen.xYes NA NA NA NA
## Partner.xNo 0.048117 0.092538 0.520 0.603085
## Partner.xYes NA NA NA NA
## Dependents.xNo 0.115826 0.107094 1.082 0.279460
## Dependents.xYes NA NA NA NA
## PhoneService.xNo -0.046453 0.781103 -0.059 0.952577
## PhoneService.xYes NA NA NA NA
## MultipleLines.xNo -0.395069 0.212506 -1.859 0.063014 .
## MultipleLines.xYes NA NA NA NA
## InternetService.xDSL 1.531491 0.972364 1.575 0.115252
## InternetService.xFiber.optic 2.859383 1.920519 1.489 0.136524
## InternetService.xNo NA NA NA NA
## OnlineSecurity.xNo 0.259282 0.214765 1.207 0.227322
## OnlineSecurity.xYes NA NA NA NA
## OnlineBackup.xNo 0.108721 0.212081 0.513 0.608203
## OnlineBackup.xYes NA NA NA NA
## DeviceProtection.xNo -0.031567 0.211615 -0.149 0.881418
## DeviceProtection.xYes NA NA NA NA
## TechSupport.xNo 0.168748 0.218063 0.774 0.439020
## TechSupport.xYes NA NA NA NA
## StreamingTV.xNo -0.443858 0.393187 -1.129 0.258951
## StreamingTV.xYes NA NA NA NA
## StreamingMovies.xNo -0.426316 0.394729 -1.080 0.280133
## StreamingMovies.xYes NA NA NA NA
## Contract.xMonth.to.month 1.130290 0.200639 5.633 1.77e-08 ***
## Contract.xOne.year 0.427822 0.202842 2.109 0.034933 *
## Contract.xTwo.year NA NA NA NA
## PaperlessBilling.xNo -0.368835 0.089630 -4.115 3.87e-05 ***
## PaperlessBilling.xYes NA NA NA NA
## PaymentMethod.xBank 0.071515 0.136275 0.525 0.599731
## PaymentMethod.xCredit -0.084686 0.138396 -0.612 0.540599
## PaymentMethod.xElectronic 0.340802 0.116272 2.931 0.003378 **
## PaymentMethod.xMailed NA NA NA NA
## MonthlyCharges -3.276914 4.545037 -0.721 0.470917
## TotalCharges 2.536015 0.710147 3.571 0.000355 ***
## tenure -0.056685 0.007117 -7.965 1.65e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 5679.7 on 4873 degrees of freedom
## Residual deviance: 4103.1 on 4851 degrees of freedom
## AIC: 4149.1
##
## Number of Fisher Scoring iterations: 6
glm.model_1<-MASS::stepAIC(glm.model,direction = "both")
## Start: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingTV.xYes +
## StreamingMovies.xNo + StreamingMovies.xYes + Contract.xMonth.to.month +
## Contract.xOne.year + Contract.xTwo.year + PaperlessBilling.xNo +
## PaperlessBilling.xYes + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + PaymentMethod.xMailed + MonthlyCharges +
## TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingTV.xYes +
## StreamingMovies.xNo + StreamingMovies.xYes + Contract.xMonth.to.month +
## Contract.xOne.year + Contract.xTwo.year + PaperlessBilling.xNo +
## PaperlessBilling.xYes + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingTV.xYes +
## StreamingMovies.xNo + StreamingMovies.xYes + Contract.xMonth.to.month +
## Contract.xOne.year + Contract.xTwo.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingTV.xYes +
## StreamingMovies.xNo + StreamingMovies.xYes + Contract.xMonth.to.month +
## Contract.xOne.year + PaperlessBilling.xNo + PaymentMethod.xBank +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingTV.xYes +
## StreamingMovies.xNo + Contract.xMonth.to.month + Contract.xOne.year +
## PaperlessBilling.xNo + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + TechSupport.xYes + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + DeviceProtection.xYes +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## OnlineBackup.xYes + DeviceProtection.xNo + TechSupport.xNo +
## StreamingTV.xNo + StreamingMovies.xNo + Contract.xMonth.to.month +
## Contract.xOne.year + PaperlessBilling.xNo + PaymentMethod.xBank +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineSecurity.xYes + OnlineBackup.xNo +
## DeviceProtection.xNo + TechSupport.xNo + StreamingTV.xNo +
## StreamingMovies.xNo + Contract.xMonth.to.month + Contract.xOne.year +
## PaperlessBilling.xNo + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + InternetService.xNo +
## OnlineSecurity.xNo + OnlineBackup.xNo + DeviceProtection.xNo +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + MultipleLines.xYes +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + DeviceProtection.xNo + TechSupport.xNo +
## StreamingTV.xNo + StreamingMovies.xNo + Contract.xMonth.to.month +
## Contract.xOne.year + PaperlessBilling.xNo + PaymentMethod.xBank +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## PhoneService.xYes + MultipleLines.xNo + InternetService.xDSL +
## InternetService.xFiber.optic + OnlineSecurity.xNo + OnlineBackup.xNo +
## DeviceProtection.xNo + TechSupport.xNo + StreamingTV.xNo +
## StreamingMovies.xNo + Contract.xMonth.to.month + Contract.xOne.year +
## PaperlessBilling.xNo + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + Dependents.xYes + PhoneService.xNo +
## MultipleLines.xNo + InternetService.xDSL + InternetService.xFiber.optic +
## OnlineSecurity.xNo + OnlineBackup.xNo + DeviceProtection.xNo +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Partner.xYes + Dependents.xNo + PhoneService.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + DeviceProtection.xNo + TechSupport.xNo +
## StreamingTV.xNo + StreamingMovies.xNo + Contract.xMonth.to.month +
## Contract.xOne.year + PaperlessBilling.xNo + PaymentMethod.xBank +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + SeniorCitizen.xYes + Partner.xNo +
## Dependents.xNo + PhoneService.xNo + MultipleLines.xNo + InternetService.xDSL +
## InternetService.xFiber.optic + OnlineSecurity.xNo + OnlineBackup.xNo +
## DeviceProtection.xNo + TechSupport.xNo + StreamingTV.xNo +
## StreamingMovies.xNo + Contract.xMonth.to.month + Contract.xOne.year +
## PaperlessBilling.xNo + PaymentMethod.xBank + PaymentMethod.xCredit +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
##
## Step: AIC=4149.07
## Churn ~ SeniorCitizen.xNo + Partner.xNo + Dependents.xNo + PhoneService.xNo +
## MultipleLines.xNo + InternetService.xDSL + InternetService.xFiber.optic +
## OnlineSecurity.xNo + OnlineBackup.xNo + DeviceProtection.xNo +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
## Df Deviance AIC
## - PhoneService.xNo 1 4103.1 4147.1
## - DeviceProtection.xNo 1 4103.1 4147.1
## - OnlineBackup.xNo 1 4103.3 4147.3
## - Partner.xNo 1 4103.3 4147.3
## - PaymentMethod.xBank 1 4103.3 4147.3
## - PaymentMethod.xCredit 1 4103.4 4147.4
## - MonthlyCharges 1 4103.6 4147.6
## - TechSupport.xNo 1 4103.7 4147.7
## - StreamingMovies.xNo 1 4104.2 4148.2
## - Dependents.xNo 1 4104.2 4148.2
## - StreamingTV.xNo 1 4104.3 4148.3
## - OnlineSecurity.xNo 1 4104.5 4148.5
## <none> 4103.1 4149.1
## - InternetService.xFiber.optic 1 4105.3 4149.3
## - InternetService.xDSL 1 4105.5 4149.5
## - MultipleLines.xNo 1 4106.5 4150.5
## - Contract.xOne.year 1 4107.7 4151.7
## - PaymentMethod.xElectronic 1 4111.7 4155.7
## - SeniorCitizen.xNo 1 4116.3 4160.3
## - TotalCharges 1 4116.4 4160.4
## - PaperlessBilling.xNo 1 4120.1 4164.1
## - Contract.xMonth.to.month 1 4139.4 4183.4
## - tenure 1 4177.0 4221.0
##
## Step: AIC=4147.07
## Churn ~ SeniorCitizen.xNo + Partner.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + DeviceProtection.xNo + TechSupport.xNo +
## StreamingTV.xNo + StreamingMovies.xNo + Contract.xMonth.to.month +
## Contract.xOne.year + PaperlessBilling.xNo + PaymentMethod.xBank +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
## Df Deviance AIC
## - DeviceProtection.xNo 1 4103.1 4145.1
## - Partner.xNo 1 4103.3 4145.3
## - PaymentMethod.xBank 1 4103.3 4145.3
## - PaymentMethod.xCredit 1 4103.4 4145.4
## - Dependents.xNo 1 4104.2 4146.2
## - OnlineBackup.xNo 1 4104.6 4146.6
## <none> 4103.1 4147.1
## - TechSupport.xNo 1 4105.6 4147.6
## + PhoneService.xNo 1 4103.1 4149.1
## + PhoneService.xYes 1 4103.1 4149.1
## - Contract.xOne.year 1 4107.7 4149.7
## - OnlineSecurity.xNo 1 4109.3 4151.3
## - PaymentMethod.xElectronic 1 4111.7 4153.7
## - MonthlyCharges 1 4113.8 4155.8
## - StreamingMovies.xNo 1 4114.7 4156.7
## - StreamingTV.xNo 1 4115.5 4157.5
## - MultipleLines.xNo 1 4115.7 4157.7
## - SeniorCitizen.xNo 1 4116.3 4158.3
## - TotalCharges 1 4116.4 4158.4
## - PaperlessBilling.xNo 1 4120.1 4162.1
## - Contract.xMonth.to.month 1 4139.4 4181.4
## - InternetService.xFiber.optic 1 4146.5 4188.5
## - InternetService.xDSL 1 4150.7 4192.7
## - tenure 1 4177.0 4219.0
##
## Step: AIC=4145.11
## Churn ~ SeniorCitizen.xNo + Partner.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
## Df Deviance AIC
## - Partner.xNo 1 4103.4 4143.4
## - PaymentMethod.xBank 1 4103.4 4143.4
## - PaymentMethod.xCredit 1 4103.5 4143.5
## - Dependents.xNo 1 4104.3 4144.3
## - OnlineBackup.xNo 1 4104.7 4144.7
## <none> 4103.1 4145.1
## - TechSupport.xNo 1 4105.8 4145.8
## + DeviceProtection.xNo 1 4103.1 4147.1
## + DeviceProtection.xYes 1 4103.1 4147.1
## + PhoneService.xNo 1 4103.1 4147.1
## + PhoneService.xYes 1 4103.1 4147.1
## - Contract.xOne.year 1 4107.7 4147.7
## - OnlineSecurity.xNo 1 4109.6 4149.6
## - PaymentMethod.xElectronic 1 4111.7 4151.7
## - MonthlyCharges 1 4114.7 4154.7
## - StreamingMovies.xNo 1 4114.8 4154.8
## - StreamingTV.xNo 1 4115.6 4155.6
## - MultipleLines.xNo 1 4116.0 4156.0
## - SeniorCitizen.xNo 1 4116.4 4156.4
## - TotalCharges 1 4116.5 4156.5
## - PaperlessBilling.xNo 1 4120.2 4160.2
## - Contract.xMonth.to.month 1 4139.5 4179.5
## - InternetService.xFiber.optic 1 4149.5 4189.5
## - InternetService.xDSL 1 4151.5 4191.5
## - tenure 1 4177.0 4217.0
##
## Step: AIC=4143.38
## Churn ~ SeniorCitizen.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xBank + PaymentMethod.xCredit + PaymentMethod.xElectronic +
## MonthlyCharges + TotalCharges + tenure
##
## Df Deviance AIC
## - PaymentMethod.xBank 1 4103.6 4141.6
## - PaymentMethod.xCredit 1 4103.8 4141.8
## - OnlineBackup.xNo 1 4104.9 4142.9
## <none> 4103.4 4143.4
## - Dependents.xNo 1 4105.4 4143.4
## - TechSupport.xNo 1 4106.1 4144.1
## + Partner.xNo 1 4103.1 4145.1
## + Partner.xYes 1 4103.1 4145.1
## + DeviceProtection.xNo 1 4103.3 4145.3
## + DeviceProtection.xYes 1 4103.3 4145.3
## + PhoneService.xNo 1 4103.4 4145.4
## + PhoneService.xYes 1 4103.4 4145.4
## - Contract.xOne.year 1 4108.0 4146.0
## - OnlineSecurity.xNo 1 4109.9 4147.9
## - PaymentMethod.xElectronic 1 4111.9 4149.9
## - MonthlyCharges 1 4115.0 4153.0
## - StreamingMovies.xNo 1 4115.0 4153.0
## - StreamingTV.xNo 1 4115.8 4153.8
## - MultipleLines.xNo 1 4116.2 4154.2
## - SeniorCitizen.xNo 1 4116.4 4154.4
## - TotalCharges 1 4116.8 4154.8
## - PaperlessBilling.xNo 1 4120.4 4158.4
## - Contract.xMonth.to.month 1 4139.7 4177.7
## - InternetService.xFiber.optic 1 4149.7 4187.7
## - InternetService.xDSL 1 4151.8 4189.8
## - tenure 1 4178.7 4216.7
##
## Step: AIC=4141.63
## Churn ~ SeniorCitizen.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xCredit + PaymentMethod.xElectronic + MonthlyCharges +
## TotalCharges + tenure
##
## Df Deviance AIC
## - PaymentMethod.xCredit 1 4104.7 4140.7
## - OnlineBackup.xNo 1 4105.2 4141.2
## <none> 4103.6 4141.6
## - Dependents.xNo 1 4105.7 4141.7
## - TechSupport.xNo 1 4106.4 4142.4
## + PaymentMethod.xBank 1 4103.4 4143.4
## + PaymentMethod.xMailed 1 4103.4 4143.4
## + Partner.xNo 1 4103.4 4143.4
## + Partner.xYes 1 4103.4 4143.4
## + DeviceProtection.xNo 1 4103.6 4143.6
## + DeviceProtection.xYes 1 4103.6 4143.6
## + PhoneService.xNo 1 4103.6 4143.6
## + PhoneService.xYes 1 4103.6 4143.6
## - Contract.xOne.year 1 4108.2 4144.2
## - OnlineSecurity.xNo 1 4110.2 4146.2
## - PaymentMethod.xElectronic 1 4114.5 4150.5
## - MonthlyCharges 1 4115.1 4151.1
## - StreamingMovies.xNo 1 4115.3 4151.3
## - StreamingTV.xNo 1 4116.2 4152.2
## - MultipleLines.xNo 1 4116.6 4152.6
## - SeniorCitizen.xNo 1 4116.6 4152.6
## - TotalCharges 1 4116.8 4152.8
## - PaperlessBilling.xNo 1 4120.9 4156.9
## - Contract.xMonth.to.month 1 4139.8 4175.8
## - InternetService.xFiber.optic 1 4150.4 4186.4
## - InternetService.xDSL 1 4152.7 4188.7
## - tenure 1 4179.6 4215.6
##
## Step: AIC=4140.68
## Churn ~ SeniorCitizen.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## OnlineBackup.xNo + TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
## Df Deviance AIC
## - OnlineBackup.xNo 1 4106.3 4140.3
## <none> 4104.7 4140.7
## - Dependents.xNo 1 4106.7 4140.7
## - TechSupport.xNo 1 4107.4 4141.4
## + PaymentMethod.xCredit 1 4103.6 4141.6
## + PaymentMethod.xBank 1 4103.8 4141.8
## + Partner.xNo 1 4104.4 4142.4
## + Partner.xYes 1 4104.4 4142.4
## + DeviceProtection.xYes 1 4104.7 4142.7
## + DeviceProtection.xNo 1 4104.7 4142.7
## + PhoneService.xNo 1 4104.7 4142.7
## + PhoneService.xYes 1 4104.7 4142.7
## + PaymentMethod.xMailed 1 4104.7 4142.7
## - Contract.xOne.year 1 4109.4 4143.4
## - OnlineSecurity.xNo 1 4111.2 4145.2
## - MonthlyCharges 1 4116.2 4150.2
## - StreamingMovies.xNo 1 4116.2 4150.2
## - StreamingTV.xNo 1 4117.2 4151.2
## - MultipleLines.xNo 1 4117.5 4151.5
## - SeniorCitizen.xNo 1 4117.6 4151.6
## - TotalCharges 1 4118.3 4152.3
## - PaymentMethod.xElectronic 1 4121.4 4155.4
## - PaperlessBilling.xNo 1 4121.6 4155.6
## - Contract.xMonth.to.month 1 4141.1 4175.1
## - InternetService.xFiber.optic 1 4151.0 4185.0
## - InternetService.xDSL 1 4153.1 4187.1
## - tenure 1 4182.4 4216.4
##
## Step: AIC=4140.28
## Churn ~ SeniorCitizen.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure
##
## Df Deviance AIC
## <none> 4106.3 4140.3
## - Dependents.xNo 1 4108.4 4140.4
## - TechSupport.xNo 1 4108.7 4140.7
## + OnlineBackup.xNo 1 4104.7 4140.7
## + OnlineBackup.xYes 1 4104.7 4140.7
## + PaymentMethod.xCredit 1 4105.2 4141.2
## + PaymentMethod.xBank 1 4105.3 4141.3
## + PhoneService.xNo 1 4105.8 4141.8
## + PhoneService.xYes 1 4105.8 4141.8
## + Partner.xNo 1 4106.0 4142.0
## + Partner.xYes 1 4106.0 4142.0
## + DeviceProtection.xNo 1 4106.2 4142.2
## + DeviceProtection.xYes 1 4106.2 4142.2
## + PaymentMethod.xMailed 1 4106.3 4142.3
## - Contract.xOne.year 1 4110.9 4142.9
## - OnlineSecurity.xNo 1 4112.1 4144.1
## - SeniorCitizen.xNo 1 4119.1 4151.1
## - TotalCharges 1 4119.3 4151.3
## - StreamingMovies.xNo 1 4120.4 4152.4
## - MultipleLines.xNo 1 4120.9 4152.9
## - StreamingTV.xNo 1 4121.5 4153.5
## - MonthlyCharges 1 4122.7 4154.7
## - PaymentMethod.xElectronic 1 4122.8 4154.8
## - PaperlessBilling.xNo 1 4122.9 4154.9
## - Contract.xMonth.to.month 1 4142.5 4174.5
## - InternetService.xDSL 1 4158.5 4190.5
## - InternetService.xFiber.optic 1 4162.0 4194.0
## - tenure 1 4184.7 4216.7
glm.pred<-predict(glm.model_1,test.churn,type = "response")
summary(glm.model_1)
##
## Call:
## glm(formula = Churn ~ SeniorCitizen.xNo + Dependents.xNo + MultipleLines.xNo +
## InternetService.xDSL + InternetService.xFiber.optic + OnlineSecurity.xNo +
## TechSupport.xNo + StreamingTV.xNo + StreamingMovies.xNo +
## Contract.xMonth.to.month + Contract.xOne.year + PaperlessBilling.xNo +
## PaymentMethod.xElectronic + MonthlyCharges + TotalCharges +
## tenure, family = "binomial", data = train.churn)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.9466 -0.6803 -0.3033 0.7429 3.3094
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.94692 0.41716 -2.270 0.023212 *
## SeniorCitizen.xNo -0.35765 0.10000 -3.577 0.000348 ***
## Dependents.xNo 0.14037 0.09751 1.440 0.150001
## MultipleLines.xNo -0.39965 0.10484 -3.812 0.000138 ***
## InternetService.xDSL 1.49991 0.20924 7.168 7.59e-13 ***
## InternetService.xFiber.optic 2.85335 0.38172 7.475 7.72e-14 ***
## OnlineSecurity.xNo 0.25793 0.10690 2.413 0.015832 *
## TechSupport.xNo 0.17140 0.11116 1.542 0.123104
## StreamingTV.xNo -0.45017 0.11559 -3.894 9.84e-05 ***
## StreamingMovies.xNo -0.43019 0.11467 -3.752 0.000176 ***
## Contract.xMonth.to.month 1.12336 0.19993 5.619 1.92e-08 ***
## Contract.xOne.year 0.42420 0.20261 2.094 0.036284 *
## PaperlessBilling.xNo -0.36329 0.08942 -4.063 4.85e-05 ***
## PaymentMethod.xElectronic 0.34128 0.08352 4.086 4.38e-05 ***
## MonthlyCharges -3.29958 0.81430 -4.052 5.08e-05 ***
## TotalCharges 2.48507 0.70264 3.537 0.000405 ***
## tenure -0.05716 0.00699 -8.177 2.90e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 5679.7 on 4873 degrees of freedom
## Residual deviance: 4106.3 on 4857 degrees of freedom
## AIC: 4140.3
##
## Number of Fisher Scoring iterations: 6
confusionMatrix(ifelse(glm.pred>=0.5,"Yes","No") %>% as.factor(),test.churn$Churn,positive = "Yes",mode="everything")
## Confusion Matrix and Statistics
##
## Reference
## Prediction No Yes
## No 1461 247
## Yes 152 309
##
## Accuracy : 0.816
## 95% CI : (0.7991, 0.8321)
## No Information Rate : 0.7437
## P-Value [Acc > NIR] : 7.891e-16
##
## Kappa : 0.4889
## Mcnemar's Test P-Value : 2.528e-06
##
## Sensitivity : 0.5558
## Specificity : 0.9058
## Pos Pred Value : 0.6703
## Neg Pred Value : 0.8554
## Precision : 0.6703
## Recall : 0.5558
## F1 : 0.6077
## Prevalence : 0.2563
## Detection Rate : 0.1425
## Detection Prevalence : 0.2125
## Balanced Accuracy : 0.7308
##
## 'Positive' Class : Yes
##
glm.roc<-roc(test.churn$Churn,glm.pred)
plot.roc(xg.roc,col="black",legacy.axes = T)
plot.roc(rf.roc,col="blue",add = T)
plot.roc(glm.roc,add=TRUE,col="red")
legend("bottom", c("XGBoost","Random Forest", "Logistic"),
lty = c(1,1), lwd = c(2, 2), col = c("black", "red", "blue"), cex = 0.75)
In this markdown,we deeply ananlyzed the churn data from kaggle in various methods and machine learning algotithms.Maybe we should walk you through the procesure once again just in case you miss.
1. read in the data and have a glimpse at it
2. transform the character features into categorical
3. EDA about all the other features regarding to the predictor–Churn
4. using rpart decision tree algorithm to roughly see the importance of each feature
5. change all categorical features into numerical ones with built-in function model.matrix
6. fit three different machine learning models using xgboost,random forest and logistic regression
random forest make the best prediction
in general,xgboost always does a good job in prediction,but in this special case,it fails.Maybe I should find it out
tenure,monthlycharges and totalcharges are the top3 most important features