# Remove outliers from trained scVI model

**URL:** <https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165>\
**Category:** scvi-tools\
**Tags:** integration, scvi\
**Created:** [March 16, 2024, 3:23am UTC](https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165 "2024-03-16T03:23:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph-siefert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joseph-siefert/32/789_2.png) [@joseph-siefert](https://discourse.scverse.org/u/joseph-siefert)\
**Post date:** [March 16, 2024, 3:23am UTC](https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165/1 "2024-03-16T03:23:35Z")

</div>

Thanks for the great framework! On occasion when I build a model for a particular cell type, the majority of the cells cluster together while some are severe outliers and clearly not of the same cell type. I can easily remove these cells, however then they are absent from the trained model, so I cannot load the model with that dataset or perform differential expression. Is there a simple way to update the trained model with the outliers excluded, without having to train a new model?

---

<div class="post-metadata">

**Author:** ![Valentine\_Svensson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/valentine_svensson/32/10_2.png) [@Valentine\_Svensson](https://discourse.scverse.org/u/Valentine_Svensson)\
**Post date:** [March 19, 2024, 10:12pm UTC](https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165/2 "2024-03-19T22:12:01Z")

</div>

You should be able to use the model in any way regardless if you have removed some cells from the dataset.

What kind of error are you seeing?

---

<div class="post-metadata">

**Author:** ![joseph-siefert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/joseph-siefert/32/789_2.png) [@joseph-siefert](https://discourse.scverse.org/u/joseph-siefert)\
**Post date:** [March 20, 2024, 12:58am UTC](https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165/3 "2024-03-20T00:58:16Z")

</div>

I could still use it, but the cells, which are clearly outliers, are still included and will affect analysis performed with the model. For example, if I recompute neighbors from the latent space the projections only get worse. The model still seems to still retain information regarding the outlier cells in the latent space. My concern is this also affects the batch conditioning, normalization, and DEG. Similarly, in order to perform DE I would need to do some fancy indexing to exclude the outlier cells. Would be much easier and cleaner if it was possible to update the model.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [March 23, 2024, 9:22pm UTC](https://discourse.scverse.org/t/remove-outliers-from-trained-scvi-model/2165/4 "2024-03-23T21:22:41Z")

</div>

You can pass indices to most downstream tasks or an AnnData object. If you pass your filtered objects you will get the results on only those cells. In the DE function there is an ‘importance’ weighting. Enabling this downweights the effect that these outliers will have without removing those. This downweighting is described in: [https://www.pnas.org/doi/full/10.1073/pnas.2209124120](https://www.pnas.org/doi/full/10.1073/pnas.2209124120)
