tempor.methods.preprocessing.encoding.static.plugin_static_onehot_encoder module

One-hot encoding for static data.

class tempor.methods.preprocessing.encoding.static.plugin_static_onehot_encoder.StaticOneHotEncoderParams(features: ~typing.List[str] | None = None, categories: typing_extensions.Literal[auto] | ~typing.List = 'auto', drop: None | typing_extensions.Literal[first, if_binary] | ~typing.List = None, dtype: ~typing.Type = <class 'float'>, handle_unknown: typing_extensions.Literal[error, ignore, infrequent_if_exist] = 'error', min_frequency: int | float | None = None, max_categories: int | None = None, feature_name_combiner: typing_extensions.Literal[concat] | ~typing.Callable = 'concat')[source]

Bases: object

Initialization parameters for StaticOneHotEncoder.

See sklearn.preprocessing.OneHotEncoder.

Note

sparse_output is always set to False.

features : list[str] | None = None

Features to encode. If None, all features will be encoded.

categories : Literal[auto] | list = 'auto'

See categories in sklearn.preprocessing.OneHotEncoder

drop : None | Literal[first] | Literal[if_binary] | list = None

See drop in sklearn.preprocessing.OneHotEncoder

dtype

See dtype in sklearn.preprocessing.OneHotEncoder

alias of float

handle_unknown : Literal[error] | Literal[ignore] | Literal[infrequent_if_exist] = 'error'

See handle_unknown in sklearn.preprocessing.OneHotEncoder

min_frequency : int | float | None = None

See min_frequency in sklearn.preprocessing.OneHotEncoder

max_categories : int | None = None

See max_categories in sklearn.preprocessing.OneHotEncoder

feature_name_combiner : Literal[concat] | Callable = 'concat'

See feature_name_combiner in sklearn.preprocessing.OneHotEncoder

class tempor.methods.preprocessing.encoding.static.plugin_static_onehot_encoder.StaticOneHotEncoder(**params: Any)[source]

Bases: BaseEncoder

One-hot encoding for the static data.

See sklearn.preprocessing.OneHotEncoder for details.

Specify features list to encode only a subset of the features.

Parameters:
**params : Any

Parameters and defaults as defined in StaticOneHotEncoderParams.

Example

>>> from tempor import plugin_loader
>>>
>>> dataset = plugin_loader.get("prediction.temporal.dummy_prediction", plugin_type="datasource").load()
>>>
>>> # Get static data with some categorical features.
>>> import numpy as np
>>> import pandas as pd
>>> np.random.seed(777)
>>> from tempor.data.samples import StaticSamples
>>> static_df = dataset.static.dataframe()
>>> static_df["categorical_feat_1"] = pd.Categorical(
...     np.random.choice(["a", "b", "c"], size=(len(static_df),))
... )
>>> static_df["categorical_feat_2"] = pd.Categorical(np.random.choice(["D", "E"], size=(len(static_df),)))
>>> dataset.static = StaticSamples.from_dataframe(static_df)
>>>
>>> # Load the encoder:
>>> enc = plugin_loader.get(
...     "preprocessing.encoding.static.static_onehot_encoder",
...     features=["categorical_feat_1", "categorical_feat_2"],
... )
>>>
>>> # Fit:
>>> enc.fit(dataset)
StaticOneHotEncoder(...)
>>>
>>> # Encode:
>>> encoded = enc.transform(dataset)
ParamsDefinition

alias of StaticOneHotEncoderParams

category : ClassVar[plugin_typing.PluginCategory] = 'preprocessing.encoding.static'

Plugin category, such as 'prediction.one_off.classification'. Must be set by the plugin class using @register_plugin.

name : ClassVar[plugin_typing.PluginName] = 'static_onehot_encoder'

Plugin name, such as 'my_nn_classifier'. Must be set by the plugin class using @register_plugin.

plugin_type : ClassVar[plugin_typing.PluginTypeArg] = 'method'

Plugin type, such as 'method'. May be optionally set by the plugin class using @register_plugin, else will set the default plugin type.

params : StaticOneHotEncoderParams
static hyperparameter_space(*args: Any, **kwargs: Any) list[Params][source]

The hyperparameter search domain, used for tuning.

Can provide variadics *args and **kwargs, these will be received from sample_hyperparameters.