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 greatest 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, default: 'feature_importances') – The key in adata.var to use for feature importances.

  • n_features (int, default: 10) – The number of features to plot.

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

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

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

  • **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_neighbors=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