In a competitive world, the key to business success is to understand enough about your customers' behavior and preferences so that you can provide a personalized service to both your prospective and existing customer base. Using customer behavior analytics techniques, you can predict how a customer will respond to a business situation, thereby giving you the information you need to approach them. These techniques can be broadly grouped into two buckets:
Regression problems: The response to this type of problem is a numerical value; for example, based on customer demographics and past purchasing patterns, how much will the customer spend in a particular instance?
Classification problems: The response to this type of problem is categorical; for example, based on the customer demographics and his or her past experience with the product/service, will the customer stay or leave the product/service?
Predicting whether a customer will stop using your product or service is an important component of customer behavior analytics called churn prediction. In this post, I will analyze two aspects of churn prediction:
For the given scenario, which factors are mainly responsible for customer churn?
Given the data pertaining to a new customer, how do you predict whether the customer will churn or stay, and what are the associated probabilities?
The Business Problem: Predicting Churn at a Telecom Service Provider
The telecom business is challenged by frequent customer churn due to several factors related to service and customer demographics. The dataset we'll use in our analysis includes a list of service-related factors about existing customers and information about whether they have stayed or left the service provider. Our objective is to understand which of the factors contribute most to customer churn and to predict which customers will potentially churn based on service-related factors.
About the Dataset
The dataset used for the analysis can be downloaded here. It consists of information for 5,000 customers and includes independent variables such as account length, number of voicemail messages, total daytime charge, total evening charge, total night charge, total international charge, and number of customer service calls.
The dependent variable in the dataset is whether the customer churned or not, which is indicated by a 1 for "yes" and 0 for "no."
What is Discriminant Analysis?
In order to uncover which variables are responsible for churn and predict whether a customer will churn or not, we will use discriminant analysis.
Discriminant analysis is a segmentation tool. It segments groups in a way as to achieve maximum separation between them. This technique makes use of the information provided by the X variables to achieve the clearest possible separation between two groups (in our case, the two groups are customers who stay and customers who churn). Below is our formula:
D= b0 + b1X1 + b2X2 + .. bnXn
Here, D is the discriminant score, b is the discriminant coefficient, and X1 and X2 are independent variables.
The discriminant coefficient is estimated by maximizing the ratio of the variation between the classes of customers and the variation within the classes. In other words, points belonging to the same class should be close together, while also being far away from the other clusters.
Discriminant Analysis: A High-Level Approach
Below, I've broken down the steps we will be following in order to predict customer churn, starting with data preparation and ending with validating the accuracy of our model.
Let's get started.
Formulating the Problem and Preparing the Data
To begin, we need to read the CSV file in R and convert the target variables into categorical variables. For the purpose of discriminant analysis, the Y variable has to be a categorical variable (meaning it is one of a limited number of possible values).
## Setting the working directory and reading the source file
setwd("C:/Users/Sowmya CR/Google Drive/datascience_blog")
## Converting the target variable to categorical variable
Now that we've converted our target variables, let's find the baseline churn rate for the dataset:
## 0 1
## 0.8586 0.1414
As you can see here, the baseline churn rate is 14.14%, which is an indicator that the dataset is unbalanced — there are more 0s than 1s. Subsequently, this will have an impact on how we interpret model performance measures.
Exploratory Data Analysis
Using ggplot2, I will explore our dataset and determine the impact our variables have on churn, starting with account length.
Generally, tariffs for day, evening, night, and international calls are higher for customers who churn compared to those who don't. This could indicate that customers who churn are not happy with the amount of money they are paying for their plan.
Here, we see that the number of customer service calls made to customers who churn is relatively high. This indicates that customers who have churned have tried contacting customer service — but might have not received a satisfactory resolution to their issue.
Using the assumptions we've derived from our exploratory data analysis, we will dive deeper into our variables using discriminant analysis.
Since the data have variables that are in various dimensions, it is advisable to scale them so the range of each variable does not have an influence on the discriminant coefficients. After the dataset is scaled, we will split the dataset into training and test datasets. We will build the model based on the training dataset and test the model performance using the test dataset.:
## Scale X variables
x <- subset(data,select=c(1:7))
## Split into training and test sets
split = sample.split(data1$churn, SplitRatio = 0.7)
traindata = subset(data1, split == TRUE)
testdata = subset(data1, split == FALSE)
#### Check if distribution of partition data is correct Testing dataset
## 0 1
## 0.8585714 0.1414286
## 0 1
## 0.8586667 0.1413333
Step One: Test the Significance of the Discriminant Function Using MANOVA
To test the significance of the discriminant function, we will use multivariate analysis of variance (MANOVA). Here's the approach we will take:
The null hypothesis of MANOVA is that all the means of the independent variables are equal, which implies that the independent variables are not differentiators of the group.
The alternative hypothesis is that at least one independent variable has a different mean or, in other words, a significant differentiator.
As you see above, the Wilks' lambda for MANOVA is closer to 1, indicating that the extent of discrimination in the model is relatively low. But the p-value is highly significant, indicating that the null hypothesis cannot be accepted. This implies that the discriminant model is highly significant.
Step 2: Develop the Fisher Discriminant Function
Now we need to identify a combination of features that separates our customers that are likely to churn from those who are not. I'll be using the packages DiscriMiner and MASS to do so.
In terms of magnitude, the number of customer service calls has the most impact, whereas the account length has the least impact. Number of voice mail messages has a negative sign indicating that it has a negative impact on churn. In other words, as the number of voice mail messages increases, the probability of churn decreases.
Step 3: Differentiation of Individual Independent Variables and Wilks' Lamba
The p-value is not significant for account length, but it highly significant for the other X variables. This indicates that all X variables except account length are excellent predictors in terms of differentiating our customer groups.
Step 4: Correlation Between Discriminant Function and Independent Variable
The relative importance of the X variables can be determined by the correlation ratio of each of the variables. The number of customer service calls emerges as the most significant variable in its ability to differentiate the groups.
Step 5: Classify Records Based on Discriminant Analysis of X Variables and Predict Y Variables for the Test Set
Since the discriminant model is significant, we will use it to classify records as belonging to either customers who will churn or those who will not churn depending on the X variables. We will use the lda() function in R to classify records based on value of X variables and predict the class and probability for the test set.
The difference in group means is highest for number of customer service calls and lowest for account length. This gives us insight into which factors contribute most to the discrimination between the groups.
The coefficients also give a similar pattern and throw light on which X variables contribute most to group separation.
Step 6: Visualizing the Groups
Now, let's visualize what our non-churning customers look like compared to our customers who will most likely churn. Remember, 0 indicates customers who will not churn and 1 indicates customers who will.
plot(sublda, dimen = 1, type = "b")
The groups created by discriminant analysis can be seen in the graphs, and are in sync with the Wilks lambda value of 0.89 that we got from our MANOVA test. These graphs are a good indicator that although the model is significant, our two groups are not completely separated. There is some overlap.
Step 7: Make Predictions on the Test Set
Using our test set, let's predict whether a customer will churn or stay based on the X variables of the test set. We will apply the discriminant model that we built using the training set to make predictions about the test set. The objective of this is to measure how the model performs on a new set of data.
## ER Sens Spec Precision Recall TPR FPR F Youden
## 1 0.143 0.127 0.977 0.474 0.127 0.127 0.0233 0.201 0.104
Step 8: Evaluate Model Performance Measures
The accuracy of the model is 1-Error rate = 1-0.1433 = 85.67%
Accuracy indicates how many correct predictions are made by the model. The model has a fairly good accuracy. However, since the dataset is unbalanced, accuracy alone may not be the sole indicator that the model is a robust model. Hence we will look at few other model performance measures.
Sensitivity also called the true positive rate is defined as the proportion of actual positives that are correctly identified by the model. The sensitivity of the model is 12.7% which is very low. For a churn prediction model, it is important that the model picks up positives as positives. It is important to make an accurate prediction of customers who will churn which is given by sensitivity.
We will now vary the threshold of the model from the default 50% to other values to decide on a optimum balance for sensitivity and specificity.
## classifying with a default threshold of 0.5
Now, let's compare the values of sensitivity and specificity for three threshold values.
## ER Sens Spec
## 1 0.1573333 0.3867925 0.9177019
## ER Sens Spec
## 1 0.21 0.6320755 0.8159938
## ER Sens Spec
## 1 0.242 0.7122642 0.765528
## ER Sens Spec
## 1 0.256 0.740566 0.7445652
## ER Sens Spec
## 1 0.272 0.7688679 0.7212733
## ER Sens Spec
## 1 0.4226667 0.8584906 0.5310559
When we plot the accuracy, sensitivity, and specificity for various threshold values, the three lines intersect at a particular point. The threshold corresponding to this point indicates the optimum threshold for the model.
From the chart above, it is clear that the optimum threshold for the model is 16%. When we make predictions at this threshold, the accuracy, sensitivity, and specificity are 74%.
Insights From the Model and Business Recommendations
Based on the discriminant coefficients and the correl_ratio provided by the model, an increase in the below variables increases the probability of customer churn:
Number of customer service calls
Total day charge
Total evening charge
Total international charge
Total night charge
Additionally, an increase in number of voice mail messages decreases the probability of customer churn.
These insights from the discriminant model can help the business formulate strategies to reduce customer churn. Here's what I would recommend to the business based on what we've learned: First, customer issues should be resolved within the first or second call, as repeated calls to customer service causes customer churn. Second, there should be an organized escalation procedure for issues not resolved within two calls. Lastly, the provider should offer more attractive plans that reduce the cost of day, evening, and international calls based on usage.