Skip to content

Conversation

@Guilly-Kolkman
Copy link
Collaborator

@Guilly-Kolkman Guilly-Kolkman commented Nov 17, 2025

Implemented Kalman filter as both a pre and post processing option with tests.

  • Basekalman
  • KalmanPreprocessor
  • KalmanPostprocessor

The implementation follows the sktime implementation of KalmanFilterTransformerFP build on filterpy. The kalman filter reduces noise and improves results. However, the method is computationally more expensive.

For the preprocessor you can add it in the preprocessing list in workflows of models with, for example:
preprocessing = [ *checks, *feature_adders, HolidayFeatureAdder(country_code=config.location.country_code), DatetimeFeaturesAdder(onehot_encode=False), KalmanPreprocessor( selection=config.kalman_features, ), *feature_standardizers, ],
The kalman_features are currently based only on weather features.

For postprocessing a flag is added which can be set to True or False depending on the user's need.

*feature_adders,
HolidayFeatureAdder(country_code=config.location.country_code),
DatetimeFeaturesAdder(onehot_encode=False),
KalmanPreprocessor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to only add it to xgboost? Did it not perform well in gblinear?

Also whether we want to add it to the preset, depends on the results also. I would probably leave it out (for now).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added this for convenience, we will take it out. Good you noticed, thank you.


# Preprocessor: operates on TimeSeriesDataset
class KalmanPreprocessor(BaseKalman, TimeSeriesTransform):
"""Apply Kalman Smoothing to time series data to reduce noise and improve temporal consistency.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific source you used for the implementation? If so, I think it is nice to add it to the docs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation was done to mimic other transforms. No additional sources were used


import pandas as pd
from pydantic import Field
from sktime.transformations.series.kalman_filter import (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this as a dependency? I don't think we have it already.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as dependency of openstef models

transform = KalmanPreprocessor()
result = transform.fit_transform(dataset)

expected_values = pd.DataFrame(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice to add a tests for the multiple column case where all columns are transformed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants