Selector#

class openstef_models.transforms.general.Selector(**data: Any) None[source]

Bases: BaseConfig, TimeSeriesTransform

Selects features based on FeatureSelection.

Example

>>> import pandas as pd
>>> from datetime import timedelta
>>> from openstef_core.datasets import TimeSeriesDataset
>>> from openstef_models.transforms.general import Selector
>>> from openstef_models.utils.feature_selection import FeatureSelection
>>>
>>> # Create sample dataset
>>> data = pd.DataFrame(
...     {
...         "load": [100.0, 110.0, 120.0],
...         "temperature": [20.0, 22.0, 23.0],
...         "humidity": [60.0, 65.0, 70.0],
...     },
...     index=pd.date_range("2025-01-01", periods=3, freq="1h"),
... )
>>> dataset = TimeSeriesDataset(data, timedelta(hours=1))
>>>
>>> # Select specific features
>>> selector = Selector(selection=FeatureSelection(include={'load', 'temperature'}))
>>> transformed = selector.transform(dataset)
>>> transformed.feature_names
['load', 'temperature']
Parameters:

data (Any)

selection: FeatureSelection
property is_fitted: bool

Check if the transform has been fitted.

fit(data: TimeSeriesDataset) None[source]

Fit the transform to the input data.

This method should be called before applying the transform to the data. It allows the transform to learn any necessary parameters from the data.

Parameters:
Return type:

None

transform(data: TimeSeriesDataset) TimeSeriesDataset[source]

Transform the input data.

This method should apply a transformation to the input data and return a new instance.

Parameters:
Returns:

A new instance of the transformed data.

Raises:

NotFittedError – If the transform has not been fitted yet.

Return type:

TimeSeriesDataset

features_added() list[str][source]

List of feature names added by this transform.

Return type:

list[str]

Returns:

A list of strings representing the names of features added to the dataset by this transform. Default is an empty list.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

  • self

  • context

Return type:

None