Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc.pp.neighbors values #3497

Closed
QuentinPerriere opened this issue Mar 4, 2025 · 2 comments
Closed

sc.pp.neighbors values #3497

QuentinPerriere opened this issue Mar 4, 2025 · 2 comments

Comments

@QuentinPerriere
Copy link

What kind of feature would you like to request?

Additional function parameters / changed functionality / changed defaults?

Please describe your wishes

Hello,
How can I choose appropriate values for sc.pp.neighbors(self.adata, n_neighbors=X, n_pcs=Y)?

thank you in advance !!

@QuentinPerriere QuentinPerriere added the Triage 🩺 This issue needs to be triaged by a maintainer label Mar 4, 2025
@maltekuehl
Copy link

This will depend on your data and the question you are trying to answer. In the context of clustering of single cell data, you typically would use between 5 and 100 neighbors depending on your dataset size and variance. The number of PCs is commonly set to the number of PCs that explain 90% or 95% of variance in your data as you would like to preserve as much biological information as possible but late PCs often capture technical noise. The optimal neighbor count will also depend on what you are trying to detect, e.g., would you like to cluster broad cell types or smaller subtypes? The best way to choose a value is a grid search, combining n_neighbors of the neighbors function and the resolution parameter of leiden. Then, you can use standard clustering metrics (ARI, silhouette, modularity, etc.) to evaluate the clustering and visualize the results and get the cluster defining genes (PanglaoDb is a good resource for marker genes) to check for biological plausibility. pyclustree (disclaimer, I'm the author) also allows you to plot gene expression or other variables in a flow diagram of different clustering runs. The example only shows this for variations of the resolution parameter of leiden, but you can easily adapt this to also include different values for n_neighbors.

@Zethson
Copy link
Member

Zethson commented Mar 10, 2025

Such questions are better suited for https://discourse.scverse.org/. Thank you very much for answering @maltekuehl though!

@Zethson Zethson closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2025
@flying-sheep flying-sheep removed the Triage 🩺 This issue needs to be triaged by a maintainer label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants