TorchNormalizer¶
- class pytorch_forecasting.data.encoders.TorchNormalizer(method: str = 'standard', center: bool = True, transformation: Optional[Union[str, Tuple[Callable, Callable]]] = None, eps: float = 1e-08)[source]¶
Bases:
sklearn.base.BaseEstimator,sklearn.base.TransformerMixinBasic target transformer that can be fit also on torch tensors.
Initialize
- Parameters
method (str, optional) – method to rescale series. Either “identity”, “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.
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
- logp1: 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
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 calculations. Defaults to 1e-8.
- 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 preprocess re-scaled data (e.g.
Inverse scale.
preprocess(y)Preprocess input data (e.g.
set_params(**params)Set the parameters of this estimator.
transform(y[, return_norm, target_scale])Rescale data.
Attributes
TRANSFORMATIONS- 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
- 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_preprocess(y: Union[pandas.core.series.Series, numpy.ndarray, torch.Tensor]) Union[numpy.ndarray, torch.Tensor][source]¶
Inverse preprocess re-scaled data (e.g. take exp).
Uses
transformattribute to determine how to apply inverse transform.- Returns
return rescaled series with type depending on input type
- Return type
Union[np.ndarray, 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
- preprocess(y: Union[pandas.core.series.Series, pandas.core.frame.DataFrame, numpy.ndarray, torch.Tensor]) Union[numpy.ndarray, torch.Tensor][source]¶
Preprocess input data (e.g. take log).
Uses
transformattribute to determine how to apply transform.- Returns
return rescaled series with type depending on input type
- Return type
Union[np.ndarray, torch.Tensor]
- transform(y: Union[pandas.core.series.Series, numpy.ndarray, torch.Tensor], return_norm: bool = False, target_scale: Optional[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]]