Clustering Algorithms: The Key to Segmentation for Targeted Digital Marketing

Hello everyone! Today, I'd like to discuss customer/audience segmentation analysis, which is essential for businesses of all sizes and industries. We'll be using a dataset example and applying machine learning techniques in RapidMiner to identify more targeted segments. I firmly believe in the power of data and highly recommend leveraging data analytics on your digital marketing data to uncover valuable insights.

Learning Python for this kind of analysis can be challenging, so I invite you to join me in exploring basic methods together!

Customer Segmentation

Customer segmentation is a vital part of modern marketing strategy, allowing businesses to tailor their offerings and messaging to specific groups within their customer base. By dividing customers into distinct segments based on shared characteristics, preferences, and behaviours, companies can deliver more personalised and impactful digital marketing campaigns.

In the digital age, the significance of customer segmentation is amplified by the vast array of online channels and data available. Through advanced analytics and predictive modelling techniques, businesses can gain deep insights into their customers' needs, preferences, and propensities. This allows for highly targeted digital marketing efforts, ensuring the right message reaches the right audience at the right time, maximising engagement and conversions.

Effective customer segmentation, combined with strategic digital marketing initiatives, empowers businesses to foster stronger connections with their customers, enhance brand loyalty, and ultimately drive growth and profitability.

Digital Marketing Use Case Examples for Customer Segmentation

As digital marketers, there are many use cases where we can apply clustering algorithms to achieve better results and ROI. These algorithms can provide us with a competitive edge, and they're easy to use. While we sometimes prefer to use Excel for grouping data, I promise that RapidMiner is just as user-friendly. So, I'd like to encourage all digital marketers to explore these digital marketer-friendly business intelligence (BI) tools :)

Let's think about our daily tasks and create some examples:

Account-Based Marketing (B2B): Identify clusters of high-value accounts or companies based on their size, industry, and other relevant criteria to enable targeted ABM campaigns and personalised outreach.

Content Personalisation (B2B/C): Segment customers based on their interests, behaviours, and engagement patterns to deliver personalised content recommendations, product suggestions, and offers that align with their preferences.

Email Marketing (B2B/C): Leverage customer segments to send targeted email campaigns with relevant messaging, promotions, and calls-to-action for each group, improving open rates and conversions. You can use your audience's interactions like open rate, and click rate for analysis.

Social Media Advertising (B2C): Create targeted social media ad campaigns for specific customer segments based on their demographics, interests, and online purchase behaviours, ensuring more effective ad spending and higher engagement.

Lead Scoring and Nurturing (B2B): Segment leads based on their company profiles, online activities, and engagement levels to prioritise high-potential leads and deliver nurturing campaigns tailored to their stage in the buyer's journey.

Upsell and Cross-sell Opportunities (B2B): Segment customers based on their purchase histories, product usage, and lifecycle stages to recommend complementary products or premium upgrades that align with their needs and behaviours.

Brand Loyalty Programs (B2C): Segment customers based on their loyalty levels, purchase frequencies, and lifetime values to create targeted loyalty programs, rewards, and exclusive offers that foster long-term brand advocacy.

Search Ads Campaigns (B2B/C): Segment audiences based on their search behaviours, interests, and online activities to create highly targeted paid search campaigns with tailored ad copy, landing pages, and offers for each segment. You can cluster your keywords to determine your ad groups.

Attribution Modeling (B2C): Analyse customer segments based on their attribution paths, touchpoints, and conversion patterns to optimise marketing channel allocations, budgets, and attribution models for each segment.

App User Segmentation (B2C): For mobile apps, cluster users based on their app usage behaviours, in-app events, and demographic data to deliver personalised in-app experiences, push notifications, and targeted app marketing campaigns.

For example, a business-to-business (B2B) company can segment its customer base using clustering algorithms and LinkedIn Sales Navigator data. By analysing company industries, sizes, and employee positions, the algorithm can identify clusters of companies operating in similar industries, with comparable sizes, and targeting similar roles or job functions. These clusters can then be targeted with tailored marketing campaigns, content, and offerings that align with their specific needs and preferences.

Additionally, clustering algorithms can be combined with other data sources, such as website analytics, social media interactions, and purchase histories, to create even more comprehensive customer segments. These segments can inform various digital marketing strategies, including content marketing, email campaigns, social media advertising, and account-based marketing (ABM).

Machine Learning Techniques for Customer Segmentation:

Clustering techniques are powerful tools for customer segmentation. Clustering algorithms can group similar customers, revealing distinct segments in your customer base.

  • RFM analysis categorises customers by purchase recency, frequency and monetary value to identify high-value and loyal customers for lead generation.

  • Demographic segmentation divides customers by age, gender, location etc. allowing tailored messaging per segment.

  • Algorithms like k-means, and DBSCAN can identify homogeneous audience groups by analysing customer data and grouping similar individuals together.

  • Additionally, decision tree-based methods such as CART and Random Forest enable rule-based segmentation, uncovering patterns and relationships within the data to define distinct customer segments.

These clustering and decision tree approaches provide valuable insights for targeted marketing strategies, allowing businesses to tailor their offerings and messaging effectively.

K-means Clustering Algorithm (centroid-based clustering)

K-means is a popular clustering algorithm that partitions data into a specified number of clusters. The algorithm aims to minimize the sum of squared distances between data points and their assigned cluster centroids. However, one of the drawbacks of k-means is that you need to specify the number of clusters (k) beforehand, which can be challenging if you don't have prior knowledge about the data.

X-means Clustering Algorithm (centroid-based clustering)

X-means is an extension of the k-means algorithm that addresses this issue by automatically determining the optimal number of clusters. Instead of requiring the user to provide the number of clusters, x-means employs a technique called the Bayesian Information Criterion (BIC) to estimate the appropriate number of clusters based on the data itself.

I am leaving one of the academic studies here, you can read and learn more. Especially, I really liked the clustering methods comparison table which smoothly showed advantages and disadvantages.

By automatically determining the number of clusters, x-means can be a more beneficial algorithm for effective segmentation, especially when you don't have prior knowledge about the number of clusters in your data.

In real-world applications, such as analysing company data from LinkedIn Sales Navigator, x-means can be a powerful tool for clustering companies based on various features like industry, size, number of employees, and employee positions. With x-means, you don't have to guess the number of clusters beforehand, allowing for a more data-driven approach to segmentation.

Clustering questions that we can use in our digital marketing efforts:

"What are the major segments in our customer base?"

"Are there distinct seasonal customer clusters in our data?"

"Can we cluster customers by which marketing channels they respond to best?"

Customer Segmentation with RapidMiner - Use Case

Earlier, we discussed RapidMiner, so I'll dive straight into our analysis. If you'd like to learn more about RapidMiner and how we can utilise it, you can find additional information here. RapidMiner provides a wide range of machine learning algorithms suitable for various use cases, from regression to deep learning. The platform simplifies model building using techniques like automated machine learning, requiring just a few clicks.

For our use case, we'll be using the Customer Shopping Data from Kaggle. We'll then apply the k-means and x-means clustering algorithms to our customer data and compare the results.

Context of Our Dataset

The Customer Shopping Preferences Dataset offers valuable insights into consumer behaviour and purchasing patterns. Understanding customer preferences and trends is critical for businesses to tailor their products, marketing strategies, and overall customer experience. This dataset captures a wide range of customer attributes including age, gender, purchase history, preferred payment methods, frequency of purchases, and more. Analysing this data can help businesses make informed decisions, optimise product offerings, and enhance customer satisfaction.

Description of Our Use Case:

A retail company wants to optimise their advertising strategy and segment their customer base. Well, we can segment customers based on their buying behaviour on the market. Keep in mind that the data is really huge, and we can not analyse it using our bare eyes. In such cases, we can leverage machine learning algorithms and computational power to gain valuable insights.

This use case will demonstrate how to segment customers into clusters based on their shopping behaviour using the K-Means and X-Means algorithms. It will guide you through the entire customer segmentation process, from data preparation to clustering, step-by-step using RapidMiner. Or you can generate Phyton code for clustering with AI. By the end, you'll have a better understanding of how to leverage these techniques to gain deeper insights into your customer base and optimise your advertising efforts.

Content of Dataset

This dataset encompasses various features related to customer shopping preferences, gathering essential information for businesses seeking to enhance their understanding of their customer base. The features include customer age, gender, purchase amount, preferred payment methods, frequency of purchases, and feedback ratings. Additionally, data on the type of items purchased, shopping frequency, preferred shopping seasons, and interactions with promotional offers is included. With a collection of 3900 records, this dataset serves as a foundation for businesses looking to apply data-driven insights for better decision-making and customer-centric strategies.

Dataset Glossary (Column-wise)

  • Customer ID - Unique identifier for each customer

  • Age - Age of the customer

  • Gender - Gender of the customer (Male/Female)

  • Item Purchased - The item purchased by the customer

  • Category - Category of the item purchased

  • Purchase Amount (USD) - The amount of the purchase in USD

  • Location - The location where the purchase was made

  • Size - Size of the purchased item

  • Color - The color of the purchased item

  • Season - Season during which the purchase was made

  • Review Rating - Rating given by the customer for the purchased item

  • Subscription Status - Indicates if the customer has a subscription (Yes/No)

  • Shipping Type - The type of shipping chosen by the customer

  • Discount Applied - Indicates if a discount was applied to the purchase (Yes/No)

  • Promo Code Used - Indicates if a promo code was used for the purchase (Yes/No)

  • Previous Purchases - The total count of transactions concluded by the customer at the store, excluding the ongoing transaction

  • Payment Method - Customer's most preferred payment method

  • Frequency of Purchases - Frequency at which the customer makes purchases (e.g., Weekly, Fortnightly, Monthly)

Our Objective for this Use Case:

  • Understand the Customer Shopping Dataset & cleanup (if required).

  • Build a clustering model to segment the customer-based similarity.

  • Apply algorithms like K-means and X-means clustering to identify natural clusters within the customer data.

  • Evaluate and compare the clustering results using appropriate evaluation metrics to assess the quality and validity of the generated customer segments.

  • Gain insights into the characteristics and purchasing patterns of the different customer segments to inform targeted marketing and advertising strategies.


1) In the first step, I uploaded our dataset to RapidMiner.



2) After we click the next button, we should take a look at our data format and if there is a mistake we can change the format to integer, polynomial, date etc.



3) Then, we see details in the statistics section. It's a helpful summary showing min/max/average values and missing ones. As you can see, there aren't any missing values.



4) In this panel, Turpo Prep, we can clean up missing values and prepare our data.



5) I uploaded our dataset, as you can see below you can clean, generate, pivot and merge your data easily for data preparation.



6) Let's begin our analysis unless data preparation is unnecessary! In the Auto Model section for clustering algorithms, we need to select 'Clustering' and then click the 'Next' button. In our previous edition, we used the 'Predict' feature for predictive modelling.



7) In this screen, RapidMiner automatically detected important values affecting our model. For example, customer ID does not affect a customer's clustering.


8) Finally, we choose our clustering algorithms as k-means and x-means. You can arrange the number of clusters from there. I will use both techniques to show you.


K-Means Clustering Analysis:

8) We arranged a number of clusters as 2, here's the summary of our 2 clusters. For example, in Cluster 0, the average number of previous purchases made by customers in those clusters is 17.24% smaller compared to the overall average across all clusters or the entire dataset. The age of customers in the clusters being described is 15.12% smaller than the overall average age across all clusters or the entire dataset. However, the average purchase amount (in USD) made by customers in those clusters is 14.92% larger compared to the overall average purchase amount across all clusters or the entire dataset.

In summary, this highlights the relative differences in the averages of three attributes (previous purchases, age, and purchase amount) for a specific group of clusters compared to the overall averages of those attributes in the entire dataset. These differences can help characterise and differentiate the identified clusters based on their distinct patterns or behaviours.



9) Heatmap visualisation is a powerful technique for analysing patterns and relationships in a two-dimensional data matrix, where larger values are represented by darker shades of green and smaller values by lighter shades of red. By mapping the values to a colour scale, the heatmap allows you to quickly identify patterns, clusters, outliers and correlations or contrasting behaviours across variables.

In summary, you can quickly analyse your clusters by just looking at this heatmap. In Cluster 0, the Purchase Amount (USD) has larger values. On the other hand, in Cluster 1, Previous Purchases has larger values.



10) As k-means is a centroid-based clustering algorithm, here is the centroid chart that we can understand our clusters. In this chart, each cluster is represented by its centroid, which is the mean or average value of all the data points belonging to that cluster. The centroid serves as a representative or central point for the cluster. The chart displays these centroids across different dimensions or variables, allowing you to understand the distinguishing characteristics of each cluster.



11) In the clustered data screen, you can see which customer ID belongs to cluster 0 or 1. You can easily export this dataset and use your clusters for your ad targeting.



X-Means Clustering Analysis:

12) Let's look at x-means clustering analysis. RapidMiner automatically recommends 5 number of clusters to us. You can see the cluster details below.



13) I believe the x-means has more advantages rather than the k-means for better targeting. As you can see, a review rating is another impactful value that we can consider.



14) By analysing the centroid values for various attributes, such as location, purchase amount, or age, you can identify the defining features that differentiate the clusters from one another. This visual representation facilitates the understanding of the distinct profiles or behaviours captured by the x-means algorithm, enabling you to interpret the underlying patterns and make informed decisions based on the identified clusters within your previous records.



15) You can also view the cluster tree, but it's not displayed clearly on the RapidMiner interface, which I find less appealing.



16) Just like k-means, you can export your data with cluster numbers and use your campaigns.


That concludes today's episode. I hope you found it insightful! While it may seem complicated at first, the process is straightforward: upload your data, click the clustering button, and analyse further. Please share your thoughts and feedback in the comment section below!

For now, I'll see you in the next episode, where I'll delve deeper into performance marketing, my passion area. Continue exploring All About Digital Marketing & Data Analytics and don't forget to subscribe to stay updated on the latest information. Cheers!

Let's Connect!

Schedule a call with Gokce.

Let's Connect!

Schedule a call with Gokce.