For companies that build their strategy around the customer and their satisfaction, there are three machine learning models that are relatively easy to apply and can have a high impact: clustering, as a way to understand consumer behavior; association rules, which uncover which products are frequently bought together; and churn prediction, which estimates which customers are most likely to stop being customers.
Clustering: creating market segments based on customer behavior
Clustering is an unsupervised machine learning model that groups customers (or other entities) based on shared characteristics. It’s called unsupervised because there is no target variable (label) to predict. So, it’s not a predictive model, but a model for discovering patterns and extracting insights from data.
Grouping a customer base into segments with common traits provides clear guidance on which marketing strategies to adopt. Creating a unique strategy for each customer is impractical, but treating all customers the same is equally ineffective.
That’s why it’s painful to see, even in 2021, marketing campaigns sent via email or SMS that attempt to “sweep” through the entire customer base with the same undifferentiated offer.
We can do better. Not only are the algorithms available, but the necessary data is also accessible at low or even zero cost.
For instance, a book retailer could segment customers based on purchase frequency, preferred book genres, discount sensitivity, preferred purchasing channel, age group, and more. These variables are easily collected through transactional systems such as billing software or CRM platforms.
Suitable clustering algorithms for this task might include K-Means, Partitioning Around Medoids (PAM), and DBSCAN. While they differ mathematically and should be used depending on the nature of the data, they share a common goal: assigning each instance (customer) to a cluster that is internally homogeneous and externally distinct from others.
The company could then discover that its customers naturally fall into three clusters:
- Price-sensitive customers who prefer online shopping and buy mainly crime or self-help books, especially related to healthy eating;
- Traditional readers who enjoy classic Portuguese authors, visit physical stores, and are less responsive to discounts. They tend to be older and more loyal;
- Younger customers who mostly buy schoolbooks and stationery.
We don’t know the outcome of clustering in advance — only the data will reveal how customers behave and how to craft a tailored marketing narrative around each cluster.
Association rules
This is another unsupervised model, where we are still not predicting a target variable. This time, however, we explore transactional data to look inside each shopping basket and identify frequent product sets — that is, products often bought together, like cheese and ham.
Algorithms suited for this analysis include the FP-Growth and Apriori algorithms.
The process begins by identifying frequent items — products present in at least x% of transactions (a model hyperparameter). Then, by evaluating all possible combinations of these items, we calculate interest measures based on support and confidence.
The final output is a ranked list of rules, from strongest to weakest. Each rule defines which product combinations are most frequent, with clear identification of antecedents and consequents — the products that trigger the purchase of others.
For example, our book retailer might discover that schoolbooks are often bought together with unrelated items such as fashion accessories, or that self-help book buyers frequently purchase daily newspapers as well.
These insights raise new questions about the data, such as:
- Which customers bought the antecedent but not the consequent product?
- How should we organize physical and online store layouts to encourage cross-selling?
- Which customers should receive a discount or promo for a consequent product?
Churn: which customers are likely to leave?
Churn models are binary classification models — their output is either 0 or 1, indicating whether the customer is predicted to stay or leave. Some models return a probability between 0 and 1, and the analyst must decide the threshold for interpreting churn (typically 1).
Before applying such a model, you must define what “churn” means in your business context. This varies by industry. A telecom company might define churn as no purchases for 30 days, while a supermarket chain might set the threshold at three or six months of inactivity.
If your business depends on customer loyalty or recurring purchases, a churn model is usually worth implementing.
Algorithms for churn prediction include logistic regression, support vector machines, and decision trees, among many others. These are supervised learning models, so historical data must include a label indicating whether churn occurred for each customer.
Model input variables should have predictive power — that is, some relationship with churn. For example, consider variables like customer tenure, presence of a contractual relationship, number of complaints in the past year, and annual purchase volume.
If the model can also identify the relative importance of each variable, even better. With that insight and an effective model, companies can anticipate customer loss and act in time to retain them.





