Graph-based clustering is an unsupervised learning method that partitions cells into distinct populations by first constructing a k-nearest neighbor (KNN) graph from a reduced-dimensional representation, such as PCA space. Each cell becomes a node, and edges connect cells with highly similar transcriptomic profiles. The core principle is that cells belonging to the same biological type will form dense, highly intra-connected neighborhoods within this graph structure, while distinct cell types remain sparsely connected.
Glossary
Graph-Based Clustering

What is Graph-Based Clustering?
Graph-based clustering is an unsupervised machine learning technique that partitions data points into groups by representing them as nodes in a nearest-neighbor graph and applying community detection algorithms to identify densely connected subgraphs.
After graph construction, community detection algorithms like the Louvain or Leiden algorithm are applied to optimize a modularity function, iteratively merging nodes to maximize the density of connections within communities versus between them. The Leiden algorithm is generally preferred for its guarantee of well-connected communities and faster convergence. This approach scales efficiently to millions of cells, robustly captures complex, non-spherical cluster topologies that density-based methods miss, and has become the standard clustering backbone in single-cell analysis frameworks like Seurat and Scanpy.
Key Features of Graph-Based Clustering
Graph-based clustering partitions cells by constructing a nearest-neighbor network and applying community detection. This approach excels at capturing complex, non-linear relationships in high-dimensional single-cell data.
Nearest-Neighbor Graph Construction
The foundational step where each cell is connected to its k most similar neighbors based on a distance metric (typically Euclidean distance in PCA space). This transforms the data into a graph object where nodes represent cells and edges represent transcriptomic similarity. The choice of k directly influences cluster resolution—smaller values detect fine substructure, while larger values produce broader groupings.
Shared Nearest Neighbor (SNN) Refinement
Raw k-NN graphs are refined into a Shared Nearest Neighbor graph to emphasize robust connections. The edge weight between two cells is calculated based on the overlap in their neighborhoods (Jaccard index). This step effectively denoises the graph by down-weighting spurious connections and strengthening edges between cells that share many common neighbors, improving cluster separation.
Louvain Community Detection
A greedy optimization algorithm that partitions the graph by iteratively moving nodes between communities to maximize modularity—a measure comparing edge density within communities versus a random null model. Louvain is computationally fast and widely implemented in tools like Seurat and Scanpy, though it can occasionally produce arbitrarily badly connected communities.
Leiden Algorithm
An improvement over Louvain that guarantees well-connected communities by adding an intermediate refinement phase after the initial partition. The Leiden algorithm runs through three phases: local moving, refinement, and network aggregation. This ensures that all clusters are internally connected subgraphs, avoiding the fragmentation artifacts sometimes observed with Louvain. It is now the default in Scanpy.
Resolution Parameter Tuning
A critical hyperparameter controlling the granularity of clustering. Higher resolution values produce more, smaller clusters; lower values yield fewer, larger clusters. Optimal resolution is often determined empirically by inspecting cluster stability, marker gene specificity, and biological plausibility. Tools like clustree help visualize cluster assignments across a range of resolutions.
Modularity Optimization
The mathematical objective function underlying Louvain and Leiden. Modularity quantifies the strength of division of a network into communities. It compares the fraction of edges within communities to the expected fraction if edges were distributed randomly. Maximizing this score identifies partitions where intra-community connections are denser than expected by chance, defining biologically meaningful cell groups.
Frequently Asked Questions
Graph-based clustering is the dominant paradigm for partitioning cells in single-cell RNA sequencing studies. These FAQs address the core mechanisms, algorithmic choices, and practical considerations that immunology researchers and core facility directors encounter when moving from a count matrix to discrete cell populations.
Graph-based clustering is an unsupervised learning method that partitions cells into groups by first constructing a k-nearest neighbor (KNN) graph from a reduced dimensionality representation, then applying a community detection algorithm to identify densely connected modules. The process begins with a cell-by-cell distance matrix computed in PCA space. Each cell is connected to its k most similar neighbors, forming a shared nearest neighbor (SNN) graph where edge weights represent the overlap in neighborhoods. The Louvain or Leiden algorithm then optimizes a modularity function, iteratively merging cells into clusters that maximize intra-cluster connections while minimizing inter-cluster links. Unlike traditional k-means, graph-based clustering does not assume spherical cluster shapes and can capture complex, branching topologies characteristic of developmental trajectories and immune cell continua.
Louvain vs. Leiden Algorithm
A technical comparison of the two primary modularity-based community detection algorithms used for partitioning single-cell nearest-neighbor graphs into biologically meaningful clusters.
| Feature | Louvain Algorithm | Leiden Algorithm |
|---|---|---|
Optimization Objective | Modularity maximization | Modularity maximization with refinement |
Guarantees connected communities | ||
Resolution parameter support | ||
Iterative refinement step | ||
Typical cluster quality | High | Higher |
Speed on large graphs (>100K cells) | Fast | Comparable |
Susceptibility to badly connected communities | Yes | No |
Default in Scanpy (legacy) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core algorithms, validation metrics, and foundational concepts that underpin community detection in single-cell nearest-neighbor graphs.
Louvain Algorithm
A greedy modularity optimization method that partitions the k-nearest neighbor (KNN) graph into communities. It iteratively moves nodes between communities to maximize the modularity score, a measure of connection density within groups versus between groups. Louvain is computationally fast but can produce arbitrarily poorly connected communities. It remains the default in Seurat and Scanpy workflows.
Leiden Algorithm
An improvement over Louvain that guarantees well-connected communities by adding a refinement phase. After the initial modularity optimization, Leiden splits clusters into sub-communities before aggregation, ensuring all partitions are internally connected. This prevents the fragmentation artifacts observed in Louvain and typically yields higher-quality biological partitions. It is the recommended default for Traag et al. implementations.
Modularity Score
A scalar metric evaluating the strength of division of a network into communities. It compares the fraction of edges within communities to the expected fraction if edges were distributed randomly. Values range from -0.5 to 1, with positive scores indicating more intra-community edges than expected by chance. Modularity is the objective function optimized by both Louvain and Leiden algorithms.
K-Nearest Neighbor (KNN) Graph
The foundational graph structure where each cell is a node connected to its k most similar cells based on a distance metric, typically Euclidean distance in PCA space. The choice of k critically influences clustering granularity: small values produce many small clusters, while large values merge distinct populations. Typical values range from 5 to 50 neighbors, often scaled relative to dataset size.
Shared Nearest Neighbor (SNN) Graph
A refinement of the KNN graph where edge weights represent the Jaccard similarity between the neighborhoods of two cells. Two cells are strongly connected if they share many common neighbors, reducing noise and emphasizing robust local density relationships. The SNN graph is the standard input for Louvain and Leiden clustering in single-cell analysis pipelines.
Resolution Parameter
A user-defined hyperparameter controlling the granularity of community detection. Higher resolution values produce more clusters by favoring smaller, finer partitions; lower values yield fewer, broader clusters. In Seurat, the default is 0.8, while Scanpy defaults to 1.0. Optimal resolution is typically determined by inspecting cluster stability and biological coherence rather than applying a fixed value.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us