Blog/Complete Clustering Guide

Statistics

Complete Clustering Guide

Master K-Means, DBSCAN, SOM and All Clustering Algorithms

SK

Skari Team

Skari

July 2026·18 min read

Clustering

An analysis that automatically groups data by similarity, without any labels.

Cluster Analysis

K-Means · k=3

Cluster 1Cluster 2Cluster 3

One of the most common techniques you'll encounter when starting data analysis is clustering.

Whether you want to segment customers, group survey respondents by similarity, or detect anomalous transactions, clustering is used across industries.

Note

Many people think of K-Means as the default clustering algorithm, but it's not suitable for all data. Depending on your data shape and analysis goal, DBSCAN, Hierarchical Clustering, GMM, Fuzzy C-Means, or SOM may deliver better results.

What is Clustering?

Clustering is an unsupervised learning technique that automatically groups data points with similar characteristics.

Unlike supervised learning which requires labeled data, unsupervised learning finds hidden patterns and structure in unlabeled data on its own.

Concrete Example

  • Customer A: Age 20s, Monthly spend $3,000, 10 visits
  • Customer B: Age 20s, Monthly spend $2,800, 9 visits
  • Customer C: Age 50s, Monthly spend $500, 2 visits

Clustering automatically groups A and B together (high-value customers) and C in a separate group (low-frequency customer).

Distance Metrics

In clustering, "similarity" is determined by distance or similarity measures.

Watch out

Your choice of distance metric significantly impacts clustering results. Select the one that best fits your data.

Distance Metrics

Euclidean measures the straight line; Manhattan follows the grid, block by block.

AB
Euclidean Manhattan

Euclidean Distance

The most commonly used distance metric. It measures the straight-line distance between two points and is K-Means' default.

  • Intuitive and computationally simple
  • Effective for normally distributed data
  • Sensitive to outliers

Manhattan Distance

Calculates distance as if traveling along city blocks. More stable for high-dimensional data.

Cosine Similarity

Measures the angle between vectors. Highly effective for text analysis and document similarity.

What Makes a Good Cluster?

Before choosing an algorithm, it helps to define what "good" even means. A good clustering satisfies two simple ideas:

  • Points in the same cluster are close together
  • Points in different clusters are far apart

These two ideas have names. Cohesion measures how tight a cluster is (how close its own points are), and separation measures how far apart different clusters sit. A good clustering has high cohesion and high separation.

Note

This is exactly what the Silhouette Score captures: for each point, it compares cohesion (distance to its own cluster) against separation (distance to the nearest other cluster). Values near +1 mean well-separated, tight clusters; values near 0 mean overlapping ones.

Major Algorithms

K-Means

K-Means is the most popular clustering algorithm. It efficiently finds clusters in numeric data.

Advantages

  • Very fast computation
  • Simple to implement
  • Suitable for large datasets

Disadvantages

  • Must specify number of clusters (K) beforehand
  • Sensitive to outliers
  • Works best on spherical clusters

Note

Finding optimal K: Elbow Method, Silhouette Score, Gap Statistic

Elbow Method

choosing k

Inertia drops sharply, then flattens. The 'elbow' — here k=3 — is a good choice.

1234567optimal k=3

DBSCAN

DBSCAN is a density-based clustering algorithm. Its key feature: it automatically identifies noise (outliers)!

Recommended for:

  • GPS data (location-based services)
  • Anomaly detection
  • Irregularly shaped clusters

DBSCAN

density-based

Dense regions form clusters; isolated points are labelled noise — no k required.

Core Border Noise

Hierarchical Clustering

Hierarchical clustering builds a tree of nested groups — repeatedly merging the two closest clusters — and draws it as a dendrogram. Its defining advantage: you don't set the number of clusters up front.

  • Produces a dendrogram — a full tree of how points merge
  • You choose the number of clusters afterward, by cutting the tree at a height
  • Reveals the nested structure, not just a flat partition

Reach for it when you don't know K in advance, or when the grouping itself has a hierarchy (e.g. products within categories within departments).

GMM (Gaussian Mixture Model)

K-Means forces each point into exactly one cluster. GMM instead models the data as a mix of Gaussian "blobs" and gives each point a probability of belonging to each cluster — soft assignment rather than hard.

  • Handles clusters that overlap, where a point could plausibly belong to two
  • Fits elliptical (stretched) clusters, not just the spheres K-Means assumes
  • Returns membership probabilities — useful when the boundary is genuinely fuzzy

Choose GMM when your clusters overlap or aren't round, and when you want a confidence, not just a label.

Spectral Clustering

Spectral clustering is the tool for clusters that aren't blob-shaped at all — concentric rings, spirals, or other non-linear structures that K-Means and GMM get completely wrong. It builds a similarity graph of the points and cuts it into groups using the graph's eigenvectors.

  • Captures non-linear, non-convex shapes (rings, crescents, chains)
  • Works from connectivity, not straight-line distance to a center
  • More computationally expensive, so best for small-to-medium datasets

SOM (Self-Organizing Map)

SOM is a neural network-based algorithm for dimensionality reduction and clustering. It visualizes high-dimensional data in 2D or 3D grids while simultaneously performing clustering.

SOM Advantages:

  • Visualize high-dimensional data on 2D plane
  • Understand complex patterns intuitively
  • Preserve data topology (geometric structure)

Self-Organizing Map

SOM

SOM projects high-dimensional data onto a 2-D grid; neighbouring cells stay similar.

Which Algorithm Should You Use?

This is the question everyone actually has: given my data, what do I run? Match your data's characteristic to the algorithm built for it.

Data characteristicRecommended algorithm
Round, well-separated clustersK-Means
Number of clusters unknownHierarchical Clustering
Lots of noise / outliersDBSCAN or HDBSCAN
Clusters overlapGMM (Gaussian Mixture)
High-dimensional, need visualizationSOM
Non-linear structure (rings, spirals)Spectral Clustering

Tip

When you're unsure, start with K-Means as a baseline, then try the algorithm that matches your data's quirk — and compare them with the Silhouette Score rather than trusting one by default.

Clustering with SKARI Platform

SKARI is an integrated data analytics platform that makes clustering accessible without coding.

Key SKARI Advantages

  • No coding required: Drag-and-drop UI for analysis workflows
  • Automated preprocessing: Data normalization and outlier handling
  • Auto algorithm selection: Platform recommends optimal algorithm
  • Built-in visualization: Charts and graphs generated automatically
  • Easy deployment: Export trained models as APIs

Real-World Example: Customer Segmentation

Result: 100,000 online retail customers segmented into 5 groups

  • VIP customers (5,000) → Personalized premium services
  • Active customers (25,000) → Early access to new products
  • Regular customers (45,000) → Regular newsletters
  • New customers (20,000) → Welcome discount coupons
  • At-risk customers (5,000) → Retention campaigns

Takeaway

With SKARI, you can complete this entire analysis in 2 hours instead of weeks.

Frequently Asked Questions

Q1. How do I determine the optimal K?

Use Elbow Method, Silhouette Score, or Gap Statistic to find the optimal number of clusters.

Q2. How is SOM different from K-Means?

K-Means partitions data into K groups, while SOM visualizes data on a 2D/3D grid while clustering simultaneously.

Q3. Which algorithm for very large datasets?

For over 1 million rows, K-Means is fastest. For visualization, use Mini-Batch K-Means or SOM in batch mode.

Conclusion

Here's the key takeaway: While K-Means is the most famous clustering algorithm, it's not a universal solution.

Takeaway

In practice, compare multiple algorithms using evaluation metrics (Silhouette Score, Davies-Bouldin Index, Calinski-Harabasz Index) to select the best clustering for your specific data and goals.

Data Normalization Guide

Essential preprocessing techniques before clustering

Advanced Clustering Techniques

Ensemble clustering and multi-level analysis

Getting Started with SKARI

Complete your first clustering project in 5 minutes