pytorch_forecasting.data.encoders.
GroupNormalizer
Bases: pytorch_forecasting.data.encoders.TorchNormalizer
pytorch_forecasting.data.encoders.TorchNormalizer
Normalizer that scales by groups.
For each group a scaler is fitted and applied. This scaler can be used as target normalizer or also to normalize any other variable.
Group normalizer to normalize a given entry by groups. Can be used as target normalizer.
method (str, optional) – method to rescale series. Either “standard” (standard scaling) or “robust” (scale using quantiles 0.25-0.75). Defaults to “standard”.
groups (List[str], optional) – Group names to normalize by. Defaults to [].
center (bool, optional) – If to center the output to zero. Defaults to True.
scale_by_group (bool, optional) – If to scale the output by group, i.e. norm is calculated as (group1_norm * group2_norm * ...) ^ (1 / n_groups). Defaults to False.
(group1_norm * group2_norm * ...) ^ (1 / n_groups)
transformation (Union[str, Tuple[Callable, Callable]] optional) –
Transform values before applying normalizer. Available options are
None (default): No transformation of values
log: Estimate in log-space leading to a multiplicative model
(e.g. if many small values <<1 are present). Note, that inverse transform is still only torch.exp() and not torch.expm1().
logit: Apply logit transformation on values that are between 0 and 1
softplus: Apply softplus to output (inverse transformation) and x + 1 to input (transformation)
relu: Apply max(0, x) to output
Tuple[Callable, Callable] of PyTorch functions that transforms and inversely transforms values.
eps (float, optional) – Number for numerical stability of calcualtions. Defaults to 1e-8. For count data, 1.0 is recommended.
Methods
fit(y, X)
fit
Determine scales for each group
fit_transform(y, X[, return_norm])
fit_transform
Fit normalizer and scale input data.
get_norm(X)
get_norm
Get scaling parameters for multiple groups.
get_parameters(groups[, group_names])
get_parameters
Get fitted scaling parameters for a given group.
get_params([deep])
get_params
Get parameters for this estimator.
inverse_preprocess(y)
inverse_preprocess
Inverse preprocess re-scaled data (e.g.
inverse_transform(y, X)
inverse_transform
Rescaling data to original scale - not implemented - call class with target scale instead.
preprocess(y)
preprocess
Preprocess input data (e.g.
set_params(**params)
set_params
Set the parameters of this estimator.
transform(y[, X, return_norm, target_scale])
transform
Scale input data.
Attributes
TRANSFORMATIONS
names
Names of determined scales.
y (pd.Series) – input data
X (pd.DataFrame) – dataframe with columns for each group defined in groups parameter.
groups
self
y (pd.Series) – data to scale
X (pd.DataFrame) – dataframe with groups columns
return_norm (bool, optional) – If to return . Defaults to False.
return_norm=True
as second element
Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]
dataframe with scaling parameterswhere each row corresponds to the input dataframe
pd.DataFrame
groups (Union[torch.Tensor, list, tuple]) – group ids for which to get parameters
group_names (List[str], optional) – Names of groups corresponding to positions in groups. Defaults to None, i.e. the instance attribute groups.
parameters used for scaling
np.ndarray
target_scale (torch.Tensor) – target scale to use instead of fitted center and scale
list of names
List[str]