openstef 3.4.27__py3-none-any.whl → 3.4.28__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.
@@ -27,6 +27,7 @@ class PredictionJobDataClass(BaseModel):
27
27
  - ``"linear"``
28
28
  - ``"linear_quantile"``
29
29
  - ``"xgb_multioutput_quantile"``
30
+ - ``"flatliner"``
30
31
 
31
32
  If unsure what to pick, choose ``"xgb"``.
32
33
 
openstef/enums.py CHANGED
@@ -13,6 +13,7 @@ class MLModelType(Enum):
13
13
  LINEAR = "linear"
14
14
  LINEAR_QUANTILE = "linear_quantile"
15
15
  ARIMA = "arima"
16
+ FLATLINER = "flatliner"
16
17
 
17
18
 
18
19
  class ForecastType(Enum):
@@ -73,8 +73,11 @@ class ConfidenceIntervalApplicator:
73
73
  result = self._add_quantiles_to_forecast_quantile_regression(
74
74
  temp_forecast, self.model.quantiles
75
75
  )
76
- self.logger.warning('Quantiles are requested the model was not trained on. Using the quantiles the model was trained on',
77
- requested_quantiles=pj["quantiles"], trained_quantiles=self.model.quantiles)
76
+ self.logger.warning(
77
+ "Quantiles are requested the model was not trained on. Using the quantiles the model was trained on",
78
+ requested_quantiles=pj["quantiles"],
79
+ trained_quantiles=self.model.quantiles,
80
+ )
78
81
  return result
79
82
 
80
83
  return self._add_quantiles_to_forecast_default(temp_forecast, pj["quantiles"])
@@ -13,6 +13,7 @@ from openstef.model.regressors.lgbm import LGBMOpenstfRegressor
13
13
  from openstef.model.regressors.linear import LinearOpenstfRegressor
14
14
  from openstef.model.regressors.linear_quantile import LinearQuantileOpenstfRegressor
15
15
  from openstef.model.regressors.regressor import OpenstfRegressor
16
+ from openstef.model.regressors.flatliner import FlatlinerRegressor
16
17
  from openstef.model.regressors.xgb import XGBOpenstfRegressor
17
18
  from openstef.model.regressors.xgb_quantile import XGBQuantileOpenstfRegressor
18
19
  from openstef.model.regressors.xgb_multioutput_quantile import (
@@ -105,6 +106,9 @@ valid_model_kwargs = {
105
106
  "imputation_strategy",
106
107
  "fill_value",
107
108
  ],
109
+ MLModelType.FLATLINER: [
110
+ "quantiles",
111
+ ],
108
112
  MLModelType.LINEAR_QUANTILE: [
109
113
  "alpha",
110
114
  "quantiles",
@@ -134,6 +138,7 @@ class ModelCreator:
134
138
  MLModelType.LINEAR: LinearOpenstfRegressor,
135
139
  MLModelType.LINEAR_QUANTILE: LinearQuantileOpenstfRegressor,
136
140
  MLModelType.ARIMA: ARIMAOpenstfRegressor,
141
+ MLModelType.FLATLINER: FlatlinerRegressor,
137
142
  }
138
143
 
139
144
  @staticmethod
@@ -52,6 +52,7 @@ class Dazls(BaseEstimator):
52
52
  Args:
53
53
  features: inputs for domain and adaptation model (domain_model_input, adaptation_model_input)
54
54
  target: the expected output (y_train)
55
+
55
56
  """
56
57
  x, y = (
57
58
  features.loc[:, self.baseline_input_columns],
@@ -76,6 +77,7 @@ class Dazls(BaseEstimator):
76
77
 
77
78
  Returns:
78
79
  prediction: The output prediction after both models.
80
+
79
81
  """
80
82
  model_test_data = x.loc[:, self.baseline_input_columns]
81
83
 
@@ -90,6 +92,7 @@ class Dazls(BaseEstimator):
90
92
 
91
93
  Returns:
92
94
  RMSE and R2 scores
95
+
93
96
  """
94
97
  rmse = (mean_squared_error(truth, prediction)) ** 0.5
95
98
  r2_score_value = r2_score(truth, prediction)
@@ -100,6 +103,7 @@ class Dazls(BaseEstimator):
100
103
 
101
104
  Returns:
102
105
  Summary represented by a string
106
+
103
107
  """
104
108
  summary_str = (
105
109
  f"{self.__name__} model summary:\n\n"
@@ -0,0 +1,100 @@
1
+ # SPDX-FileCopyrightText: 2017-2023 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501>
2
+ #
3
+ # SPDX-License-Identifier: MPL-2.0
4
+ import re
5
+ from typing import Dict, Union, Set, Optional, List
6
+
7
+ import numpy as np
8
+ import pandas as pd
9
+ from sklearn.base import RegressorMixin
10
+ from sklearn.linear_model import QuantileRegressor
11
+ from sklearn.preprocessing import MinMaxScaler
12
+ from sklearn.utils.validation import check_is_fitted
13
+
14
+ from openstef.feature_engineering.missing_values_transformer import (
15
+ MissingValuesTransformer,
16
+ )
17
+ from openstef.model.regressors.regressor import OpenstfRegressor
18
+
19
+
20
+ class FlatlinerRegressor(OpenstfRegressor, RegressorMixin):
21
+ feature_names_: List[str] = []
22
+
23
+ def __init__(self, quantiles=None):
24
+ """Initialize FlatlinerRegressor.
25
+
26
+ The model always predicts 0.0, regardless of the input features. The model is
27
+ meant to be used for flatliner locations that still expect a prediction while
28
+ preserving the prediction interface.
29
+ """
30
+ super().__init__()
31
+ self.quantiles = quantiles
32
+
33
+ @property
34
+ def feature_names(self) -> list:
35
+ """The names of the features used to train the model."""
36
+ check_is_fitted(self)
37
+ return self.feature_names_
38
+
39
+ @staticmethod
40
+ def _get_importance_names():
41
+ return {
42
+ "gain_importance_name": "total_gain",
43
+ "weight_importance_name": "weight",
44
+ }
45
+
46
+ @property
47
+ def can_predict_quantiles(self) -> bool:
48
+ """Attribute that indicates if the model predict particular quantiles."""
49
+ return True
50
+
51
+ def fit(self, x: pd.DataFrame, y: pd.Series, **kwargs) -> RegressorMixin:
52
+ """Fits flatliner model.
53
+
54
+ Args:
55
+ x: Feature matrix
56
+ y: Labels
57
+
58
+ Returns:
59
+ Fitted LinearQuantile model
60
+
61
+ """
62
+ self.feature_names_ = list(x.columns)
63
+ self.feature_importances_ = np.ones(len(self.feature_names_)) / (
64
+ len(self.feature_names_) or 1.0
65
+ )
66
+
67
+ return self
68
+
69
+ def predict(self, x: pd.DataFrame, quantile: float = 0.5, **kwargs) -> np.array:
70
+ """Makes a prediction for a desired quantile.
71
+
72
+ Args:
73
+ x: Feature matrix
74
+ quantile: Quantile for which a prediciton is desired,
75
+ note that only quantile are available for which a model is trained,
76
+ and that this is a quantile-model specific keyword
77
+
78
+ Returns:
79
+ Prediction
80
+
81
+ Raises:
82
+ ValueError in case no model is trained for the requested quantile
83
+
84
+ """
85
+ check_is_fitted(self)
86
+
87
+ return np.zeros(x.shape[0])
88
+
89
+ def _get_feature_importance_from_linear(self, quantile: float = 0.5) -> np.array:
90
+ check_is_fitted(self)
91
+ return np.array([0.0 for _ in self.feature_names_])
92
+
93
+ @classmethod
94
+ def _get_param_names(cls):
95
+ return [
96
+ "quantiles",
97
+ ]
98
+
99
+ def __sklearn_is_fitted__(self) -> bool:
100
+ return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openstef
3
- Version: 3.4.27
3
+ Version: 3.4.28
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=EJTDtimctFQQ-3f7ZcOQaRYohpZk3JD6aZBWPFYM2_A,582
4
- openstef/enums.py,sha256=i2EujJ6giJpzcxQYyVtr07D6DFnAmJpS7KEByZ2chMw,727
4
+ openstef/enums.py,sha256=TTchQ0iZ3PXBjMVmVid_x7W-zU1jNiHa-4wDMGyNWic,755
5
5
  openstef/exceptions.py,sha256=U4u2LTcdT6cmzpipT2Jh7kq9nCjT_-6gntn8yjuhGU0,1993
6
6
  openstef/settings.py,sha256=nSgkBqFxuqB3w7Rwo60i8j37c5ngDbt6vpjHS6QtJXQ,354
7
7
  openstef/data/dutch_holidays_2020-2022.csv,sha256=pS-CjE0igYXd-2dG-MlqyvR2fgYgXkbNmgCKyTjmwxs,23704
@@ -11,7 +11,7 @@ openstef/data/pv_single_coefs.csv.license,sha256=AxxHusqwIXU5RHl5ZMU65LyXmgtbj6Q
11
11
  openstef/data_classes/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
12
12
  openstef/data_classes/data_prep.py,sha256=gRSL7UiHvZis8m8z7VoTCZc0Ccffhef5_hmSyApnqK0,3417
13
13
  openstef/data_classes/model_specifications.py,sha256=Uod1W3QzhRqVLb6zvXwxh9wRL3EHCzSvX0oDNd28cFk,1197
14
- openstef/data_classes/prediction_job.py,sha256=hjJmOBzVNEb3w3Iqh6e1nSoHmToentMwnEghnvHodpI,5206
14
+ openstef/data_classes/prediction_job.py,sha256=tE3K8QCDasXh0ESOBvMgJ3yI_noS6Uz7jU0sSDdt_us,5232
15
15
  openstef/data_classes/split_function.py,sha256=ljQIQQu1t1Y_CVWGAy25jrM6wG9odIVVQVimrT1n-1s,3358
16
16
  openstef/feature_engineering/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
17
17
  openstef/feature_engineering/apply_features.py,sha256=-3fyisOVj9ckIkRe2iYfWutbXSX8iqBkcvt8AYr-gmE,3906
@@ -29,9 +29,9 @@ openstef/metrics/metrics.py,sha256=si93EP2i34v3IPg-nOcm_aheoFAdu46i3azV_PjPmF8,1
29
29
  openstef/metrics/reporter.py,sha256=w1Q6xWoYGmvnjwjXik-Gz7_gnb0lOeJMep-whEV5mNk,7897
30
30
  openstef/model/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
31
31
  openstef/model/basecase.py,sha256=caI6Q-8y0ymlxGK9Js_H3Vh0q6ruNHlGD5RG0_kE5M0,2878
32
- openstef/model/confidence_interval_applicator.py,sha256=jd6W5jLw3U7leTxWsf3RFGAfOjWd33jOYvldZUF-Wlo,9728
32
+ openstef/model/confidence_interval_applicator.py,sha256=Bx0mm4zGKlqopMZ589cVyDN_k6jfuyqtV1FoViXxc2Y,9775
33
33
  openstef/model/fallback.py,sha256=VV9ehgnoMZtWzqKk9H1t8wnERFh5CyC4TvDIuRP_ZDI,2861
34
- openstef/model/model_creator.py,sha256=rQI7aEUcNI58x43vHmIRCIhymCis56SfLo3bhPBn410,5755
34
+ openstef/model/model_creator.py,sha256=v-_NHNG1MEQizg9ZKEkDxCdRKjqwg4Knpm-Yvd__1nE,5930
35
35
  openstef/model/objective.py,sha256=2wPoONbk11WbySyPyqFMmXBx2lDFeUq_7jFPaCNETao,14572
36
36
  openstef/model/objective_creator.py,sha256=_qIjq0ckrVIFr7k0L0NN0WyF0LIDaEYWA9NtVLzGs9g,2167
37
37
  openstef/model/serializer.py,sha256=IUiiAWvoGVoWzmS-akI6LC7jHRY5Ln_vOCBZy1LnESY,17238
@@ -42,7 +42,8 @@ openstef/model/metamodels/missing_values_handler.py,sha256=veyvYZHhKvlYZxaUpxRQ7
42
42
  openstef/model/regressors/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
43
43
  openstef/model/regressors/arima.py,sha256=wt7FVykjSvljpl7vjtliq61SiyjQ7KKtw8PF9x0xf04,7587
44
44
  openstef/model/regressors/custom_regressor.py,sha256=Hsmxahc9nfSWD0aEZ6cm4pxW2noQ8B1SujS17_fmxcU,1768
45
- openstef/model/regressors/dazls.py,sha256=dQMx11kfMZCl4K61n8Dug2CyBhjlmiw3-ilv7KmowqM,3990
45
+ openstef/model/regressors/dazls.py,sha256=Xt89yFHjkwpIUTkkhPmPZ74F8_tht_XV88INuP5GU2E,3994
46
+ openstef/model/regressors/flatliner.py,sha256=98JUwRGtOYT9ZR9njY7FBCLNYTtAe7ZTcBF1cbSZyZg,3024
46
47
  openstef/model/regressors/lgbm.py,sha256=zCdn1euEdSFxYJzH8XqQFFnb6R4JVUnmineKjX_Gy-g,800
47
48
  openstef/model/regressors/linear.py,sha256=uOvZMLGZH_9nXfmS5honCMfyVeyGXP1Cza9A_BdXlVw,3665
48
49
  openstef/model/regressors/linear_quantile.py,sha256=N-cia8aba39Th6BzOdtcESLuxhY9YtSGaOYIc6STgag,7830
@@ -83,8 +84,8 @@ openstef/tasks/utils/predictionjobloop.py,sha256=Ysy3zF5lzPMz_asYDKeF5m0qgVT3tCt
83
84
  openstef/tasks/utils/taskcontext.py,sha256=L9K14ycwgVxbIVUjH2DIn_QWbnu-OfxcGtQ1K9T6sus,5630
84
85
  openstef/validation/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
85
86
  openstef/validation/validation.py,sha256=628xaDbAm8B4AYtFOAn8_SXLjejNfULGCfX3hVf_mU0,11119
86
- openstef-3.4.27.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
87
- openstef-3.4.27.dist-info/METADATA,sha256=ihPPQxI45vuOqRWcg71UtkfH_hHKgeBSctu6sJXnoMo,7394
88
- openstef-3.4.27.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
89
- openstef-3.4.27.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
90
- openstef-3.4.27.dist-info/RECORD,,
87
+ openstef-3.4.28.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
88
+ openstef-3.4.28.dist-info/METADATA,sha256=AbRqjrWvhbDWiJhtgJ7r0_43YfrKK5v5sQYQ8FE9PPY,7394
89
+ openstef-3.4.28.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
90
+ openstef-3.4.28.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
91
+ openstef-3.4.28.dist-info/RECORD,,