How to use machine learning for customer segmentation

Author: Mateusz Lewandowski, Data Scientist

Enormous, extended datasets. That’s what any marketer must analyze who’s responsible for personalization of products or services, customer experience and – most importantly – for improvement of sales. At the same time, millions of dollars are spent on advertising to reach specified types of clients. Machine learning lets us take advantage of datasets and target our communication better. Save time while being more accurate. Below I explain how customer segmentation takes advantage of ML, which algorithms are used and why it is worth using.

Imagine different kinds of shoppers at Walmart. Now imagine those who do their grocery shopping in Asda Middleton or Whole Foods (a large market-like chain of shops that contain everything that a small eco indie shop does). Now think of Apple users or people who wear Patagonia clothing. Different groups with different characteristics (motivations, lifestyles, demographics, attitude) will come to mind, that you can later segment into smaller divisions.

Each brand has a specific group (or groups) of customers and large chunks of information that lead to different approaches to customer segmentation. Machine learning can help huge enterprises as well as medium businesses dig through the data and draw valuable conclusions. Here’s how.

What is customer segmentation empowered by machine learning?

Customer segmentation by means of machine learning is a process of dividing a customer base into particular groups with similar characteristics. There are countless ways to segment customers. It can be done demographically or psychographically, sorting by:

  • Age
  • Sex
  • Highest level of education achieved
  • Stage of life
  • Income
  • Religion
  • Attitudes towards products/services

You can also group customers using any combination of the above. Since there are many combinations possible, it is impractical to approach the task with pencil and paper. To ensure trustworthy, accurate results, it is wiser to resort to machine learning methods that are designed to deal with the problem at hand.

Machine learning methods are great for finding patterns and insights in customer data. Artificially intelligent models are powerful tools for decision-makers. They can precisely identify customer segments, which is much harder and takes longer when done manually or with conventional analytical methods.

What exactly is customer segmentation? 

When you group your customers/users according to specific characteristics (as mentioned at the beginning of the article) – that’s called customer segmentation.

The advancement of the segmentation depends on the customer data you have – starting with basic information like age or gender, and ending with more detailed info like “time since the user first visited a given website”.

4 types of customer segmentation

  1. Geographic – based on customer/user location, e.g. state, city, zip code.
  2. Demographic – focused on certain traits such as age, gender, income, occupation & family status.
  3. Behavioral – focused on customers’ behavior patterns, e.g. their attitude toward your product, brand or service or their use of your product/service. Behavioral customer segmentation can be based on purchase behavior, occasion/timing, benefits sought, customer loyalty, customer journey stage, engagement or satisfaction.
  4. Psychographic –  based on features such as beliefs, values, lifestyle, social status, opinions and activities. It’s different from behavioral segmentation because it draws out the motivations behind behavior, rather than tracking the behavior itself.

Customer segmentation supports many business opportunities. You can optimize areas like:

  • Budgeting
  • Product or service design
  • Promotion
  • Marketing
  • Customer satisfaction

Why to use machine learning for customer segmentation?

In marketing the quest can be straightforward: maximize profits with the smallest effort. If a marketing specialist is tasked with developing an idea of how to advertise a new Mercedes and decides to advertise that the car is affordable, he or she would be totally missing the point.

I’d hazard to state that the market segment for that type of vehicle is not somebody who’s looking for “affordable” or “cheap” vehicles, but someone who is wealthy and does not mind others knowing about it. The marketing strategy I mentioned would drive customers away and would result in a loss of faith in that employee and a loss of budget and credibility for the marketing agency.

A good data analyst can make a correct hypothesis about the target group but not only that, he or she must also look for things that are not obvious, present various hypotheses and run many tests to confirm or reject them.

Companies that analyze customer segments benefit in many ways:

  • Learn whether a given marketing assumption was correct
  • (Imagine preparing a campaign for college students only to find out that the biggest portion of customers is blue-collar workers in their 50s – a clearly missed objective.)
  • Measure how the introduction of a new feature or product influences current customer groups
  • (For example, by running A/B testing on a website, which is very useful for measuring interest in a new feature under consideration. If there is high interest – it is worth developing, but if nobody shows an interest in a ghost “new feature” button – why waste engineering hours on it?)
  •  Measure the behavior of customers who resign from services
  • (Churn modeling. If they all share something in common (maybe buying product A) – there is a need to investigate further that product A.)

Machine learning offers advantages over manual data analysis. Imagine that a new product is launched. A wise data analyst would do their best to try to collect the incoming stream of data to verify their hypotheses. And as more data become available, they will need to update their models. That can be done in two ways: either retrain the whole model from the beginning by increasing the training dataset, or train a new model on this new data and combine its output with an old model, perhaps taking care to weigh the predictions according to how much data was used to train each model. In either scenario, it is the machine that gets all the work done and not humans, and that means significant results, as machines work tirelessly.

Benefits of machine learning for customer segmentation

  • More time – manual segmentation, especially if there’s a lot of data (and you’re seeking specific patterns) is extremely time-consuming. Machine learning frees up marketers’ time so they can focus on more demanding tasks requiring more creativity and complex thinking.
  • Scaling – machine learning models support scalability. They may work now for 10,000 customers but even if the company gains 1 million more, the model can handle the new data and analyze it fast.
  • Higher accuracy – the performance of machine learning models for customer segmentation is much better when it comes to extended datasets.

What type of machine learning can be used for customer segmentation?

The most common types of machine learning are supervised learning, unsupervised learning and reinforcement learning. I’d venture to say that the most monetized type of machine learning out there is supervised learning, in which models are trained by being given many examples with corresponding labels (for example, classification problems – assign to one of the classes, regression problems – predict house prices).

In unsupervised learning, the point is that there is data available but no label is assigned (which makes preparing a dataset cheaper than with supervised learning because it eliminates the need for annotation – one of the most troublesome parts of machine learning projects), and there is a hypothesis that the given data can be distinguished by some feature. To give an example let’s have a look at the picture below:

image showing supervised learning vs. unsupervised learning

In the picture on the left, a model is tasked with drawing a line that separates the points as much as possible, while on the right side, the model’s task is to provide centres of clusters – collections of data points aggregated together because of certain similarities – that best reflect how data groups with respect to some variable in question. The picture is much simplified and plotted on a 2 dimensional plane for ease of explanation.

Unsupervised machine learning algorithms come with an idea of where centers of clusters are located (in d dimensions) and by comparing the distance from the center of that point to the radius of the cluster, they verify whether any point (representing a customer) belongs to a given cluster. That is likely to reflect this customer’s beliefs and the set of behaviours that are being measured (e.g. if the customer will buy the product or not).

Which machine learning algorithm is used for customer segmentation?

There are many machine learning algorithms, each suitable for a specific type of problem. If the goal is to assign each customer to one group, then you should reach for a K Means algorithm. It is a popular method of unsupervised machine learning method that finds “different” clusters and group them together so you end up with the most possible customer segments to interpret.

If the customers are expected (as they are in reality) to belong to many different groups at the same time, it would be wiser to use the Hidden Markov Model (HMM). However, there are other options available: Agglomerative Hierarchical Clustering, Expectation-Maximization Clustering, Density-Based Spatial Clustering, Mean Shift Clustering.

The difficulty when running the K Means clustering arises when choosing the optimal number of clusters – the algorithm might converge when given way too many clusters as well – but that just would not make sense.

There are some methods that help estimate the needed number of clusters:

Having the optimal number of clusters increases the reliability of the analysis.


I feel free to say that planning a marketing campaign or launching a new product should always start with careful data collection and analysis. Otherwise, marketers more resemble a soldier who shoots without aiming and hence misses the target, shot after shot. And you’ve always got limited ammunition, so take aim with care!

There might be a reluctance towards a data-centric approach at first, as people may not want to invest in technology they don’t understand well. That’s why it is important to have a basic understanding of algorithms (and as I mentioned above, in terms of customer segmentation there are options to choose from), know what they are doing and, most importantly, what can be expected as a result. If chosen correctly, this approach can save a lot of time and effort, while improving the accuracy of your customer segmentation and create AI powered marketing strategy!

Read our knowledge-packed articles on machine learning: