ehrapy.preprocessing.maxabs_norm

Contents

ehrapy.preprocessing.maxabs_norm#

ehrapy.preprocessing.maxabs_norm(edata, vars=None, group_key=None, layer=None, copy=False)[source]#

Apply max-abs normalization.

Functionality is provided by MaxAbsScaler, see https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MaxAbsScaler.html for details. Note: Dask arrays are not supported for this function. Please convert to numpy array first.

Supports both 2D and 3D data:

  • 2D data: Standard normalization across observations

  • 3D data: Per-variable normalization across samples and timestamps

Parameters:
  • edata (EHRData) – Central data object. Must already be encoded using encode().

  • vars (str | Sequence[str] | None, default: None) – List of the names of the numeric variables to normalize. If None all numeric variables will be normalized.

  • group_key (str | None, default: None) – Key in edata.obs that contains group information. If provided, scaling is applied per group.

  • layer (str | None, default: None) – The layer to normalize.

  • copy (bool, default: False) – Whether to return a copy or act in place.

Return type:

EHRData | None

Returns:

None if copy=False and modifies the passed edata, else returns an updated object. Also stores a record of applied normalizations as a dictionary in edata.uns[“normalization”].

Examples

>>> import ehrdata as ed
>>> import ehrapy as ep
>>> import numpy as np
>>> edata = ed.dt.physionet2012(layer="tem_data")
>>> np.nanmax(np.abs(edata.layers["tem_data"]))
36400.0
>>> ep.pp.maxabs_norm(edata, layer="tem_data")
>>> np.nanmax(np.abs(edata.layers["tem_data"]))
1.0