When I started working on customer churn prediction, it was tempting to focus on the model: try Logistic Regression, try Random Forest, then compare the scores.

But a model is only one part of the work. Before training anything, you need to decide what “churn” means, check that the data makes sense and choose a way to evaluate the model that reflects the problem you’re trying to solve.

Here’s the workflow I use to think through a churn project in Python.

First, decide what counts as churn

“Churn” can mean different things depending on the business. For a subscription service, it might mean a customer cancelled. For another product, it could mean that a customer stopped buying or using the service for a set period.

That definition affects the whole project, so it’s worth making it explicit.

There’s also a timing question: when are you trying to make the prediction? If you want to identify customers who might leave next month, your features should only include information that would have been available before that month. Including information recorded after a customer leaves can make a model look better than it really is.

Get the data ready

Churn datasets often mix numerical columns, such as tenure or monthly charges, with categories like contract type or payment method. Those need slightly different treatment.

Here’s a basic scikit-learn setup. It fills missing values, scales numerical features and encodes categorical ones. In this example, the target column is called Churn; change that if your dataset uses a different name.

import pandas as pd from sklearn.compose import ColumnTransformer from sklearn.impute import SimpleImputer from sklearn.pipeline import Pipeline from sklearn.preprocessing import OneHotEncoder, StandardScaler df = pd.read_csv("customer_churn.csv") target = "Churn" X = df.drop(columns=[target]) y = df[target] categorical_columns = X.select_dtypes( include=["object", "category"] ).columns numerical_columns = X.select_dtypes( include=["number"] ).columns preprocessor = ColumnTransformer( transformers=[ ( "numeric", Pipeline([ ("imputer", SimpleImputer(strategy="median")), ("scaler", StandardScaler()), ]), numerical_columns, ), ( "categorical", Pipeline([ ("imputer", SimpleImputer(strategy="most_frequent")), ("onehot", OneHotEncoder(handle_unknown="ignore")), ]), categorical_columns, ), ] ) 

Keeping preprocessing inside a pipeline is helpful because the transformations are fitted on the training data, not on the entire dataset before the split.

Split the data before training

For a straightforward experiment, I’d start with a stratified train-test split. Stratification helps keep a similar proportion of churn and non-churn cases in each set.

from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42, stratify=y, ) 

A random split isn’t right for every project. If the records are time-based, it may be more realistic to train on earlier data and test on later data. The split should reflect how you expect the model to be used.

Build a baseline and check more than accuracy

Logistic Regression is a reasonable place to start. It gives you a baseline without making the first version of the project more complicated than it needs to be.

from sklearn.linear_model import LogisticRegression model = Pipeline([ ("preprocess", preprocessor), ("classifier", LogisticRegression(max_iter=1000)), ]) model.fit(X_train, y_train) 

Now evaluate it:

from sklearn.metrics import ( classification_report, confusion_matrix, roc_auc_score, ) predictions = model.predict(X_test) churn_scores = model.predict_proba(X_test)[:, 1] print("ROC-AUC:", roc_auc_score(y_test, churn_scores)) print(confusion_matrix(y_test, predictions)) print(classification_report(y_test, predictions)) 

Accuracy can be misleading when fewer customers churn than stay. A model that predicts “stay” for almost everyone might still get a decent accuracy score while missing many of the customers you wanted to identify.

The confusion matrix gives you a more concrete view of those mistakes. Precision and recall help describe the trade-off between incorrectly flagging customers and missing customers who do churn. ROC-AUC shows how well the model ranks churn cases above non-churn cases across different thresholds, but it doesn’t tell you which threshold to use.

The default threshold may not fit the job

Many classifiers use 0.5 as the default threshold for turning a probability into a yes-or-no prediction. That’s a starting point, not a rule.

If the business wants to reach as many potential churners as possible, it may accept more false alarms. If contacting customers is costly or could annoy them, it may prefer to flag fewer people with greater confidence.

The choice depends on what happens after the prediction. I’d choose a threshold using validation data and the needs of the intended use, rather than repeatedly adjusting it based on the test results.

Be careful with what the model seems to explain

A model can show that certain features are associated with churn. That doesn’t prove those features caused it.

For example, if customers on a particular type of contract are more likely to churn in the data, the contract might not be the underlying reason. Other factors, such as tenure, pricing or service experience, could be involved.

I treat model results as clues to investigate, not as a complete explanation of a customer’s behaviour.

Keep the project easy to follow

For a portfolio project, the notebook or repository should explain the choices, not just show the final score. I’d include:

  • How churn was defined
  • What data was used and how it was prepared
  • How the training and test sets were created
  • Which metrics were checked and why
  • What the model can and cannot tell us

That makes the project more useful to someone reviewing it and makes it easier to reproduce later.

The main lesson for me is that churn prediction isn’t just a contest between classifiers. The definition of the problem, the timing of the data and the way the results are evaluated all matter. A model is useful only when those choices make sense for the task.