TorchNormalizer

class pytorch_forecasting.data.encoders.TorchNormalizer(method: str = 'standard', center: bool = True, log_scale: Union[bool, float] = False, log_zero_value: float = - inf, coerce_positive: Union[float, bool] = None, eps: float = 1e-08)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

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

Initialize

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

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

  • log_scale (bool, optional) – If to take log of values. Defaults to False. Defaults to False.

  • log_zero_value (float, optional) – Value to map 0 to for log_scale=True or in softplus. Defaults to -inf.

  • coerce_positive (Union[bool, float, str], optional) – If to coerce output to positive. Valid values: * None, i.e. is automatically determined and might change to True if all values are >= 0 (Default). * True, i.e. output is clamped at 0. * False, i.e. values are not coerced * float, i.e. softmax is applied with beta = coerce_positive.

  • eps (float, optional) – Number for numerical stability of calcualtions. Defaults to 1e-8. For count data, 1.0 is recommended.

Inherited-members

Methods

fit(y)

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

fit_transform(X[, y])

Fit to data, then transform it.

get_parameters(*args, **kwargs)

Returns parameters that were used for encoding.

get_params([deep])

Get parameters for this estimator.

inverse_transform(y)

Inverse scale.

set_params(**params)

Set the parameters of this estimator.

transform(y[, return_norm, target_scale])

Rescale data.

fit(y: Union[pandas.core.series.Series, numpy.ndarray, torch.Tensor])[source]

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

Parameters

y (Union[pd.Series, np.ndarray, torch.Tensor]) – input data

Returns

self

Return type

TorchNormalizer

get_parameters(*args, **kwargs) → torch.Tensor[source]

Returns parameters that were used for encoding.

Returns

First element is center of data and second is scale

Return type

torch.Tensor

inverse_transform(y: torch.Tensor) → torch.Tensor[source]

Inverse scale.

Parameters

y (torch.Tensor) – scaled data

Returns

de-scaled data

Return type

torch.Tensor

transform(y: Union[pandas.core.series.Series, numpy.ndarray, torch.Tensor], return_norm: bool = False, target_scale: torch.Tensor = None) → Union[Tuple[Union[numpy.ndarray, torch.Tensor], numpy.ndarray], numpy.ndarray, torch.Tensor][source]

Rescale data.

Parameters
  • y (Union[pd.Series, np.ndarray, torch.Tensor]) – input data

  • return_norm (bool, optional) – [description]. Defaults to False.

  • target_scale (torch.Tensor) – target scale to use instead of fitted center and scale

Returns

rescaled

data with type depending on input type. returns second element if return_norm=True

Return type

Union[Tuple[Union[np.ndarray, torch.Tensor], np.ndarray], Union[np.ndarray, torch.Tensor]]