NaNLabelEncoder

class pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan: bool = False, warn: bool = True)[source]

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

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

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.

inverse_transform(y)

Decode data, i.e. transform from integers to labels.

is_numeric(y)

Determine if series is numeric or not.

set_params(**params)

Set the parameters of this estimator.

transform(y[, return_norm, target_scale, ...])

Encode iterable with integers.

fit(y: pandas.core.series.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: pandas.core.series.Series, overwrite: bool = False) numpy.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) numpy.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: Union[torch.Tensor, numpy.ndarray]) numpy.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: pandas.core.series.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) Union[torch.Tensor, numpy.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]