ehrapy.plot.rank_features_supervised

ehrapy.plot.rank_features_supervised(adata, key='feature_importances', n_features=10, ax=None, show=True, save=None, **kwargs)[source]

Plot features with greates absolute importances as a barplot.

Parameters:
  • adata (AnnData) – AnnData object storing the data. A key in adata.var should contain the feature importances, calculated beforehand.

  • key (str) – The key in adata.var to use for feature importances. Defaults to ‘feature_importances’.

  • n_features (int) – The number of features to plot. Defaults to 10.

  • ax (Axes | None) – A matplotlib axes object to plot on. If None, a new figure will be created. Defaults to None.

  • show (bool) – If True, show the figure. If False, return the axes object. Defaults to True.

  • save (str | None) – Path to save the figure. If None, the figure will not be saved. Defaults to None.

  • **kwargs – Additional arguments passed to seaborn.barplot.

Return type:

Axes | None

Returns:

If show == False a matplotlib.axes.Axes object, else None.

Examples

>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> ep.pp.knn_impute(adata, n_neighbours=5)
>>> input_features = [
...     feat for feat in adata.var_names if feat not in {"service_unit", "day_icu_intime", "tco2_first"}
... ]
>>> ep.tl.rank_features_supervised(adata, "tco2_first", "rf", input_features=input_features)
>>> ep.pl.rank_features_supervised(adata)
../../_images/feature_importances.png