NaNLabelEncoder#
- class pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan: bool = False, warn: bool = True)[source]#
Bases:
InitialParameterRepresenterMixIn
,BaseEstimator
,TransformerMixin
,TransformMixIn
Labelencoder that can optionally always encode nan and unknown classes (in transform) as class
0
init NaNLabelEncoder
- Parameters:
add_nan – if to force encoding of nan at 0
warn – if to warn if additional nans are added because items are unknown
- Inherited-members:
Methods
extra_repr
()fit
(y[, overwrite])Fit transformer
fit_transform
(y[, overwrite])Fit and transform data.
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.
Decode data, i.e. transform from integers to labels.
is_numeric
(y)Determine if series is numeric or not.
preprocess
(y)Preprocess input data (e.g.
set_output
(*[, transform])Set output container.
set_params
(**params)Set the parameters of this estimator.
transform
(y[, return_norm, target_scale, ...])Encode iterable with integers.
Attributes
TRANSFORMATIONS
- fit(y: Series, overwrite: bool = False)[source]#
Fit transformer
- Parameters:
y (pd.Series) – input data to fit on
overwrite (bool) – if to overwrite current mappings or if to add to it.
- Returns:
self
- Return type:
- fit_transform(y: Series, overwrite: bool = False) ndarray [source]#
Fit and transform data.
- Parameters:
y (pd.Series) – input data
overwrite (bool) – if to overwrite current mappings or if to add to it.
- Returns:
encoded data
- Return type:
np.ndarray
- get_parameters(groups=None, group_names=None) ndarray [source]#
Get fitted scaling parameters for a given group.
All parameters are unused - exists for compatability.
- Returns:
zero array.
- Return type:
np.ndarray
- inverse_transform(y: Tensor | ndarray) ndarray [source]#
Decode data, i.e. transform from integers to labels.
- Parameters:
y (Union[torch.Tensor, np.ndarray]) – encoded data
- Raises:
KeyError – if unknown elements should be decoded
- Returns:
decoded data
- Return type:
np.ndarray
- static is_numeric(y: Series) bool [source]#
Determine if series is numeric or not. Will also return True if series is a categorical type with underlying integers.
- Parameters:
y (pd.Series) – series for which to carry out assessment
- Returns:
True if series is numeric
- Return type:
bool
- transform(y: Iterable, return_norm: bool = False, target_scale=None, ignore_na: bool = False) Tensor | ndarray [source]#
Encode iterable with integers.
- Parameters:
y (Iterable) – iterable to encode
return_norm – only exists for compatability with other encoders - returns a tuple if true.
target_scale – only exists for compatability with other encoders - has no effect.
ignore_na (bool) – if to ignore na values and map them to zeros (this is different to add_nan=True option which maps ONLY NAs to zeros while this options maps the first class and NAs to zeros)
- Returns:
returns encoded data as torch tensor or numpy array depending on input type
- Return type:
Union[torch.Tensor, np.ndarray]