NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > Machine Learning > Predicting Customer Churn at Telco

Predicting Customer Churn at Telco

Denise Garbato
Posted on Jan 19, 2023

Background

Telco is a hypothetical telecommunications company. Like any company that offers contract / subscription based services customers canceling services is an ongoing problem.

Services they provide include:

  • Phone Service
  • Internet Service
  • Online Security
  • Online Backup
  • Streaming TV
  • Streaming Movies

They have asked me to build a model to predict customer churn so that at risk customers can be identified and given special offers so that they stay with the company.

The data used is from Kaggle.  There are 7,043 customers.

A churn is a customer who left within the last month.

The three classification models I built predict, but also provide information about factors driving churn.

  • Regularized Logistic Regression (Lasso)
  • Random Forest
  • Gradient Bossting

Some key features from in the influencing churn at Telco are:

  • Contract Type
  • Customer Tenure in Months
  • Online Security
  • Monthly Charges
  • Tech Support

You will see later on in my exploratory data analysis why these features are important.

First I am going to walk you through the process that I went through to build the model for this company.

70% of the customers was used to train the models and 30% was used for testing.

Exploratory Data Analysis

Missing values

There were not any missing values in the data.

Outliers in the data

There are only three numeric features in the data and there were not any outliers.  The boxplots below confirm that.

 

 

Relationship of  numeric features with Churn in the training data.

The numeric factors were broken out into deciles for analysis.

A decile is comprised of ten percentiles.  For example, if a student's test score is in the 90th percentile, it means that he/she scored in the top 10 percent.  It would be equivalent to say that his/her score is in the tenth decile as that also means the top 10 percent.

As the value of a numeric factor increases the range of values in each decile increases.

The churn rate within each decile was calculated and indexed to the overall churn rate of 27% using the following calculations:

Overall Churn Rate = (Number Of Churns) / (Total Number Of Customers)

Index = (Churn Rate Within Each Decile) / Overall Churn Rate) * 100

 

Customer Tenure has a strong negative relationship with churn.  Newer customers are much more likely to churn.  I've built a number of logistic regression models in the course of my career and Customer Tenure has always been the strongest feature in the model.  It was the strongest feature in the logistic regression model for this project as well.

 

Monthly Charges have a positive relationship with churn.

 

Total Charges have a negative relationship with churn.  Most likely because customers with longer tenure have paid more than newer ones.  The correlation between Customer Tenure and Total Charges is 0.83.

 

Relationship of key categorical features with Churn in the training data.

For the categorical factors, each category was indexed to the overall churn rate of 27% using the following calculation:

Index = (Churn Rate Per Category) / (Overall Churn Rate) * 100

Note: when the index of the Churn Rate Per Category is equivalent to the Overall Churn Rate the index = 100

Customers with month-to-month contracts are more likely to churn with an index of 161 and a churn rate of 43%.  55% of  customers fall into this category.

 

Customers who do not have online security are much more likely to churn with and index of 158 and a churn rate of 42%.  49% of customers fall into this category.

Customers without tech support are more likely to churn.  50% of customers fall into this category.

Models

As previously mentioned, three different models were built:

One Linear Model

  • Regularized Logistic Regression (Lasso).

Two Tree Based Models:

  • Random Forest
  • Gradient Boosting

For all three models the AUC ROC  was used for grid search.

Regularized Logistic Regression (Lasso)

I examined the numeric features for multicollinearity.

Tenure and Total Charges have variance inflation factors greater than five.  The variance inflation factor doesn't indicate what is correlated with what so I looked at a correlations matrix.  I consider a correlation of 0.4 or above to be high.

Total Charges is highly correlated with both Tenure and Monthly Charges and was not included in the model.

Before building the model:

  • All features were standardized.
  • The data was balanced.

The L1 norm was selected for Lasso.

Features were sorted by the absolute value of the coefficients in descending order.

Features with coefficients with the smallest absolute values were gradually removed which resulted in an increase in an increase in the area under the ROC curve of the test data. Once that value began to decrease no additional features were removed.

The best model had the largest AUC ROC for the test data.

Random Forest

Before building the model:

  • All categorical features were label encoded.
  • All features were standardized.
  • The data was balanced.

My approach:

Using randomized search, I set a broad range of values for the following hyperparameters:

  • maximum depth
  • number of trees
  • minimum samples an internal node must hold to further split
  • minimum samples in a leaf

After that I narrowed my search and using grid search.

I selected the model with the largest AUC ROC for the test data.

The best model had 400 trees, a depth of 6, minimum sample split =20 and minimum sample leaf=13.

Gradient Boosting

Before building the model:

  • All categorical features were label encoded.
  • All features were standardized

My approach:

Using randomized search, I tuned for the following hyperparameters:

  • maximum depth
  • number of trees
  • learning rate

I initiated my search for maximum depth and learning rate based on what I read in An Introduction to Statistical Learning. The authors indicate that a depth of one often works well and I initiated with [1,2]. For the learning rate, they say that the typical rates are 0.01 or 0.001 and I initiated with [0.01, 0.001].  Too many trees can lead to overfitting.  I started with a range from 1,000 to 5,000.

I selected the model with the largest AUC ROC  for the test data.

The best model had maximum depth = 1, learning rate = 0.01 and 5,000 trees. Models with more than 5,000 had lower values of AUC ROC.

Selecting the best model

The model with the highest AUC ROC and the highest accuracy in the test data is gradient boosting.  However, in a churn model, the main objective is to detect all customers who will churn so that they can be incentivized with special offers to stay with the company.  Even if the model predicts a customer that was going to leave the company, the customer will just get a special offer which is not a huge loss.  Therefore, the most important criteria in selecting the best model is the Recall or the True Positive Rate of the test data. 

Below are the confusion matrices of the test data for each of the three models.  The row with the true values for Churn in the confustion matrix for Gradient Boosting looks quite different than it does for the other two models.  That's because it has the lowest Recall.

The table below compares the three models.

In the data, there are only three numeric features. the others are categorical.  When the features are primarily categorical, the relationship is most likely not linear.

Based on that reasoning, the best model is Random Forest.

  • it's good at predicting nonlinear relationships
  • the recall isn't that much lower than logistic regression
  • the AUC ROC isn't that much lower than gradient boosting

Feature Importances

Random Forest top 15 feature importnaces

  • Contract Type
  • Customer Tenure
  • Total Charges
  • Monthly Charges
  • Online Security
  • Tech Support
  • Internet Service
  • Payment Method
  • Online Backup
  • Device Protection
  • Paperless Billing
  • Multiple Lines
  • Gender
  • Streaming Movies
  • Dependents

 

 

About Author

Denise Garbato

I am a Statistician and Business Analyst who supports strategic decision making in digital and traditional marketing channels by discovering insights, applying statistical and programming skills with a results-focused approach. I am skilled in data analysis and predictive...
View all posts by Denise Garbato >

Related Articles

Capstone
Catching Fraud in the Healthcare System
Data Analysis
Car Sales Report R Shiny App
Data Analysis
Injury Analysis of Soccer Players with Python
Capstone
Acquisition Due Dilligence Automation for Smaller Firms
R Shiny
Forecasting NY State Tax Credits: R Shiny App for Businesses

Leave a Comment

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application