DEV Community

Cover image for Building a Customer Churn Prediction Model with Logistic Regression
Nnamdi Nnanna
Nnamdi Nnanna

Posted on

Building a Customer Churn Prediction Model with Logistic Regression

This week, I worked through Module 3: Machine Learning for Classification in ML Zoomcamp 2026.

The goal was to build a model that could help a telecom company identify customers who were likely to leave. Working through the project helped me connect several machine learning concepts to a practical problem.

What I worked on

  1. Data preparation and exploratory data analysis

I explored the Telco customer churn dataset, examined the target variable, checked missing values, and looked at how different features were distributed.

  1. Feature importance

I learned different ways to understand the relationship between features and customer churn:

  • Risk ratio and risk difference for categorical variables
  • Mutual information to measure how informative categorical features are about the target
  • Correlation coefficients to examine relationships between numerical features

One finding that stood out was that contract type had the highest mutual information among the categorical features we examined.

  1. One-hot encoding with DictVectorizer

Since machine learning models need numerical inputs, I used Scikit-Learn's "DictVectorizer" to convert categorical features into numerical representations. This produced a feature matrix with 45 columns.

  1. Training a logistic regression model

I trained a logistic regression model using Scikit-Learn and achieved approximately 80% accuracy on the validation set.

I also explored how to interpret the model's weights, trained a smaller model using selected features, and worked through how to calculate a prediction manually.

What I learned

The biggest lesson for me was understanding how the different stages of a machine learning project connect.

Feature analysis helps us understand the data. Encoding prepares it for the model. Logistic regression uses those features to estimate the probability of a customer churning, and evaluation helps us understand how well the model performs.

I also learned that the same classification workflow can be applied to other problems, such as spam detection, loan default prediction, and lead scoring.

What's next?

I'm moving on to Module 4: Evaluation Metrics for Classification, where I'll learn more about measuring model performance and understanding what accuracy alone might not tell us.

I'm taking this journey one concept at a time, with the goal of understanding the reasoning behind the code rather than simply getting it to run.

MachineLearning #DataScience #Python #MLZoomcamp #LearningInPublic

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.