pytorch_forecasting.data.encoders.TorchNormalizer#

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

Basic target transformer that can be fit also on torch tensors.

Parameters:
  • method (str, optional, default="standard") – method to rescale series. Either “identity”, “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

  • center (bool, optional, default=True) – If to center the output to zero. Defaults to True.

  • transformation (Union[str, Dict[str, 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', center: bool = True, transformation: str | tuple[Callable, Callable] = None, method_kwargs: dict[str, Any] | None = None)[source]#
Parameters:
  • method (str, optional, default="standard") – method to rescale series. Either “identity”, “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

  • center (bool, optional, default=True) – If to center the output to zero. Defaults to True.

  • transformation (Union[str, Dict[str, 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)

Fit transformer, i.e. determine center and scale of data.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_parameters(*args, **kwargs)

Returns parameters that were used for encoding.

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)

Inverse scale.

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[, return_norm, target_scale])

Rescale 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