Monday, December 18, 2017

Churn Prediction Using Machine Learning -- Take Two


This is another attempt to use tenant metrics to predict if tenant is going to churn.
The thinking is, that normal tenant’s lifecycle is:
  1. Ramp-up (irregular behavior)
  2. Normal behavior
  3. Optional churn (deviation from normal)

Approach:
Learn by looking at churned tenants:
Take one year of tenant’s metrics after the tenant has ramped up and before it churned.  First 6 months of that year is normal behavior.  Fit normal behavior into a linear function e.g.
y = a + xb

Look at the last 6 months of that year.  Does it still fit the same function?  If it’s growing less or declining it’s a sign of churn.

Specifically look at metrics such as active accounts, active subscriptions.

Example

This is an example of tenant metrics chart:
Chart shows that tenant metric stopped growing considerably earlier than churn event (churn is end of chart’s X axis).

Tools

Anaconda python distribution https://anaconda.org/anaconda/python
Jupyter notebooks http://jupyter.org/
Sklearn toolkit http://scikit-learn.org/
Redshift (Tenant metrics was put into redshift where it was transformed as needed and then exported for analysis.)

Results

Results were not conclusive, and model accuracy wasn’t high enough.  In some cases data was not helpful (meaning that tenant metrics were not indicative of tenant’s churn).


On the positive note, learned a little about sklearn and pandas.  When used in a jupyter notebook, it’s the most awesome and simple interactive machine learning environment I’ve seen, here are a couple of illustrative screenshots:


Using Machine Learning to Detect Customer Churn


My company collects daily tenant metrics that include variables like Payments, Total Amount Invoiced, Tenant Status.  Metrics are collected daily for all tenants, and metrics history is kept indefinitely.


Can we use tenant metrics to predict which tenants will churn next?

High-Level Approach 

Divide the metrics into two parts:
  • Metrics for tenants that churned (Churned Dataset)
  • Metrics for tenants that didn’t churn (Active Datase

Use Churned Dataset to train the model about churn.
AWS ML automatically subdivides the dataset into two parts, by default:
  • 70% for training
  • 30% for validation
Use Active Dataset to predict churn.




Detailed Approach

Obtain Tenant Metrics

We obtained a sample of these metrics (500M) from production.  


Dataset contains daily metrics about:
614 tenants
116 active
145 churned
352 ignored (e.g. trial, employee test tenants)
 

Prepare Data


Write a program to divide the dataset in 2:
  • Churned tenants
  • Active tenants
Same program also
  • Converts date into account length, and into “days to churn”
  • Normalizes all metrics by converting them “percentage growth from yesterday” times 1,000
  • Limits growth or decline to +/- 100,000
  • Removes trailing records for churned tenants only keeping records until day of churn
  • Removes tenant name from churn dataset
  • Remove “days to churn” from active dataset

Create AWS Machine Learning Datasource

Target attribute (the one we’re trying to predict) is “days to churn” (named Date in the model).

Create “Churned Tenants” datasource and use Date as the target attribute (i.e. predict days to churn).
 

Create AWS Machine Learning Model

Create “Churned Tenants” ML Model

Train AWS Machine Learning Model


We trained the model on the churned tenants dataset.  

AWS uses 70% of the data to train, and 30% to validate the model.

Recipe

Model had a fairly high error: RMSE of 583 days, which means individual predictions can be off by that many days.  However the thought is, for a given tenant, given many records, average prediction would be a little more accurate.
AWS ML chose linear regression with multiple variables to predict days to churn.  The below is the “recipe” it came up with, showing which columns were used, and which had higher weight.

{
 "groups" : {
   "NUMERIC_VARS_QB_50" : "group('Total_Payments_Received_converted')",
   "NUMERIC_VARS_QB_500" : "group('Orders','Products','Total_Electronic_Payments_Received_converted','Subscriptions','Active_Accounts','Amendments','Electronic_Payments','Adjustments','Invoices','Users','Active_Subscriptions','Payment_Methods','Bill_Runs','Usage_Record_Uploads','Cancelled_Subscriptions','Total_Amount_Invoiced_converted','Total_Accounts','Data_Sources_Exports','Active_Payment_Gateways','Refunds')",
   "NUMERIC_VARS_QB_200" : "group('Rate_Plans','Payments','Payment_Gateways','Total_Amount_Refunded_converted','Total_Account_Balance_converted','Currencies')",
   "NUMERIC_VARS_QB_10" : "group('Edition')"
 },
 "assignments" : { },
 "outputs" : [ "ALL_CATEGORICAL", "quantile_bin(NUMERIC_VARS_QB_50,50)", "quantile_bin(NUMERIC_VARS_QB_500,500)", "quantile_bin(NUMERIC_VARS_QB_200,200)", "quantile_bin(NUMERIC_VARS_QB_10,10)" ]
}

Generate Predictions for Active Tenants

We passed metrics for active tenants into the model, and computed the days to churn for each daily metric of every active tenant.

Then we averaged the predictions for each tenant.

Summary: what was learned

It remains to be understood what is the best approach to transform tenant metrics into best shape for predicting churn.  The weakness of our approach was assumption that days_to_churn has some correlation to today’s changes in tenant metrics (even though smoothed out and scaled).  While there is some correlation (e.g. less money going through the system, less usage) the key challenge is how to build a machine learning model that is accurate.

We ran out of time allotted for the hackathon, and didn’t try out these potentially promising ideas:
  • Normalize days to churn so it has the same range for all tenants (would require us to scale data for tenants)
  • Smooth out metrics using approaches like moving averages or other
  • Brainstorm other ideas for analyzing time series
  • Consider taking only last N days before churn for churned tenants, and active tenants
  • Consider other machine learning approaches beside linear regression
    • Clustering (e.g. find similarity to churned tenants rather than predict days)
    • Neural networks

Tools Used

Java for cleaning and preparing data
Excel (pivot table)
AWS Machine Learning
Csvkit (command line csv tools)
Unix command line (cut, paste, grep)