Skip to main content
image Predict which customers are likely to cancel (churn) in order to proactively take measures to retain them. We will train a machine learning (ML) model based on historical customer data (including a column that indicates if the customer churned), in order to predict likelihood of churn for current customer. Churn prediction is crucial for businesses relying on recurring revenue. It identifies customers likely to stop using a product or service. The process involves analyzing a large amount of customer data to identify at-risk customers. This can be complex due to the need to identify patterns and trends. Here is an example on how to build an ML model in Peliqan.io with a few lines of Python code.

Import required modules

Load a dataset

Load data from a table into a dataframe (df). The table needs to contains customer data, including an indication if these customers churned (historical data).
Refer to Peliqan Docs to explore all available functionality.

Using Streamlit to build an app

We use the Streamlit module (st), built into Peliqan.io, to build a UI and show data.
This is what the output looks like: image Here’s our code in the Peliqan low-code editor, with a preview: image

Explore and prepare the data

Always look for missing values and try to handle them.
There are no missing values in our dataset. If they are present you might want to handle them by replacing or dropping them. For more info on how to handle missing values click here. Now we can start by exploring the distribution of the target variable (churn class in our case) to see if the target variable has a balanced distribution.
image The target variable has an imbalanced class distribution. The positive class (Churn=Yes) is much smaller than the negative class (churn=No). An imbalanced class distributions influence the performance of a machine learning model negatively. We will use upsampling or downsampling to overcome this issue. First we’ll convert categorical data into numerical data so that the ML model can understand it and we’ll do upsampling to handle an unbalanced dataset.
To learn more about upsampling click here. image

Model Training & Evaluation

We will use Random Forest Classifier to do the prediction. To learn more visit SKlearn.
To learn more about evaluating your models visit SKlearn. You can use any classification algorithm to solve similar problems. Expand this to see the full code
image

Next Steps

  1. Using Peliqan you can create an app for business users to consume the model you have made in a simple and intuitive UI. Learn more about creating apps for users to consume your ML model.
  2. You can make predictions on real-time incoming data using the saved model. Learn more about making real-time predictions on new incoming data.
  3. You can make real-time predictions on new incoming data and send alerts to slack if the model makes a prediction above a certain threshold.