# How to decide number of neighbors and resolution for Louvain clustering

I am using Louvain clustering (1,2) to cluster cells in scRNAseq data, as implemented by scanpy.

One of the parameter required for this kind of clustering is the number of neighbors used to construct the neighborhood graph of cells (docs).

Larger values result in a more global view of the manifold, leading to lower number of clusters, while reducing the number of neighbors goes in the opposite direction. However, it is unclear how to choose this parameter.

The resolution parameter seems to work in the opposite way.

Do you know of any methodology and/or rule-of-thumb to define these parameters? E.g. depending on the size of the dataset?

1. Levine, Jacob H., et al. "Data-driven phenotypic dissection of AML reveals progenitor-like cells that correlate with prognosis." Cell 162.1 (2015): 184-197.
2. Blondel, Vincent D., et al. "Fast unfolding of communities in large networks." Journal of statistical mechanics: theory and experiment 2008.10 (2008): P10008.
• The Louvian algorithm has an issue with disconnected communities. The Leiden algorithm is recommended to resolve this. See Traag et al. arxiv.org/abs/1810.08473 Nov 22 '18 at 15:16
• If I remember correctly the phenograph paper shows that their algorithm is fairly robust for different (reasonable) values for k. Dec 10 '18 at 9:10
• @gc5 did you get the answer? I also want to know what is the best resolution ? As we can get more communities when we increase resolution and vice-versa. Thanks May 30 '19 at 8:02
• @KhalidUsman no satisfying answer so far.
– gc5
May 30 '19 at 14:37

A general rule of thumb is that in order to improve the variance $n$ times you need $n^2$ neighbours. This is only applicable if you consider the $n^2$ nearest neighbours of a cell to be biologically identical (i.e. "similar enough"); if your data includes 10 types of cells with 10 cells each, then using the 20 nearest neighbours for smoothing will obscure the data.