Professional Documents
Culture Documents
REPORT
TABLE OF CONTENTS
1. Introduction---------------------------------------------------------------------------------3
2. Data overview------------------------------------------------------------------------------4-6
3. Imported Libraries------------------------------------------------------------------------7
4. Data Visualization------------------------------------------------------------------------8-9
5. Data Pre-processing---------------------------------------------------------------------10-14
6. Model Building-------------------------------------------------------------------------15-28
P a g e 1 | 35
Customer Churn Prediction
6.6.2 Rbf----------------------------------------------------------------------------------25
P a g e 2 | 35
Customer Churn Prediction
1. INTRODUCTION
Customer churn, also known as customer retention, customer turnover, or customer
defection, is the loss of clients or customers.
Telephone service companies, Internet service providers, pay TV companies, insurance
firms, and alarm monitoring services, often use customer attrition analysis and customer
attrition rates as one of their key business metrics because the cost of retaining an
existing customer is far less than acquiring a new one.
Companies from these sectors often have customer service branches which attempt to win
back defecting clients, because recovered long-term customers can be worth much more
to a company than newly recruited clients.
Companies usually make a distinction between voluntary churn and involuntary churn.
Voluntary churn occurs due to a decision by the customer to switch to another company
or service provider, involuntary churn occurs due to circumstances such as a customer's
relocation to a long-term care facility, death, or the relocation to a distant location. In
most applications, involuntary reasons for churn are excluded from the analytical models.
Analysts tend to concentrate on voluntary churn, because it typically occurs due to factors
of the company-customer relationship which companies’ control, such as how billing
interactions are handled or how after-sales help is provided.
Predictive analytics use churn prediction models that predict customer churn by assessing
their propensity of risk to churn. Since these models generate a small, prioritized list of
potential defectors, they are effective at focusing customer retention marketing programs
on the subset of the customer base who are most vulnerable to churn.
P a g e 3 | 35
Customer Churn Prediction
2. DATA OVERVIEW
2.1 Data description
State: The state the customer resides in.
Account length: The length of the
Area code: The area code of the place the customer resides in.
International plan: If the customer has subscribed to an international Plan.
Voice mail plan: If the customer has subscribed to a Voice mail Plan.
Number vmail messages: The number of messages the customer used with the voice
mail Plan.
Total day minutes: Total minutes used by the customer in the day.
Total day calls: Total number of calls made by the customer in the day.
Total day charge: Total charge for the calls and minutes used by the customer in the day.
Total eve minutes: Total minutes used by the customer in the evening.
Total eve calls: Total number calls made by the customer in the evening.
Total eve charge: Total charge for the calls and minutes used by the customer in the
evening.
Total night minutes: Total minutes used by the customer in the night.
Total night calls: Total number of calls made by the customer in the day.
Total night charge: Total charge for the calls and minutes used by the customer in the
night.
Total intl minutes: Total international minutes used by the customer.
Total intl calls: Total international calls made by the customer.
Total intl charge: Total international charge for the minutes and calls by the customer.
Customer service calls: Service calls made by the customer to the service center.
P a g e 4 | 35
Customer Churn Prediction
Rows: 2666
Number of features: 20
Missing values: 0
Features:
['State', 'Account length', 'Area code', 'International plan', 'Voice mail plan', 'Number
vmail messages', 'Total day minutes', 'Total day calls', 'Total day charge', 'Total eve
minutes', 'Total eve calls', 'Total eve charge', 'Total night minutes', 'Total night calls',
'Total night charge', 'Total intl minutes', 'Total intl calls', 'Total intl charge', 'Customer
service calls', 'Churn'].
Unique values:
State 51
Account length 205
Area code 3
International plan 2
Voice mail plan 2
Number vmail messages 42
Total day minutes 1489
Total day calls 115
Total day charge 1489
Total eve minutes 1442
Total eve calls 120
Total eve charge 1301
Total night minutes 1444
Total night calls 118
Total night charge 885
Total intl minutes 158
Total intl calls 21
Total intl charge 158
Customer service calls 10
Churn 2
P a g e 5 | 35
Customer Churn Prediction
Number of features: 20
Missing Values: 0
Features:
['State', 'Account length', 'Area code', 'International plan', 'Voice mail plan', 'Number
vmail messages', 'Total day minutes', 'Total day calls', 'Total day charge', 'Total eve
minutes', 'Total eve calls', 'Total eve charge', 'Total night minutes', 'Total night calls',
'Total night charge', 'Total intl minutes', 'Total intl calls', 'Total intl charge', 'Customer
service calls', 'Churn'].
Unique values:
State 51
Account length 179
Area code 3
International plan 2
Voice mail plan 2
Number vmail messages 37
Total day minutes 562
Total day calls 100
Total day charge 562
Total eve minutes 557
Total eve calls 94
Total eve charge 528
Total night minutes 568
Total night calls 96
Total night charge 453
Total intl minutes 132
Total intl calls 17
Total intl charge 132
Customer service calls 9
Churn 2
P a g e 6 | 35
Customer Churn Prediction
3. IMPORTED LIBRARIES:
import numpy as np
import pandas as pd
3.1 Visualization
import itertools
import io
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.figure_factory as ff
P a g e 7 | 35
Customer Churn Prediction
4. DATA VISUALIZATION
Here we can observe that 85.4% of the churn in training data is false and the rest
14.6% is true.
Now let’s observe how the variables are distributed.
P a g e 8 | 35
Customer Churn Prediction
Several of the numerical data are very correlated. (Total day minutes and Total day
charge), (Total eve minutes and Total eve charge), (Total night minutes and Total
night charge) and lastly (Total intl minutes and Total intl charge) are also
correlated. We only must select one of them.
P a g e 9 | 35
Customer Churn Prediction
5. DATA PREPROCESSING
Now, the data is scaled which makes it easy for a model to learn and understand
the problem.
P a g e 10 | 35
Customer Churn Prediction
P a g e 11 | 35
Customer Churn Prediction
Correlation explains how one or more variables are related to each other.
P a g e 12 | 35
Customer Churn Prediction
P a g e 13 | 35
Customer Churn Prediction
P a g e 14 | 35
Customer Churn Prediction
6. MODEL BUILDING
1) Logistic Regression
2) Decision Tree Classifier
3) KNN Classifier
4) Random Forest Classifier
5) Gaussian Naïve Bayes
6) SVM
7) Gaussian process Classifier
8) Gradient Boosting Classifier
9) Multi-layer perceptron Classifier
P a g e 15 | 35
Customer Churn Prediction
Here we plot roc curve and confusion matrix which aids us to understand the
features well. Next, we split the principal training dataset and plot subsets.
P a g e 16 | 35
Customer Churn Prediction
Threshold Plot
P a g e 17 | 35
Customer Churn Prediction
P a g e 18 | 35
Customer Churn Prediction
P a g e 19 | 35
Customer Churn Prediction
Decision tree classifiers are used successfully in many diverse areas. Their most
important feature is the capability of capturing descriptive decision-making
knowledge from the supplied data. Decision tree can be generated from training
sets.
Accuracy Score: 0.904047976011994
Area under curve: 0.7983851310176721
P a g e 20 | 35
Customer Churn Prediction
K-NN algorithm stores all the available data and classifies a new data point based
on the similarity. This means when new data appears then it can be easily
classified into a well suite category by using K- NN algorithm.
K-NN algorithm can be used for Regression as well as for Classification but
mostly it is used for the Classification problems.
K-NN is a non-parametric algorithm, which means it does not make any
assumption on underlying data.
It is also called a lazy learner algorithm because it does not learn from the training
set immediately instead it stores the dataset and at the time of classification, it
performs an action on the dataset.
Accuracy Score: 0.848575712143928
Area under curve: 0.5856718464351005
P a g e 21 | 35
Customer Churn Prediction
Random forest is a meta estimator that fits several decision tree classifiers on
various sub-samples of the dataset and use averaging to improve the predictive
accuracy and control over-fitting. The sub-sample size is always the same as
the original input sample size, but the samples are drawn with replacement.
Accuracy Score: 0.9115442278860569
Area under curve: 0.7736822059719684
P a g e 22 | 35
Customer Churn Prediction
P a g e 23 | 35
Customer Churn Prediction
Linear SVM is used for linearly separable data, which means if a dataset
can be classified into two classes by using a single straight line, then such
data is termed as linearly separable data, and classifier is used called as
Linear SVM classifier.
Accuracy Score: 0.8200899550224887
Area under curve: 0.5
P a g e 24 | 35
Customer Churn Prediction
P a g e 25 | 35
Customer Churn Prediction
P a g e 26 | 35
Customer Churn Prediction
P a g e 27 | 35
Customer Churn Prediction
P a g e 28 | 35
Customer Churn Prediction
P a g e 29 | 35
Customer Churn Prediction
P a g e 30 | 35
Customer Churn Prediction
P a g e 31 | 35
Customer Churn Prediction
P a g e 32 | 35
Customer Churn Prediction
P a g e 33 | 35
Customer Churn Prediction
P a g e 34 | 35
Customer Churn Prediction
P a g e 35 | 35