QuantileSorter#
- class openstef_models.transforms.postprocessing.quantile_sorter.QuantileSorter[source]
Bases:
Transform[ForecastDataset,ForecastDataset]Sort quantile forecasts to enforce monotonic ordering.
Probabilistic forecasts should have higher quantiles predict higher values (e.g., the 90th percentile should be greater than the 10th percentile). When quantiles are predicted independently, this property can be violated. This transform corrects violations by sorting quantile predictions for each time step.
The transform is stateless and requires no fitting.
Example
Basic usage with a forecast dataset
>>> import pandas as pd >>> from datetime import timedelta >>> from openstef_core.datasets import ForecastDataset >>> # Create sample data with unsorted quantiles >>> data = pd.DataFrame({ ... 'quantile_P10': [1.0, 2.0, 3.0], ... 'quantile_P50': [0.5, 1.5, 2.5], # Violates ordering ... 'quantile_P90': [2.0, 3.0, 4.0] ... }, index=pd.date_range('2025-01-01', periods=3, freq='h')) >>> dataset = ForecastDataset( ... data=data, ... sample_interval=timedelta(hours=1) ... ) >>> sorter = QuantileSorter() >>> sorted_dataset = sorter.transform(data=dataset) >>> # Now quantile_P10 <= quantile_P50 <= quantile_P90 for each time step >>> sorted_dataset.data.iloc[0].values.tolist() [0.5, 1.0, 2.0]
- property is_fitted: bool
Check if the transform has been fitted.
- fit(data: ForecastDataset) 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:
data (
ForecastDataset) – The input data to fit the transform on.data
- Return type:
- transform(data: ForecastDataset) ForecastDataset[source]
Transform the input data.
This method should apply a transformation to the input data and return a new instance.
- Parameters:
data (
ForecastDataset) – The input data to be transformed.data
- Returns:
A new instance of the transformed data.
- Raises:
NotFittedError – If the transform has not been fitted yet.
- Return type: