openstef 3.4.72__py3-none-any.whl → 3.4.73__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ class PredictionJobDataClass(BaseModel):
21
21
  )
22
22
  model: str = Field(
23
23
  ...,
24
- description="The model type that should be used. Options are: 'xgb', 'xgb_quantile', 'lgb', 'linear', 'linear_quantile', 'gblinear_quantile', 'xgb_multioutput_quantile', 'flatliner'.",
24
+ description="The model type that should be used. Options are: 'xgb', 'xgb_quantile', 'lgb', 'linear', 'linear_quantile', 'gblinear_quantile', 'xgb_multioutput_quantile', 'flatliner', 'median'.",
25
25
  )
26
26
 
27
27
  model_kwargs: Optional[dict] = Field(
openstef/enums.py CHANGED
@@ -125,6 +125,7 @@ class ModelType(Enum):
125
125
  GBLINEAR_QUANTILE = "gblinear_quantile"
126
126
  ARIMA = "arima"
127
127
  FLATLINER = "flatliner"
128
+ MEDIAN = "median"
128
129
 
129
130
 
130
131
  class ForecastType(Enum):
@@ -17,6 +17,7 @@ from openstef.model.regressors.xgb import XGBOpenstfRegressor
17
17
  from openstef.model.regressors.xgb_multioutput_quantile import (
18
18
  XGBMultiOutputQuantileOpenstfRegressor,
19
19
  )
20
+ from openstef.model.regressors.median import MedianRegressor
20
21
  from openstef.model.regressors.xgb_quantile import XGBQuantileOpenstfRegressor
21
22
 
22
23
  logger = get_logger(__name__)
@@ -138,6 +139,9 @@ valid_model_kwargs = {
138
139
  "seasonal_order",
139
140
  "trend",
140
141
  ],
142
+ ModelType.MEDIAN: [
143
+ # This model does not have any parameters
144
+ ],
141
145
  }
142
146
 
143
147
 
@@ -155,6 +159,7 @@ class ModelCreator:
155
159
  ModelType.GBLINEAR_QUANTILE: GBLinearQuantileOpenstfRegressor,
156
160
  ModelType.ARIMA: ARIMAOpenstfRegressor,
157
161
  ModelType.FLATLINER: FlatlinerRegressor,
162
+ ModelType.MEDIAN: MedianRegressor,
158
163
  }
159
164
 
160
165
  @staticmethod
@@ -0,0 +1,78 @@
1
+ """This module contains the median regressor."""
2
+
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ from sklearn.base import RegressorMixin
7
+ from sklearn.utils.validation import check_is_fitted
8
+
9
+ from openstef.model.regressors.regressor import OpenstfRegressor
10
+
11
+
12
+ class MedianRegressor(OpenstfRegressor, RegressorMixin):
13
+ """
14
+ Median regressor implementing the OpenSTEF regressor API.
15
+
16
+ This regressor is good for predicting two types of signals:
17
+ - Signals with very slow dynamics compared to the sampling rate, possibly
18
+ with a lot of noise.
19
+ - Signals that switch between two or more states, which random in nature or
20
+ depend on unknown features, but tend to be stable in each state. An example of
21
+ this may be waste heat delivered from an industrial process. Using a median
22
+ over the last few timesteps adds some hysterisis to avoid triggering on noise.
23
+ """
24
+
25
+ def __init__(self):
26
+ """Initialize MedianRegressor."""
27
+ super().__init__()
28
+
29
+ @property
30
+ def feature_names(self) -> list:
31
+ """Retrieve the model input feature names.
32
+
33
+ Returns:
34
+ The list of feature names
35
+
36
+ """
37
+ check_is_fitted(self, "feature_names_")
38
+ return self.feature_names_
39
+
40
+ @property
41
+ def can_predict_quantiles(self) -> bool:
42
+ return False
43
+
44
+ def predict(self, x: pd.DataFrame, **kwargs) -> np.array:
45
+ """
46
+ Predict the median of the lag features for each time step in the context window.
47
+
48
+ Args:
49
+ x (pd.DataFrame): The input data for prediction. This should be a pandas dataframe with lag features.
50
+
51
+ Returns:
52
+ np.array: The predicted median for each time step in the context window.
53
+ If any lag feature is NaN, this will be ignored.
54
+ If all lag features are NaN, the regressor will return NaN.
55
+ """
56
+
57
+ lag_df = x.loc[:, self.feature_names]
58
+ median = lag_df.median(axis=1, skipna=True)
59
+
60
+ return median
61
+
62
+ def fit(self, x: pd.DataFrame, y: pd.DataFrame, **kwargs) -> RegressorMixin:
63
+ """This model does not have any hyperparameters to fit,
64
+ but it does need to know the feature names of the lag features.
65
+
66
+ Which lag features are used is determined by the feature engineering step.
67
+ """
68
+ self.feature_names_ = list(x.columns[x.columns.str.startswith("T-")])
69
+ if len(self.feature_names_) == 0:
70
+ raise ValueError("No lag features found in the input data.")
71
+
72
+ self.feature_importances_ = np.ones(len(self.feature_names_)) / (
73
+ len(self.feature_names_) or 1.0
74
+ )
75
+ return self
76
+
77
+ def __sklearn_is_fitted__(self) -> bool:
78
+ return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openstef
3
- Version: 3.4.72
3
+ Version: 3.4.73
4
4
  Summary: Open short term energy forecaster
5
5
  Home-page: https://github.com/OpenSTEF/openstef
6
6
  Author: Alliander N.V
@@ -1,7 +1,7 @@
1
1
  openstef/__init__.py,sha256=93UM6m0LLQhO69-mSqLuUy73jgs4W7Iuxfo3Lm8c98g,419
2
2
  openstef/__main__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
3
3
  openstef/app_settings.py,sha256=4SiEoPfPmM_Vc9gwWleT_IRxHIk36bZaYRCdNf3ewoo,762
4
- openstef/enums.py,sha256=FrP0m_Tk0kV7gSZ2hTY_8iD45KIKnexHrjNufhpKXpE,2829
4
+ openstef/enums.py,sha256=kwAbEoMI_a--Ikk6RxeJmvR2JKYKDNHynhMUbbiczZs,2851
5
5
  openstef/exceptions.py,sha256=dgnvZe5WWuJWCZm_GES6suEATbusPlwbiEUfNQKeExY,1993
6
6
  openstef/settings.py,sha256=nSgkBqFxuqB3w7Rwo60i8j37c5ngDbt6vpjHS6QtJXQ,354
7
7
  openstef/data/NL_terrestrial_radiation.csv,sha256=A4kbW56GDzWi4tWUwY2C-4PiOvcKJCwkWQQtdg4ekPE,820246
@@ -17,7 +17,7 @@ openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_model_card.md.license,sha25
17
17
  openstef/data_classes/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
18
18
  openstef/data_classes/data_prep.py,sha256=sANgFjfwmSWhLCfmLjfqXQnczuvVZfk2765jZd7LwuE,3691
19
19
  openstef/data_classes/model_specifications.py,sha256=PZeBLfH_MrP9-QorL1r0Hklp0befE8Nw05vNhTX9Y20,1338
20
- openstef/data_classes/prediction_job.py,sha256=e6_PFAovNd31tjzoTQJvqRNQyVM-M0XHffclAG9Ez8A,6721
20
+ openstef/data_classes/prediction_job.py,sha256=omVzowGYUp5YD_7k3i3pKlDh1I7i_jU3-za7FJ3fK1s,6731
21
21
  openstef/data_classes/split_function.py,sha256=K8y1dsQC5exeIDh37f7UwJ11tV71_uVSNbnKmwXpnOM,3435
22
22
  openstef/feature_engineering/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
23
23
  openstef/feature_engineering/apply_features.py,sha256=pro4eUmOFexX_9g9kJtDcbrQ1hWKzXjVpiJBmmBi89o,5326
@@ -46,7 +46,7 @@ openstef/model/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,16
46
46
  openstef/model/basecase.py,sha256=caI6Q-8y0ymlxGK9Js_H3Vh0q6ruNHlGD5RG0_kE5M0,2878
47
47
  openstef/model/confidence_interval_applicator.py,sha256=VOdHsDJhfeyaq_cnk9QMUaZ2IumbiBBoW1zo8AuqDg0,9559
48
48
  openstef/model/fallback.py,sha256=g6TEuEhV4w07SCGkR_AvPf2up9f0ixGKQojYC-Ewl6Y,2812
49
- openstef/model/model_creator.py,sha256=XiWqTrVwCqGcqc9PUKprMOHu7T9Lz2qngi4bD8LkWas,6473
49
+ openstef/model/model_creator.py,sha256=fnhcVGUHskbuAys5kjlJ4GXKxbi9Eq5eAA19ex11Vv0,6658
50
50
  openstef/model/objective.py,sha256=0PZUbPzuyaYlpWEH_qPavO6ll7zwqTTUTfIrUzzFMbs,15585
51
51
  openstef/model/objective_creator.py,sha256=3jJgcmY1sm-Yoe3SfjKrJukrsqtYyloUFaPbBWqswhQ,2208
52
52
  openstef/model/serializer.py,sha256=k5GY8eRJdlii8mEY7Qheu4yb5USyIyxw77EYkSQJGYk,17034
@@ -64,6 +64,7 @@ openstef/model/regressors/gblinear_quantile.py,sha256=PKQL_TAXa3Kw9oZrKC6Uvo_n2N
64
64
  openstef/model/regressors/lgbm.py,sha256=zCdn1euEdSFxYJzH8XqQFFnb6R4JVUnmineKjX_Gy-g,800
65
65
  openstef/model/regressors/linear.py,sha256=uOvZMLGZH_9nXfmS5honCMfyVeyGXP1Cza9A_BdXlVw,3665
66
66
  openstef/model/regressors/linear_quantile.py,sha256=zIpGo9deMeTZdwFWoZ3FstX74mYdlAhfg-YOsPRFl0k,10534
67
+ openstef/model/regressors/median.py,sha256=ITM5QhqfvjMjfk8fuHbyVWyWgld1NTiWajaaWAugbis,2697
67
68
  openstef/model/regressors/regressor.py,sha256=0um575rTEkzYb1E5IAOuTlsZDhmb7eI5byu5e062NRs,3469
68
69
  openstef/model/regressors/xgb.py,sha256=uhV9Wm90aOkjByTm-O2xpt2kpANRxAqQvv5mA0H1uBc,1294
69
70
  openstef/model/regressors/xgb_multioutput_quantile.py,sha256=xWzA7tymC_o-F1OS3I7vUKf9zP6RR1ZglEeY4NAgjU0,9146
@@ -103,8 +104,8 @@ openstef/tasks/utils/predictionjobloop.py,sha256=Ysy3zF5lzPMz_asYDKeF5m0qgVT3tCt
103
104
  openstef/tasks/utils/taskcontext.py,sha256=O-LZ_wHEl5vbT8oB7EYtOeMkvk6EqCnI1-KiyER7Eu4,5407
104
105
  openstef/validation/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
105
106
  openstef/validation/validation.py,sha256=r6UqkdH5TMjsGfn8Ta07K1jkqmrVmwcPGfyQvMmZyO4,11459
106
- openstef-3.4.72.dist-info/licenses/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
107
- openstef-3.4.72.dist-info/METADATA,sha256=79Nx_OmSE_1sLNUR1OIvNarsDaieOjrbjEU1dnRfo28,8834
108
- openstef-3.4.72.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
109
- openstef-3.4.72.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
110
- openstef-3.4.72.dist-info/RECORD,,
107
+ openstef-3.4.73.dist-info/licenses/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
108
+ openstef-3.4.73.dist-info/METADATA,sha256=7Nxg4a2GePqCFf19ANnEIze222JfNmypS88wt05cdfg,8834
109
+ openstef-3.4.73.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
110
+ openstef-3.4.73.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
111
+ openstef-3.4.73.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5