Untitled

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

from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import LabelEncoder
from collections import defaultdict
from joblib import dump
import pandas as pd

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).

# Load Data
dbconn = pq.dbconnect('dw_123')
df = dbconn.fetch('db_name', 'schema_name', 'customers', df = True)

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.

# Show a title (st = Streamlit module)
st.title("Churn Prediction")

# Show some text
st.text("Sample data")

# Show the dataframe
st.dataframe(df.head(), use_container_width=True)

This is what the output looks like:

Untitled

Here’s our code in the Peliqan low-code editor, with a preview:

Untitled