ehrapy.anndata.infer_feature_types¶
- ehrapy.anndata.infer_feature_types(adata, layer=None, output='tree', verbose=True)[source]¶
Infer feature types from AnnData object.
For each feature in adata.var_names, the method infers one of the following types: ‘date’, ‘categorical’, or ‘numeric’. The inferred types are stored in adata.var[‘feature_type’]. Please check the inferred types and adjust if necessary using adata.var[‘feature_type’][‘feature1’]=’corrected_type’. Be aware that not all features stored numerically are of ‘numeric’ type, as categorical features might be stored in a numerically encoded format. For example, a feature with values [0, 1, 2] might be a categorical feature with three categories. This is accounted for in the method, but it is recommended to check the inferred types.
- Parameters:
layer (
str
|None
, default:None
) – The layer to use from the AnnData object. If None, the X layer is used.output (
Optional
[Literal
['tree'
,'dataframe'
]], default:'tree'
) – The output format. Choose between ‘tree’, ‘dataframe’, or None. If ‘tree’, the feature types will be printed to the console in a tree format. If ‘dataframe’, a pandas DataFrame with the feature types will be returned. If None, nothing will be returned.verbose (
bool
, default:True
) – Whether to print warnings for uncertain feature types.
Examples
>>> import ehrapy as ep >>> adata = ep.dt.mimic_2(encoded=False) >>> ep.ad.infer_feature_types(adata)