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_metadata_routing()

Get metadata routing of this object.

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)

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. take log).

set_fit_request(*[, overwrite])

Request metadata passed to the fit method.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

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

Request metadata passed to the transform method.

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:

NaNLabelEncoder

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

set_fit_request(*, overwrite: bool | None | str = '$UNCHANGED$') NaNLabelEncoder#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

overwrite (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for overwrite parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, ignore_na: bool | None | str = '$UNCHANGED$', return_norm: bool | None | str = '$UNCHANGED$', target_scale: bool | None | str = '$UNCHANGED$') NaNLabelEncoder#

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
  • ignore_na (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for ignore_na parameter in transform.

  • return_norm (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for return_norm parameter in transform.

  • target_scale (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for target_scale parameter in transform.

Returns:

self – The updated object.

Return type:

object

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]