ehrapy.preprocessing.scale_norm#
- ehrapy.preprocessing.scale_norm(edata, vars=None, group_key=None, layer=None, copy=False, **kwargs)[source]#
Apply scaling normalization.
Functionality is provided by
StandardScaler, see https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html for details. If edata.X is a Dask Array, functionality is provided byStandardScaler, see https://ml.dask.org/modules/generated/dask_ml.preprocessing.StandardScaler.html for details.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 usingencode().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.copy (
bool, default:False) – Whether to return a copy or act in place.**kwargs – Additional arguments passed to the StandardScaler.
- Return type:
- 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.nanmean(edata.layers["tem_data"]) 74.213570 >>> ep.pp.scale_norm(edata, layer="tem_data") >>> np.nanmean(edata.layers["tem_data"]) 0.0