Sitemap

What If Your Customers Are Quietly Leaving…?? (Part — 2)

An End-to-End Customer Churn Analysis Project

The first part of this project focused on building the foundation : loading and cleaning the customer data in SQL Server, transforming it in Power BI, creating DAX measures, and analyzing historical churn through interactive dashboards.

Here you can read the part 1 : https://medium.com/@DhanashriPetkar/what-if-your-customers-are-quietly-leaving-part-1-ac32ab0e06b9

Now that we understand who churned, how churn varied across different customer segments, and some of the possible reasons behind it, we can move to the next stage.

Press enter or click to view image in full size

Step 11 : Building the Churn Prediction Model

The project uses a Random Forest Classifier to predict customer churn. If you’ve never heard of Random Forest, don’t let the name scare you. It’s basically an ensemble of multiple decision trees.

Press enter or click to view image in full size

Instead of relying on one decision tree to make the prediction, Random Forest combines the decisions of many trees. The idea is that combining multiple trees can produce a more robust prediction than relying on a single tree.

In this project, the target variable is :

Customer Status

which is converted into :

  • 0 → Stayed
  • 1 → Churned

So the Machine Learning model is essentially learning :

“Based on everything I know about this customer, does this customer look more like someone who stays or someone who churns…??”

Pretty cool, right…??

Step 12 : Preparing Data for Machine Learning

Before training the model, the data needs to be converted into a format that Machine Learning algorithms can understand. Several columns are categorical. For example :

  • Gender
  • State
  • Contract
  • Internet Type
  • Payment Method
  • Phone Service

A Random Forest model cannot directly work with text categories in the same way humans understand them.

So categorical variables are converted into numerical representations using Label Encoding.

The target variable is also converted :

Stayed → 0

Churned → 1

The dataset is then separated into :

X → Features and y → Target

In simple words :

X contains the information about the customer.

y contains the answer we want the model to learn.

Then the dataset is split into training and testing sets, with 80% used for training and 20% for testing.

Step 13 : Training the Random Forest Model

The Random Forest classifier is configured with 100 decision trees and then trained on the training data. Once training is complete, the model makes predictions on the test dataset. But, we can’t just say : “The model predicted something.” and call it a day. (even if you can, DO’NT…)

We need to evaluate it.

Step 14 : Evaluating the Model

The project evaluates the model using :

  • Confusion Matrix
  • Classification Report

The confusion matrix helps us understand how many predictions were correct and incorrect for each class.

The classification report provides additional metrics such as :

  • Precision
  • Recall
  • F1-score

These metrics are particularly important in churn prediction.

Why…??

Because predicting churn isn’t just about overall accuracy.

Imagine the model is 90% accurate. Sounds amazing. But what if it is terrible at identifying actual churners…?? Then the model isn’t very useful for the business.

If the whole purpose is to identify customers who might leave, we care about how effectively the model identifies that group.

This is where evaluation becomes much more important than simply saying : “My model has 90% accuracy.” with a dramatic hair flip.

Step 15 : Which Features Matter Most…??

The project also looks at feature importance from the Random Forest model. This is interesting because now we can ask :

Which customer characteristics are contributing most to the model’s churn predictions…??

Features might include things related to :

  • Contract
  • Tenure
  • Monthly charges
  • Services
  • Payment method
  • Demographics
  • Customer behavior

Feature importance doesn’t mean :

“This variable definitely causes churn.”

That’s an important distinction. It means the model found that the feature was useful for making predictions.

And honestly, this is one of the parts of Machine Learning that I find most interesting.

We’re not just predicting.

We’re also trying to understand what information the model is using.

Step 16 : Predicting Future Churners

Press enter or click to view image in full size

Now comes the actual business application. The model has learned from customers whose outcomes are already known. But what about customers who recently joined…?? We don’t yet know whether they will churn. That’s where the second SQL view comes in :

vw_JoinData

The project loads this data into the prediction workflow and applies the trained Random Forest model. The model generates :

Customer_Status_Predicted

Then the customers predicted as churners are filtered and saved into a new prediction dataset.

And now…

We have something much more useful than historical analysis.

We have a list of customers who may be at risk of leaving.

Step 17: Bringing Predictions Back into Power BI

The final step is to bring these predicted churners back into Power BI. And this creates a completely new dashboard page :

Churn Prediction

Instead of analyzing customers who have already churned, this page focuses on customers predicted to churn.

The dashboard can show details such as :

  • Customer ID
  • Monthly Charge
  • Total Revenue
  • Total Refunds
  • Number of Referrals
  • Gender
  • Age Group
  • Marital Status
  • Payment Method
  • Contract
  • Tenure Group
  • State

This is where the project finally connects analytics with business action. Because now a marketing or customer-success team could potentially say : “These are the customers we should investigate first.”

And THAT is the difference between Data analysis and Decision support.

The Complete Project Architecture

So after going through the entire workflow, the project can basically be summarized like this :

Customer Data → SQL Server → Staging Table → Data Exploration → Data Cleaning → Production Table → SQL Views → Power BI Transformation → DAX Measures → Historical Churn Dashboard → Python + Random Forest → Future Churn Prediction → Predicted Churner Dataset → Power BI Prediction Dashboard

And when you look at it this way…

It’s actually a pretty complete data analytics pipeline.

Not just a dashboard.

Not just a Machine Learning model.

Not just SQL.

It’s all of them working together ❤️.

Press enter or click to view image in full size
Ta — Da…!!

What I Learned From This Project

There were quite a few things I took away from this project.

1. A dashboard is only the visible part of analytics

When people see a Power BI dashboard, they usually notice :

Charts.

Cards.

Colors.

Filters.

Maps.

But they don’t see everything underneath.

Get Dhanashri Petkar’s stories in your inbox

Join Medium for free to get updates from this writer.

The database.

The transformations.

The calculations.

The data model.

The cleaning.

The validation.

The SQL queries.

That’s where a huge part of the actual work happens.

The dashboard is basically the final window through which someone sees all that work.

2. SQL and Power BI complement each other

I used to think of SQL and Power BI as somewhat separate skills.

Projects like this make the relationship much clearer.

SQL is excellent for :

  • Data storage
  • Data cleaning
  • Data transformation
  • Filtering
  • Aggregation
  • Creating views

Power BI is excellent for :

  • Data modeling
  • Measures
  • Interactive visualization
  • Dashboarding
  • Business reporting

Together, they create a much stronger workflow.

3. Machine Learning doesn’t replace analytics

This one is important. It would be very easy to jump straight to “Let’s train a Random Forest and predict churn.” But without understanding the data first, the model doesn’t have much meaning.

Press enter or click to view image in full size

Before prediction comes :

Data understanding.

Then :

Data cleaning.

Then :

Exploration.

Then :

Feature preparation.

Then :

Modeling.

And finally :

Evaluation.

Machine Learning is one piece of the pipeline.

It isn’t the entire pipeline.

4. Predicting churn is not the same as preventing churn

Press enter or click to view image in full size

This is probably my favorite takeaway. A model can tell us :

“This customer looks likely to churn.”

But it doesn’t automatically tell us :

“Here’s exactly what will make this customer stay.”

That’s where business strategy comes in. The prediction identifies the customers who may need attention. Then the business needs to decide what action to take.

Maybe :

  • Offer a better plan
  • Provide a discount
  • Improve support
  • Offer a contract incentive
  • Address service problems
  • Provide a personalized retention campaign

The model identifies the risk.

People still have to decide what to do about it.

From “Who Left…??” to “Who Might Leave Next…??”

Press enter or click to view image in full size

And I think that’s what makes this project particularly interesting. At the beginning, we’re simply looking at historical data. We ask :

Who churned…??

Then we move deeper :

Why did they churn…??

Then :

What characteristics do churned customers have in common…??

And finally :

Who might churn next…??

That’s a very natural progression :

Descriptive → Diagnostic → Predictive

And that progression is one of the biggest things I learned from this project.

Final Thoughts

When I started looking at this project, I initially thought :

“Okay… it’s just a churn dashboard.”

But after going through the entire workflow, I realized it’s much more than that. It’s a complete example of how different parts of Data Science and Analytics can work together.

SQL handles the data foundation.

Power BI turns the cleaned data into interactive business intelligence.

Python handles the Machine Learning side.

Random Forest helps predict future churners.

And finally, Power BI brings those predictions back into a form that business teams can actually understand and use.

And that’s probably my biggest takeaway :

Data analysis isn’t just about finding numbers.

It’s about creating a chain that goes from :

Raw Data to Information to Insight to Prediction to Action.

Because at the end of the day, knowing that customers are leaving is useful.

Knowing why they’re leaving is better.

But being able to identify customers who might leave next…??

Now we’re talking. And honestly, that’s the part of Data Science that makes me want to keep digging deeper…

Tech Stack

Database : Microsoft SQL Server

Visualization and BI : Microsoft Power BI

Programming Language : Python

Machine Learning model : Random Forest Classifier

Python Libraries :

  • Pandas
  • NumPy
  • Matplotlib
  • Seaborn
  • Scikit-learn
  • Joblib

Key Concepts :

  • ETL
  • Data Cleaning
  • SQL Views
  • Data Transformation
  • Data Modeling
  • DAX
  • KPI Analysis
  • Customer Segmentation
  • Churn Analysis
  • Data Visualization
  • Machine Learning
  • Classification
  • Feature Importance
  • Predictive Analytics

If you’re working with customer data, I’d love to know :

Would you rather know why customers left… or know who is going to leave next…?? (iykyk 💀)

Because apparently, after this project, my answer is :

Why not both…?? 😉

✍️ Thanks for reading till here…!!
If you liked this blog, leave a 👏 or a comment.
If you want the GitHub repo, tutorial, or want to collab — just hit me up…!!

Let’s build things that make a difference, not just features.

– Dhanashri 💜

See more from me