Flagger#

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

Bases: BaseConfig, TimeSeriesTransform

Transform that flags specified features to their observed min and max values.

This transform flags the peaks for the metalearner to know when to expect outliers and extrapolate from its training set.

Example

>>> import pandas as pd
>>> from datetime import timedelta
>>> from openstef_core.datasets import TimeSeriesDataset
>>> from openstef_models.transforms.general import Flagger
>>> from openstef_models.utils.feature_selection import FeatureSelection
>>> # Create sample training dataset
>>> training_data = pd.DataFrame({
...     'load': [100, 90, 110],
...     'temperature': [19, 20, 21]
... }, index=pd.date_range('2025-01-01', periods=3, freq='1h'))
>>> training_dataset = TimeSeriesDataset(training_data, timedelta(hours=1))
>>> test_data = pd.DataFrame({
...     'load': [90, 140, 100],
...     'temperature': [18, 20, 22]
... }, index=pd.date_range('2025-01-06', periods=3,
... freq='1h'))
>>> test_dataset = TimeSeriesDataset(test_data, timedelta(hours=1))
>>> # Initialize and apply transform
>>> flagger = Flagger(selection=FeatureSelection(include=['load', 'temperature']))
>>> flagger.fit(training_dataset)
>>> transformed_dataset = flagger.transform(test_dataset)
>>> transformed_dataset.data['load'].tolist()
[0, 0, 1]
>>> transformed_dataset.data['temperature'].tolist()
[0, 1, 0]
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