pytorch_forecasting.data.encoders.GroupNormalizer#

class pytorch_forecasting.data.encoders.GroupNormalizer(method: str = 'standard', groups: list[str] | None = None, center: bool = True, scale_by_group: bool = False, transformation: str | tuple[Callable, Callable] | None = None, method_kwargs: dict[str, Any] | None = None)[source]#

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.

Parameters:
  • method (str, optional, default="standard") – method to rescale series. Either “standard” (standard scaling) or “robust” (scale using quantiles 0.25-0.75). Defaults to “standard”.

  • method_kwargs (Dict[str, Any], optional, default=None) –

    Dictionary of method specific arguments as listed below

    • ”robust” method: “upper”, “lower”, “center” quantiles defaulting to 0.75, 0.25 and 0.5

  • groups (List[str], optional, default=[]) – Group names to normalize by. Defaults to [].

  • center (bool, optional, default=True) – 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.

  • transformation (Union[str, Tuple[Callable, Callable]] optional, default=None):) –

    Transform values before applying normalizer. Available options are

    • None (default): No transformation of values

    • log: Estimate in log-space leading to a multiplicative model

    • log1p: Estimate in log-space but add 1 to values before transforming for stability

      (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

    • count: Apply softplus to output (inverse transformation) and x + 1 to input

      (transformation)

    • softplus: Apply softplus to output (inverse transformation) and inverse softplus to input

      (transformation)

    • relu: Apply max(0, x) to output

    • Dict[str, Callable] of PyTorch functions that transforms and inversely transforms values. forward and reverse entries are required. inverse transformation is optional and should be defined if reverse is not the inverse of the forward transformation. inverse_torch can be defined to provide a torch distribution transform for inverse transformations.

__init__(method: str = 'standard', groups: list[str] | None = None, center: bool = True, scale_by_group: bool = False, transformation: str | tuple[Callable, Callable] | None = None, method_kwargs: dict[str, Any] | None = None)[source]#

Group normalizer to normalize a given entry by groups. Can be used as target normalizer.

Parameters:
  • method (str, optional, default="standard") – method to rescale series. Either “standard” (standard scaling) or “robust” (scale using quantiles 0.25-0.75). Defaults to “standard”.

  • method_kwargs (Dict[str, Any], optional, default=None) –

    Dictionary of method specific arguments as listed below

    • ”robust” method: “upper”, “lower”, “center” quantiles defaulting to 0.75, 0.25 and 0.5

  • groups (List[str], optional, default=[]) – Group names to normalize by. Defaults to [].

  • center (bool, optional, default=True) – 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.

  • transformation (Union[str, Tuple[Callable, Callable]] optional, default=None):) –

    Transform values before applying normalizer. Available options are

    • None (default): No transformation of values

    • log: Estimate in log-space leading to a multiplicative model

    • log1p: Estimate in log-space but add 1 to values before transforming for stability

      (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

    • count: Apply softplus to output (inverse transformation) and x + 1 to input

      (transformation)

    • softplus: Apply softplus to output (inverse transformation) and inverse softplus to input

      (transformation)

    • relu: Apply max(0, x) to output

    • Dict[str, Callable] of PyTorch functions that transforms and inversely transforms values. forward and reverse entries are required. inverse transformation is optional and should be defined if reverse is not the inverse of the forward transformation. inverse_torch can be defined to provide a torch distribution transform for inverse transformations.

Methods

__call__(data)

Inverse transformation but with network output as input.

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getstate__()

Helper for pickle.

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init_subclass__(**kwargs)

Set the set_{method}_request methods.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(*args, **kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__setstate__(state)

__sizeof__()

Size of object in memory, in bytes.

__sklearn_clone__()

__sklearn_tags__()

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_get_class_level_metadata_request_values(...)

Get class level metadata request values.

_get_doc_link()

Generates a link to the API documentation for a given estimator.

_get_fitted_attr_html([doc_link])

Get fitted attributes of the estimator.

_get_metadata_request()

Get requested metadata for the instance.

_get_param_names()

Get parameter names for the estimator

_get_params_html([deep, doc_link])

Get parameters for this estimator with a specific HTML representation.

_html_repr()

Build an HTML representation of an estimator.

_repr_html_inner()

This function is returned by the @property _repr_html_ to make hasattr(estimator, "_repr_html_") return `True or False depending on get_config()["display"].

_repr_mimebundle_(**kwargs)

Mime bundle used by jupyter kernels to display estimator

_set_parameters(y_center, y_scale)

Calculate parameters for scale and center based on input timeseries

_validate_params()

Validate types and values of constructor parameters

extra_repr()

Return extra information about parameters for representation/logging.

fit(y, X)

Determine scales for each group

fit_transform(y, X[, return_norm])

Fit normalizer and scale input data.

get_metadata_routing()

Get metadata routing of this object.

get_norm(X)

Get scaling parameters for multiple groups.

get_parameters(groups[, group_names])

Get fitted scaling parameters for a given group.

get_params([deep])

Get parameters for this estimator.

get_transform(transformation)

Return transformation functions.

inverse_preprocess(y)

Inverse preprocess re-scaled data (e.g. take exp).

inverse_transform(y, X)

Rescaling data to original scale - not implemented - call class with target scale instead.

preprocess(y)

Preprocess input data (e.g. take log).

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

set_transform_request(*[, return_norm, ...])

Configure whether metadata should be requested to be passed to the transform method.

transform(y[, X, return_norm, target_scale])

Scale input data.

Attributes

TRANSFORMATIONS

__annotations__

__dict__

__doc__

__module__

__weakref__

list of weak references to the object

_doc_link_module

_doc_link_template

_doc_link_url_param_generator

_repr_html_

HTML representation of estimator.

_sklearn_auto_wrap_output_keys

names

Names of determined scales.