Customer churn prediction

Customer Churn Prediction: A Beginner-Friendly Mini Project

Picture a bucket full of water. New water pours in from the top every day. But if the bucket has even one small crack, water leaks out from the bottom too. That leak is quiet. Nobody notices it right away. Only later, when the bucket looks half empty, does anyone realize something went wrong.

Every business faces the same problem. Customers pour in every month. However, some of them leave quietly through the cracks. In business language, that leak has a name: churn. And the moment you can spot the crack, you can fix it before it costs you.

This article walks through a hands-on mini project that predicts customer churn from start to finish. It follows Episode 52 of the Intelevo machine learning series, so watch the full video first if you prefer a spoken walkthrough. This write-up will still make sense on its own, though, so let’s dive in.

What Is Customer Churn?

Churn simply means a customer stops doing business with you. They cancel a subscription. They switch to a competitor. Or they just stop paying and disappear.

You have likely experienced churn yourself, even without noticing the term. A streaming platform loses a viewer when someone cancels their plan. A telecom company loses a subscriber when they port their number elsewhere. A bank loses a customer when an account slowly goes inactive and finally closes.

In every case, the pattern stays the same. A customer walks away, and the business loses future revenue. That is exactly what customer churn prediction tries to stop before it happens.

Why Customer Churn Prediction Matters

Here is a number worth remembering: winning a new customer costs roughly five times more than keeping an existing one. Therefore, even a small drop in churn can protect a large chunk of revenue.

Most companies discover churn only after it happens. A customer cancels, and the team reacts too late. Customer churn prediction flips that timeline. Instead of reacting, a business can act early, while the customer still has a reason to stay.

This is exactly why churn prediction sits at the center of so many real-world data science projects. It combines everything a beginner learns early on: data exploration, data cleaning, a train-test split, a working model, and a clear business outcome.

Beginners often assume customer churn prediction needs advanced math or years of experience. It does not. As this article shows, a handful of familiar steps, applied in the right order, can produce a genuinely useful model. That accessibility is exactly what makes churn prediction such a rewarding first mini project.

Meet the Dataset

This project uses a real-world telecom dataset. Each row represents one customer, and each column captures something about their relationship with the company. Here are the key columns:

  • tenure: how many months the customer has stayed so far
  • MonthlyCharges: how much the customer pays each month
  • Contract: month-to-month, one year, or two year
  • InternetService: DSL, fiber optic, or none
  • PaymentMethod: how the customer pays their bill
  • Churn: the target column, marked Yes or No

This dataset works well for a mini project because it mixes numeric columns with categorical ones. Consequently, it gives beginners real practice at cleaning mixed data types before modeling anything.

Step 1: Explore the Data First

Before touching a single line of modeling code, always look at the data first. A quick check on the Churn column reveals something important: about 73% of customers stay, while only 27% churn.

That imbalance matters a lot. A lazy model could predict “stays” for every customer and still score 73% accuracy, without learning anything useful at all. Keep that number in mind. We will return to it later, when accuracy alone starts to look misleading.

The exploration step also reveals a strong pattern. Customers on month-to-month contracts churn about three times more often than customers locked into a one-year or two-year contract. That single insight already tells a business something actionable, even before any model gets built.

Step 2: Prepare the Data

A model cannot read text. It only understands numbers. So before training anything, the data needs two quick transformations.

First, encode the categorical columns. A column like Contract, which contains values such as “month-to-month” or “two year,” becomes a set of numbers instead. Second, scale the numeric columns. Tenure and MonthlyCharges sit on very different number ranges, so scaling puts them on a level playing field. Otherwise, one column could unfairly dominate the model simply because its numbers happen to be bigger.

Think of this step as translation. You are turning human-readable labels into a numeric language the model can actually compare.

Step 3: Split into Train and Test

Next, hold some customers back. This step, called a train-test split, keeps the model honest.

Eighty percent of the data becomes the training set. The model studies these customers and learns which patterns lead to churn. The remaining twenty percent becomes the test set. Crucially, the model never sees this portion during training. It acts as a surprise quiz later, showing exactly how the model performs on customers it has never encountered before.

This split matters because a model that memorizes its training data can look great on paper. However, it might fail completely on new customers in the real world. The test set protects against that false confidence.

Step 4: Build the Model

Now for the model itself: Logistic Regression. Despite the name, it solves a classification problem, not a regression one. It predicts whether a customer belongs to the “churn” group or the “stay” group.

Here is the mental shift that makes this easier to understand. Logistic Regression does not shout a flat yes or no. Instead, it quietly turns every customer’s numbers into a risk score between 0 and 1, similar to a dial rather than an on-off switch.

The formula behind it looks like this:

probability of churn = 1 / (1 + e^-z)

Do not worry about memorizing this formula. Just remember what it does: it squeezes any input into a tidy score between zero and one. Once that score exists, a simple rule decides the outcome. A score above 0.5 gets flagged as “likely to churn.” A score below 0.5 gets treated as “likely to stay.”

For example, imagine a customer with a month-to-month contract, only three months of tenure, and high monthly charges. That combination might produce a risk score of 0.81, well above the threshold. The model flags that customer immediately, giving the business a clear early warning.

Step 5: The Full Pipeline in Python

All six steps come together in just a few lines of Python. Here is the complete mini project, written with scikit-learn:

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report

X = data.drop(columns=['Churn'])         # features
y = data['Churn']                        # target

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42)

model = LogisticRegression()
model.fit(X_train, y_train)              # learn

predictions = model.predict(X_test)      # apply
print(classification_report(y_test, predictions))

Let’s break this down line by line. First, three imports bring in the tools needed: train_test_split divides the data, LogisticRegression builds the model, and classification_report measures performance afterward.

Next, the code separates features from the target. X holds every column except Churn, while y holds only the Churn column, since that is what the model needs to predict. After that, train_test_split creates the 80/20 division discussed earlier, using a fixed random_state so the split stays repeatable every time the code runs.

Then comes the learning step. model.fit() studies the training data and adjusts itself to find the patterns that separate churners from loyal customers. Finally, model.predict() applies everything it learned to the unseen test data, and classification_report() prints a clear summary of how well it performed.

Six steps, six lines. That is the entire mini project compressed into working code.

Step 6: Evaluate Beyond Accuracy

Remember that 73/27 imbalance from earlier? This is exactly where it comes back into play. Accuracy alone can lie, so a better tool called the confusion matrix tells the full story instead.

A confusion matrix splits every prediction into four buckets:

  1. True Negative — predicted stay, and the customer actually stayed
  2. False Positive — predicted churn, but the customer actually stayed
  3. False Negative — predicted stay, but the customer actually churned
  4. True Positive — predicted churn, and the customer actually churned

Out of these four outcomes, one deserves extra attention: the false negative. Telling a customer “you’re fine” right before they leave is the costliest mistake a business can make, because it gives zero warning and zero chance to react.

That is why data scientists watch a metric called recall closely. Recall measures the share of actual churners that the model successfully caught. In a churn project, a high recall score often matters more than raw accuracy, since missing a churner costs far more than a false alarm.

What Drives Churn the Most?

Beyond predictions, Logistic Regression can also explain itself. It reveals which features carried the most weight in its decisions.

In this project, Contract type turned out to be the strongest driver of churn, followed by tenure, then monthly charges, internet service, and finally payment method. This detail transforms the model from a mysterious black box into a clear story. It does not just predict who might leave. It also explains why.

From Prediction to Action

A prediction alone saves nobody. It only becomes valuable once it changes what the business actually does next. Here are four practical ways to act on a churn model:

  • Target the top 10%: Sort customers by risk score, then focus retention effort where it matters most.
  • Offer personalized deals: A high-risk, high-value customer might respond well to a loyalty discount or a plan upgrade.
  • Reach out proactively: A quick support call before a customer even considers leaving can make a real difference.
  • Fix the root cause: If month-to-month contracts drive most of the churn, it might be time to redesign those contract options entirely.

In short, the model works best as a starting point for action, not as a final answer on its own.

Common Mistakes to Avoid

Even a simple mini project like this one can go wrong in predictable ways. Here are a few pitfalls worth watching for during any customer churn prediction exercise.

Trusting accuracy blindly. As shown earlier, a 73/27 imbalance lets a lazy model look accurate while learning nothing. Always check recall and precision alongside accuracy, especially when one outcome is rarer than the other.

Skipping the exploration step. It might feel tempting to jump straight into modeling. However, skipping exploration means missing patterns like the month-to-month contract effect, which often turns out to be the most useful insight in the entire project.

Forgetting to scale numeric features. A column like MonthlyCharges can quietly dominate a model if it never gets scaled against smaller-range columns like tenure. That imbalance skews results in subtle, hard-to-diagnose ways.

Testing on training data. This mistake inflates performance numbers and hides real weaknesses. The train-test split exists specifically to prevent this, so never skip it, even for a “quick” experiment.

Stopping at the prediction. A churn score means nothing until a team acts on it. Always connect the model’s output back to a real business decision, whether that means a retention offer, a support call, or a contract redesign.

Avoiding these five mistakes turns a fragile classroom exercise into a churn prediction workflow that actually holds up in the real world.

Frequently Asked Questions

Is Logistic Regression the only model suitable for customer churn prediction? No. Logistic Regression works well as a first model because it stays simple and explainable. However, other models, such as decision trees or gradient boosting, can also handle churn prediction, often with a small accuracy boost at the cost of interpretability.

How much data does a churn prediction project need? There is no fixed number, but more historical examples generally help the model learn stronger patterns. This project uses a full telecom dataset with thousands of customer records, which gives the model enough signal to work with.

Why does recall matter more than accuracy here? Because a missed churner, a false negative, usually costs more than a false alarm. Recall directly measures how many actual churners the model catches, so it maps more closely to real business risk than accuracy alone.

Key Takeaways

Let’s tie everything together. This entire mini project boils down to six familiar steps:

  1. Explore the data first
  2. Prepare the features
  3. Split into train and test
  4. Fit a Logistic Regression model
  5. Evaluate using recall, not just accuracy
  6. Act on the resulting risk score

None of these steps require new skills. In fact, that is the real takeaway here. Customer churn prediction is not some advanced, unfamiliar technique. It is the exact same pipeline used throughout this ML series, simply pointed at a new business question.

What’s Next

The next episode tackles an important follow-up question: was that 80/20 split lucky, or was it actually reliable? A single test set can sometimes flatter a model, or it can judge it unfairly harshly. Episode 53 covers Cross-Validation Techniques, including K-Fold and Stratified methods, so you can trust your model’s score with far more confidence.

Watch the Full Video

This article summarizes Episode 52 of the Intelevo machine learning series. For the complete walkthrough, along with visual explanations and a live code demo, watch the full video on the Intelevo YouTube channel. If this project helped you understand customer churn prediction more clearly, please like the video, subscribe to the channel, and leave your thoughts in the comments. Every bit of feedback helps shape future episodes.

Leave a Comment

Your email address will not be published. Required fields are marked *