Agglomerative Hierarchical Clustering: A Comprehensive Guide 2026
Learn what agglomerative hierarchical clustering is, how it works, and how to apply it to your business. A comprehensive guide with examples in Python.

Your CRM is full of contacts, your e-commerce order history, marketing campaign data, support tickets, and maybe even Excel spreadsheets created by different teams. It’s all there. It’s all useful. But often, it’s all jumbled together.
For many small and medium-sized businesses, the problem isn’t a lack of data. It’s a lack of structure. A retail manager wants to understand which customers have similar buying patterns. An operations manager wants to see which products sell well together. A finance team wants to distinguish between normal behavior and patterns that warrant attention. Without a clear method, data remains a mere repository rather than a guide.
This is where agglomerative hierarchical clustering comes in. It's a machine learning technique that organizes observations into groups by building a hierarchy from the bottom up. It's not new. It's an established technique: introduced in the 1960s, and already applied in Italy in 1985 in a project on socio-economic data that reduced 50 regions to 7 main clusters (reference reported here). This matters because it shows a simple thing: when data seems chaotic, hierarchical clustering can reveal a readable structure.
If you want to start with a broader view of how data is used in business, this guide on company data analysis is a great complement.
Table of Contents
- Introduction From Data Chaos to Strategic Clarity
- What sets it apart from other methods
- First question: how do you measure similarity
- Second question: how do you merge two clusters
- Comparison of linkage methods
- How to choose based on business context
- A concrete example
- Computational cost matters too
- How to read the dendrogram without unnecessary jargon
- How to choose the cut point
- Preparing the data the right way
- Basic implementation example
- The three decisions that really matter
- Customer segmentation that actually helps marketing
- Products and inventory
- Financial risk and cybersecurity
- Where an internal team really gets stuck
- What changes with an automated workflow
- Conclusions and Key Points to Remember
Introduction: From Data Chaos to Strategic Clarity
Monday morning. The sales manager opens the CRM, the marketing team reviews campaigns with widely varying results, and the logistics team flags products with unpredictable turnover rates. The data is there, but there’s no clear roadmap to guide decision-making.
This is where an SME manager starts asking the right questions. Which customers actually exhibit similar behavior? Which products warrant a distinct strategy? Which locations or business areas should be managed differently, even if they all end up in the same report today?
Agglomerative hierarchical clustering works to turn this disorder into a readable structure. Instead of immediately forcing categories decided in advance, it organizes elements by similarity and shows how groups take shape step by step. The result isn't just a statistical exercise. It's concrete support for sales segmentation, operational priorities, and positioning choices.
For a company, the point isn’t to know the name of the algorithm. The point is to make effective use of three practical tools: choosing the right linkage for your specific situation, interpreting a dendrogram without getting bogged down in technical details, and knowing where to split the hierarchy to obtain clusters that are useful for the business.
This is the difference between an academic approach to clustering and its managerial application.
If you're already working on segmentation, reporting, or company data analysis for faster, more concrete decisions, this method helps you see relationships that stay hidden in Excel spreadsheets. And with tools like Electe, even an SME without a data science team can bring this approach into everyday processes, from reading data to making operational choices.
What Is Agglomerative Hierarchical Clustering and How Does It Work?
Agglomerative hierarchical clustering starts from the bottom. Each record begins as a group on its own. Then the algorithm compares similarities, merges the two closest elements, and repeats the same step until it builds a complete hierarchy.
For an SME, this approach is useful because it reflects a realistic decision-making process. At the outset, you don’t yet know exactly how many segments you need. You only know that some customers behave similarly, that certain products follow comparable patterns, and that some areas of the business are worth examining together. Agglomerative clustering organizes these relationships without forcing you to set a specific number of groups right away.
The operating mechanism is straightforward:
- Each observation starts on its own. A customer, a product, or a transaction are separate clusters.
- How different two elements or two groups are is calculated.
- The closest clusters are merged based on the chosen rule.
- The structure is updated and the comparison is repeated.
- This continues until there's a single hierarchical tree that shows all possible aggregations.
This is where a point of confusion often arises. The algorithm doesn’t immediately return “the right 4 clusters” or “the correct 6 segments.” It first constructs a k-nearest neighbors map. The decision on how many groups to retain comes later, when you interpret that hierarchy in light of the business objective.
An example might help. If you’re analyzing your customer portfolio, you might find that some customers are similar in terms of purchase frequency, others in terms of average spend, and still others in terms of seasonality. Agglomerative clustering doesn’t force you to choose a level of detail right away. It lets you see both micro-groups—useful for targeted campaigns—and macro-segments—useful for defining budgets, service levels, and business priorities.
What sets it apart from other methods
The practical difference compared to methods like k-means is simple. With k-means, you have to decide in advance how many clusters you want to find. With agglomerative hierarchical clustering, you build a hierarchy and then decide where to stop.
For a manager, this makes a big difference. It means being able to start with an open-ended question, rather than a preconceived answer. If the sales team suspects that there are different customer profiles but doesn’t yet know how many there are, this method provides a more useful framework for discussing a strategy.
There’s another reason why it’s popular. The results are easy to understand. You don’t just get final labels assigned to the records; you also get a step-by-step process showing how the groups are formed. It is precisely this hierarchical structure that makes the method valuable for business decision-making, because it links statistical analysis to a practical choice: where it makes sense to separate groups in order to gain actionable insights.
Rule of thumb: use hierarchical clustering when you want to explore the structure of the data before defining stable operational segments.
If you want to compare this approach with other machine learning algorithms for different business problems, it makes sense to evaluate them based on the decision you need to make, not just the technique.
Distance Metrics and Linkage Methods: The Choice That Defines Your Clusters
Two companies can use the same algorithm and get very different segmentations. The reason, almost always, lies here: in the choice of how to measure distance and how to decide which groups to merge.
For an SME manager, this isn’t just a technical detail. It’s a decision that affects the bottom line. It can lead to useful clusters for marketing campaigns and pricing, or to confusing groups that the team can’t make use of.
First question: How do you measure similarity?
The distance metric is used to measure how different two observations are from each other. If you're analyzing customers, products, or points of sale, it's the rule the algorithm uses to compare profiles.
The most common ones are:
- Euclidean distance. Measures the straight-line distance between two points. It's suitable when working with numeric variables that are comparable to each other, for example revenue, purchase frequency, and average order value, after proper normalization.
- Manhattan distance. Sums the absolute differences across each variable. It works well when you want a measure that's less sensitive to individual deviations and closer to a "block-based" logic, useful in some operational datasets.
This is where a common mistake arises. If one variable has a much wider range than the others, it will end up dominating the distance calculation. In practice, the clustering will be based almost entirely on that column. For this reason, before choosing a linkage method, it is advisable to check whether the data has been standardized.
Second question: How do you merge two clusters?
Linkage comes into play afterward. It doesn't compare two individual points, but two already formed groups.
Here’s a good analogy: the metric determines how you measure the distance between two stores on a map. The linkage determines how you assess the distance between two entire retail chains. It makes a big difference.
The main methods are:
- Single linkage. Considers the two closest points between different clusters.
- Complete linkage. Considers the two farthest points.
- Average linkage. Uses the average of the distances between all points in the two clusters.
- Ward. Merges the clusters that increase internal variability as little as possible.
Comparison of linkage methods
Linkage MethodHow It WorksProsConsIdeal for
Single Linkage
Use the minimum distance between points in two clusters
Capture progressive connections
It can create "chained" clusters that are not very compact
Highly connected patterns, initial exploration
Complete Linkage
Use the maximum distance between points in two clusters
Generate more compact clusters
It may separate groups that are naturally close together
Segmentations where homogeneity matters
Average Linkage
Average distances between points in the two clusters
A good compromise
Less straightforward to explain to the business
Balanced analyses
Ward
Minimizes the increase in intra-cluster variance
Creates stable and readable partitions
Requires properly formatted numeric variables
Customer segmentation, business analysis
The right choice depends on the decision you need to make at work, not on some abstract preference.
If your goal is to find clusters connected by progressive similarities, single linkage can be useful during the exploratory phase. If instead you need to build clear segments to assign to campaigns, price lists, or service levels, in many cases complete or Ward produce groups that are easier to interpret. Average linkage is often a good middle ground when you want neither overly rigid clusters nor overly elongated structures.
Rule of thumb: if you need to present the clusters to sales, marketing or management, start with Ward. If the result looks too “forced,” compare it against average linkage.
How to choose based on your company's context
In academic guides, the discussion often stops at the definition. In the business world, however, a decision-making framework is needed.
Use this track:
- Want compact clusters that are easy to explain? Start with complete or Ward.
- Want to explore weak connections or highly irregular structures? Consider single linkage.
- Want a compromise between stability and flexibility? Try average linkage.
- Do you have variables on different scales or a mix of poorly homogeneous indicators? Check data preparation and the metric first, otherwise the linkage will be judged unfairly.
In other words, there is no single "best" method. There is, however, the method that best aligns with the business need.
A concrete example
Let’s say you want to segment the customers of a small retail business using purchase frequency, average order value, and the number of product categories purchased.
With single linkage, you might get a very extended cluster, joined by gradual steps between customers who are quite different from each other. It's useful if you want to observe continuity in behavior, but less so if you need to create distinct commercial actions.
With complete linkage, the groups become tighter. Customers within each cluster resemble each other more, so the marketing team can more easily build dedicated promotions.
With Ward, you often get ordered, readable segments. That's why it's a frequent choice when the goal isn't just to analyze, but to reach a decision.
Computational cost matters too
Agglomerative hierarchical clustering can be computationally intensive on large datasets. This has tangible consequences: longer processing times, higher memory requirements, and less flexibility for quickly testing different metrics and linkage methods.
For an SME, the point isn’t to get bogged down in theoretical discussions about algorithms. The point is to determine whether the analysis will remain feasible given the available data, the team’s time constraints, and the tools currently in use.
That is why the technical decision should address three simple questions:
- will the clusters be clear enough to guide an action?
- does the method hold up well against the actual structure of the data?
- is the process sustainable without excessive manual work?
This is where a platform like ELECTE becomes handy. It simplifies the most technical aspects of configuration and makes it easier to compare different options, even if you don’t have an in-house team of data scientists. The value isn’t in “doing clustering.” It’s in choosing a segmentation that the business can understand, validate, and use.
Building and Interpreting a Dendrogram: Turning a Tree into Action
The real value of agglomerative hierarchical clustering appears when you look at its most typical output: the dendrogram. It's not a decorative chart. It's a decision map.
How to Read a Dendrogram Without Unnecessary Technical Jargon
On the horizontal axis, you’ll find observations, or small groups of observations. On the vertical axis, you’ll see the distance or dissimilarity at which the mergers occur.
The most important visual rule is this: the higher up a merge happens, the more different the joined groups were.
This allows you to do something that many managers immediately appreciate. You’re not simply accepting a number of clusters determined by some “black box” formula. You’re looking at the data structure and deciding where it makes sense to stop.
For example:
- if many merges happen at low height, the data contains very similar groups;
- if at some point a clear vertical jump appears, you're probably merging groups that are already fairly different;
- that jump often signals a good point to cut the tree.
A dendrogram translates a statistical decision into a visual decision. That's why it's useful in meetings too, not just in a Python notebook.
A visual aid can help reinforce the concept:
How to choose the cutting point
Many people get stuck here. “How many clusters should I have?” The honest answer is: it depends on the problem you want to solve.
If you need to take action, too many clusters can complicate operations. If you’re analyzing very different behaviors, too few clusters risk obscuring useful patterns.
Here is a practical guideline:
- Look at the widest vertical jumps in the dendrogram.
- Draw a horizontal line at a relevant jump.
- Count the cut branches. That's the resulting number of clusters.
Let’s say the cut intersects four main branches. You end up with four segments. At that point, management is no longer a matter of statistics. It becomes a matter of interpretation.
Ask yourself:
- do these groups make sense for marketing, sales or operations?
- can I describe them in an understandable way?
- does each group lead to a different action?
Operational note: the best dendrogram isn't the most elegant one. It's the one that lets you justify a segmentation choice in front of the people who will have to use it.
A Practical Guide to Python and Scikit-learn
You have a customer dataset, a few useful variables, and a specific question: Are there groups that warrant different marketing approaches? Python is exactly what you need to turn this question into a quick, readable, and reproducible test.
To do this, you typically use scikit-learn to build the model and SciPy to draw the dendrogram. The technical part is accessible. What makes the difference for an SME is setting up the data properly and reading the result with judgment.
Prepare the data correctly
The most common mistake occurs even before the algorithm comes into play. If you include both a variable like annual revenue and one like the number of orders in the same model, the one with the larger scale is likely to carry much more weight. The resulting cluster, therefore, reflects the units of measurement more than the actual similarities between customers or products.
Standardization is meant to avoid this problem. In practice, you bring the numeric variables onto a comparable scale. It's a simple choice, but it changes the result in a concrete way, especially if you want to use Ward linkage, which works well with well-prepared numeric data.
Before launching the model, check three things:
- Numeric variables on different scales. Standardize them.
- Categorical variables. Convert them into a format the model can use.
- Missing values. Handle them beforehand, otherwise the clustering becomes fragile or unusable.
Here’s a useful analogy: you’re comparing customers as if you were evaluating them using the same unit of measurement. If one is measured in euros and another in raw counts, the comparison is already skewed from the start.
Basic implementation example
Here is a simple example using scikit-learn:
import pandas as pdfrom sklearn.preprocessing import StandardScalerfrom sklearn.cluster import AgglomerativeClustering# Example: dataset with numeric variablesdf = pd.DataFrame({"purchase_frequency": [12, 10, 2, 3, 15, 1],"average_ticket": [80, 75, 20, 25, 95, 15],"number_of_categories": [5, 4, 1, 2, 6, 1]})# 1. Scalingscaler = StandardScaler()X_scaled = scaler.fit_transform(df)# 2. Modelmodel = AgglomerativeClustering(n_clusters=3,linkage="ward")# 3. Cluster assignmentlabels = model.fit_predict(X_scaled)df["cluster"] = labelsprint(df)
The code is short. What matters most is the managerial perspective.
In this example you're telling the model: "group these observations into 3 clusters, progressively merging the most similar cases". The final result is the cluster column, i.e. the label assigned to each row of the dataset. From there, the useful business work begins: understanding what distinguishes cluster 0 from cluster 1, and which decisions are worth making.
If you also want to visualize the full hierarchical structure, you'll typically use scipy.cluster.hierarchy.linkage together with dendrogram. Scikit-learn helps you get the groups. SciPy helps you see how they were formed.
The three decisions that really matter
In a business setting, the value of clustering does not depend on the complexity of the notebook. It depends on the quality of three decisions.
- Which variables to include. If you choose columns of little use, you'll get clusters that are hard to interpret.
- Which linkage to use. Ward is often a good baseline with standardized numeric data, but it's not always the best choice for every problem.
- How many clusters make the output usable. A model with 8 groups may look precise, but become unmanageable for marketing, sales or operations.
Here we see the difference between a technical exercise and a decision-making tool. A manager doesn’t need to “do clustering” in the abstract. They need segments that can be named, explained, and used.
So, if you’re working in Python, don’t stop at the label assigned by the model. Look at the average of the variables for each cluster, compare the resulting profiles, and ask yourself right away: does this group require a different approach than the others? If the answer is no, the problem isn’t the code. It’s usually in the choice of variables, the linkage method, or the cutoff point.
Practical Examples to Help Grow Your Business
An algorithm truly matters when it changes a concrete action. Agglomerative hierarchical clustering becomes useful when it turns database rows into segments the business can use.
Customer segmentation that actually helps with marketing
Many small and medium-sized businesses still segment their customers in a very basic way. Age, geographic area, perhaps revenue bracket. It’s a start, but it’s often not enough.
With hierarchical clustering, you can combine behavioral variables such as purchase frequency, average order value, preferred categories, and response to promotions. The result isn’t just a list of profiles. It’s a hierarchy that shows you which groups are truly similar to one another and which ones should be targeted with different messages.
This helps the marketing team make more informed decisions:
- Loyal customers to protect with loyalty programs
- Occasional buyers to reactivate with dedicated campaigns
- New customers to guide toward a second purchase
- Unstable profiles to monitor before they drift away
Products and Inventory
In retail and e-commerce, clustering isn’t just about understanding people. It’s also about understanding products.
You can group products based on sales patterns, cross-purchases, seasonality, or response to promotions. This helps improve various operational decisions:
- Assortment. You understand which products have similar dynamics.
- Promotions. You build more coherent bundles.
- Stock. You avoid treating items with very different behaviors the same way.
The managerial benefit here is clear. You’re not looking at individual SKUs in isolation. You’re identifying product families that can be planned together.
When products move in similar clusters, reorder and promotion decisions also become more coherent.
Financial risk and cybersecurity
In finance, clustering can help distinguish normal patterns from those that warrant further analysis. It does not replace regulatory controls or specialized models, but it can serve as a useful tool for grouping similar behaviors and identifying anomalies.
There's also an interesting direction in cybersecurity. An emerging perspective concerns the use of advanced AHC for network traffic in Italian SMBs. In 2025, ransomware attacks on Italian IT SMBs rose by 27%, and inner-product-based AHC frameworks improved outlier detection by 18% on Italian network traffic datasets (JMLR reference reported here).
It’s important to interpret this correctly. It doesn’t mean that every SME needs to immediately build a security clustering pipeline. It does mean, however, that hierarchical clustering isn’t limited to marketing or retail. It can serve as a cross-functional analytical framework, ranging from customer behavior to risk monitoring.
How ELECTE Clustering for Your Business
You have customer data in your CRM, orders in your e-commerce system, profit margins in an Excel file, and some operational information in your business management software. As long as these remain separate, clustering remains a theoretical exercise. For an SME, the problem isn’t understanding that clusters can be useful. The problem is arriving at clusters that are meaningful, consistent, and reliable enough to guide a business or operational decision.
This is where a platform like ELECTE reduces manual work and makes the process more practical for decision-makers, not programmers.
Where does an internal team really hit a wall?
In practice, there are four recurring obstacles.
- Data sources scattered across CRM, e-commerce, local files and finance tools
- Variables that are hard to prepare, because they have different scales and units
- Choice of linkage that's far from intuitive, especially when it's unclear whether to prioritize compactness, stability or sensitivity to outliers
- Outputs that are hard to read for managers and operational teams who don't work in Python every day
The most underrated point is exactly this: the algorithm isn't enough. You need a path that takes you from raw data to a segmentation the business can actually use. Electe already helps with the first step, connecting company sources in an orderly way. If you want to see which integrations are available, you can check the page on data sources connectable in Electe.
There is also a second challenge, one that is more strategic than technical. Choosing the wrong linkage method can result in segments that are of little use to the company, even if the model was run correctly. A manager does not need to know every mathematical detail. They need to understand which configuration generates segments stable enough to support a campaign, a stock policy, or a review of the customer portfolio.
What changes with an automated workflow
With an automated workflow, the process resembles a well-organized production line more than a series of manual tests. Data is fed in, processed consistently, multiple configurations are compared, and the final output is delivered in a readable format.
Specifically, the process can follow these steps:
- Collect the data from company systems into a single environment.
- Prepare the variables with consistent rules, so that revenue doesn't weigh disproportionately compared to purchase frequency.
- Compare multiple clustering configurations without manually repeating every test.
- Read interpretable groups, with labels and patterns that make sense for sales, marketing or operations.
- Translate clusters into decisions, for example commercial priorities, promotional segments or reorder policies.
The benefit isn't automation itself. It lies in the fact that the team's time is redirected toward what matters most: interpreting the dendrogram, choosing the appropriate level of segmentation, and deciding what to do with those groups.
For an SME, this makes a big difference. Instead of wondering whether to use Ward, average, or complete clustering in an abstract sense, the comparison becomes practical: which method produces clearer clusters for our customers, our products, and our goals? ELECTE makes this question more accessible even without an in-house team of data scientists.
Automation, therefore, does not replace managerial judgment. It places it at the right stage of the process.
Conclusions and Key Takeaways
Agglomerative hierarchical clustering isn't just a university course topic. It's a concrete tool for bringing order to data that would otherwise remain fragmented.
There are just a few key points to keep in mind, but they are crucial:
- It starts from the bottom up. Each observation begins on its own and is progressively merged with similar ones.
- It doesn't impose k at the start. This makes the method useful when you don't yet know how many segments make sense.
- The choice of linkage changes the result. Ward, complete, average and single don't produce the same structure.
- The dendrogram helps you decide. It's not just a visualization. It's a tool for translating statistical structure into managerial action.
For an SME, this is where the real value lies: gaining a better understanding of customers, products, and operational behaviors without relying solely on intuition. If your team has technical expertise, you can start with Python and scikit-learn. If, on the other hand, you want to arrive at actionable insights more quickly, an automated approach reduces friction and saves time.
The point isn't to use an "advanced" algorithm. The point is to make clearer decisions, with more context and less noise.
If you want to turn scattered data into clear segments and operational decisions, discover how Electe makes analysis accessible even without a team of data scientists. You can connect your data sources, get readable insights, and move from analysis to action faster.

Comments
No comments yet — start the conversation.