<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/predict-customer-churn-with-gradient-boosting/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.displayr.com/predict-customer-churn-gradient-boosting/?utm_medium=Feed&utm_source=Syndication"> R – Displayr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>Customer churn is a key predictor of the long term success or failure of a business. But when it comes to all this data, what’s the best model to use? This post shows that gradient boosting is the most accurate way of predicting customer attrition.</strong><strong> I’ll show you how you can create your own data analysis using gradient boosting to identify and save those at risk customers! </strong></p>
<h2><img sizes="(max-width: 778px) 100vw, 778px" src="https://i1.wp.com/www.displayr.com/wp-content/uploads/2017/07/customer-churn-edit.jpeg?w=450&ssl=1" alt="" class="wp-image-5391" data-recalc-dims="1"></h2>
<h2>Why predict customer churn?</h2>
<p>Customer retention should be a top priority of any business as acquiring new customers is often far more expensive that keeping existing ones. It is no longer a given that long standing customers will remain loyal given the numerous options in the market. Therefore, it is vital that companies can proactively determine the customers most at risk of leaving and take preventative measures against this.</p>
<p>Predictive models for customer churn can show the overall rate of attrition, while knowledge of how the churn rate varies over a period of time, customer cohort, product lines and other changes can provide numerous valuable insights. Yet, customers also vary enormously in their behaviors and preferences which means that applying a simple “rule of thumb” analysis will not work. Here’s where a predictive model using gradient boosting can help you.</p>
<p>First, I’m going to describe the data. Then I’ll use <em>gradient boosting</em> to predict who will churn and who will stay. Finally I’ll benchmark my result against other models.</p>
<h2>The data</h2>
<p>I’ll aim to predict<em> Churn</em>, a binary variable indicating whether a customer of a telecoms company left in the last month or not.</p>
<p>To do this I’ll use 19 variables including:</p>
<ul>
<li>Length of tenure in months.</li>
<li>Types of services signed up for such as phone, internet and movie streaming.</li>
<li>Demographic information.</li>
<li>Monthly charges, type of contract and billing.</li>
</ul>
<p>The full data set is available <a rel="nofollow" href="https://community.watsonanalytics.com/wp-content/uploads/2015/03/WA_Fn-UseC_-Telco-Customer-Churn.csv" target="_blank">here</a>.</p>
<p>The breakdown of <em>Churn </em>is shown below. If we predict <em>No </em>(a customer will not churn) for every case, we can establish a baseline. Our baseline establishes that 73% is the minimum accuracy that we should improve on.</p>
<p><iframe width="206.03" src="https://embedded.azureedge.net/75668/212296/937135e0-6955-4e9a-8572-1bf7744b4af6.html?v=34784434422678" height="158.62"><span data-mce-type="bookmark">﻿</span></iframe></p>
<h2>Gradient boosting</h2>
<p>In <a rel="nofollow" href="https://www.displayr.com/gradient-boosting-the-coolest-kid-on-the-machine-learning-block" target="_blank">this earlier post</a> I explained gradient boosting. Gradient boosting sits alongside regression, decision trees, support vector machines and random forests. They are all supervised learning algorithms capable of fitting a model to train data and make predictions.</p>
<p>A common strategy when working with any of these models is to split the data into a training sample and a testing sample. The model learns the associations between the predictor variables and the target outcome from the training sample. The testing sample is used to provide an unbiased estimate of the prediction accuracy on unseen data.</p>
<p>I randomly split the data into a a 70% training sample and a 30% testing sample. I then perform gradient boosting with an underlying tree model. The chart below shows the 10 most important variables. We learn that having a monthly contract, length of tenure and amount of charges are useful predictors of churn.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/212296/1620f5ea-21bf-4fd6-a159-61089f43a593.html?v=28070-f9eb6565a0-931163598"></iframe></p>
<h2>How accurately can we predict customer churn with gradient boosting?</h2>
<p>Gradient boosting has various internal parameters know generically as hyper-parameters. These settings determine the size of the underlying trees and the impact that each round of boosting has on the overall model. It can be time consuming to explore all of the possibilities to find the best values. To create the model below I automatically performed a grid search of 36 different combinations of hyper-parameters. I selected the best set by 5-fold cross validation.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/212296/6808ca09-4539-480b-ad3b-3fc0b7094788.html?v=347841101681789"></iframe></p>
<p>We’ve already established that our baseline when always predicting that a customer will not churn is 73%. This amounts to a shot in the dark when trying to determine whether or not a customer will churn. Not great, right? However, when we can input more information like different variables such as a person’s bills, their contract length or tenure and their comfort level with the technology, we can learn much more about this customer.</p>
<p>From this information, we can more accurately pinpoint who will churn and our prediction accuracy rises by 8% to 80.87%. This gives us a much greater edge in being able to identify the factors that may lead to customer attrition and more of an edge when it comes to the crucial business of customer retention!</p>
<h2>Why choose gradient boosting over other models?</h2>
<p>In the same way that I just fitted a gradient boosting model, we can fit other models. I tried 3 other approaches. Each time I followed the same procedure as above, selecting the same variables, fitting with the training sample and calculating accuracy from the testing sample. The results are:</p>
<table>
<thead>
<tr>
<th>Model</th>
<th>Accuracy</th>
</tr>
</thead>
<tbody>
<tr>
<td>Gradient Boosted Tree</td>
<td>80.87%</td>
</tr>
<tr>
<td>CART</td>
<td>79.21%</td>
</tr>
<tr>
<td>Random Forest</td>
<td>79.94%</td>
</tr>
<tr>
<td>Linear Discriminant Analysis</td>
<td>79.97%</td>
</tr>
</tbody>
</table>
<p></p>
<p><strong>Whilst this is not a comprehensive comparison, gradient boosting performs the best amongst these models with the highest accuracy score.</strong></p>
<hr>
<p><span>TRY IT OUT</span><br>
The analysis in this post was performed in <a rel="nofollow" href="http://www.displayr.com/" target="_blank">Displayr</a> using R. The <a rel="nofollow" href="https://github.com/Displayr/flipMultivariates" target="_blank"><span>flipMultivariates</span></a> package, which uses the <span>xgboost</span> package, performs the machine learning calculations. You can <a rel="nofollow" href="https://app.displayr.com/Try/Churn%20Prediction" target="_blank">try this analysis</a> for yourself in Displayr.</p>
<hr>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.displayr.com/predict-customer-churn-gradient-boosting/?utm_medium=Feed&utm_source=Syndication"> R – Displayr</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/y64AgsVHlcI" height="1"></a></div>