openenergyid 0.1.8__tar.gz → 0.1.9__tar.gz
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.
Potentially problematic release.
This version of openenergyid might be problematic. Click here for more details.
- {openenergyid-0.1.8 → openenergyid-0.1.9}/PKG-INFO +1 -1
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/__init__.py +1 -1
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/mvlr/main.py +1 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/mvlr/models.py +16 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/mvlr/mvlr.py +27 -14
- {openenergyid-0.1.8 → openenergyid-0.1.9}/.devcontainer/devcontainer.json +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/.github/workflows/python-publish.yml +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/.github/workflows/ruff.yml +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/.gitignore +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/.pre-commit-config.yaml +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/LICENSE +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/README.md +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/data/da_prices_be.json +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/data/mvlr/sample_gas.json +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/data/mvlr/sample_solar.json +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/demo_energyid_download.ipynb +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/demo_mvlr.ipynb +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/download_prices.ipynb +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/const.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/enums.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/models.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/mvlr/__init__.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/openenergyid/mvlr/helpers.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/pyproject.toml +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/requirements-dev.txt +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/requirements.txt +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/tests/__init__.py +0 -0
- {openenergyid-0.1.8 → openenergyid-0.1.9}/tests/data/mvlr/sample.dat +0 -0
|
@@ -18,6 +18,7 @@ def find_best_mvlr(
|
|
|
18
18
|
granularity=granularity,
|
|
19
19
|
allow_negative_predictions=data.allow_negative_predictions,
|
|
20
20
|
single_use_exog_prefixes=data.single_use_exog_prefixes,
|
|
21
|
+
exogs__disallow_negative_coefficient=data.get_disallowed_negative_coefficients(),
|
|
21
22
|
)
|
|
22
23
|
mvlr.do_analysis()
|
|
23
24
|
if mvlr.validate(
|
|
@@ -51,6 +51,11 @@ class IndependentVariableInput(BaseModel):
|
|
|
51
51
|
"Eg. `HDD_16.5` will be Heating Degree Days with a base temperature of 16.5°C, "
|
|
52
52
|
"`CDD_0` will be Cooling Degree Days with a base temperature of 0°C.",
|
|
53
53
|
)
|
|
54
|
+
allow_negative_coefficient: bool = Field(
|
|
55
|
+
default=True,
|
|
56
|
+
alias="allowNegativeCoefficient",
|
|
57
|
+
description="Whether the coefficient can be negative.",
|
|
58
|
+
)
|
|
54
59
|
|
|
55
60
|
|
|
56
61
|
class MultiVariableRegressionInput(BaseModel):
|
|
@@ -123,6 +128,17 @@ class MultiVariableRegressionInput(BaseModel):
|
|
|
123
128
|
|
|
124
129
|
return frame
|
|
125
130
|
|
|
131
|
+
def get_disallowed_negative_coefficients(self) -> List[str]:
|
|
132
|
+
"""Get independent variables that are not allowed to have a negative coefficient."""
|
|
133
|
+
result = []
|
|
134
|
+
for iv in self.independent_variables: # pylint: disable=not-an-iterable
|
|
135
|
+
if iv.name == COLUMN_TEMPERATUREEQUIVALENT and iv.variants is not None:
|
|
136
|
+
if not iv.allow_negative_coefficient:
|
|
137
|
+
result.extend(iv.variants)
|
|
138
|
+
elif not iv.allow_negative_coefficient:
|
|
139
|
+
result.append(iv.name)
|
|
140
|
+
return result
|
|
141
|
+
|
|
126
142
|
|
|
127
143
|
######################
|
|
128
144
|
# MVLR Result Models #
|
|
@@ -41,6 +41,7 @@ class MultiVariableLinearRegression:
|
|
|
41
41
|
allow_negative_predictions: bool = False,
|
|
42
42
|
granularity: Granularity = None,
|
|
43
43
|
single_use_exog_prefixes: list[str] = None,
|
|
44
|
+
exogs__disallow_negative_coefficient: list[str] = None,
|
|
44
45
|
):
|
|
45
46
|
"""Parameters
|
|
46
47
|
----------
|
|
@@ -72,6 +73,8 @@ class MultiVariableLinearRegression:
|
|
|
72
73
|
will be used as an independent variable.
|
|
73
74
|
Once the best fit using a variable with a given prefix is found, the other variables with the same
|
|
74
75
|
prefix will not be used as independent variables.
|
|
76
|
+
exogs__disallow_negative_coefficient : list of str, default=None
|
|
77
|
+
List of variable names for which the coefficient is not allowed to be negative.
|
|
75
78
|
"""
|
|
76
79
|
self.data = data.copy()
|
|
77
80
|
if y not in self.data.columns:
|
|
@@ -87,6 +90,7 @@ class MultiVariableLinearRegression:
|
|
|
87
90
|
self.allow_negative_predictions = allow_negative_predictions
|
|
88
91
|
self.granularity = granularity
|
|
89
92
|
self.single_use_exog_prefixes = single_use_exog_prefixes
|
|
93
|
+
self.exogs__disallow_negative_coefficient = exogs__disallow_negative_coefficient
|
|
90
94
|
self._fit = None
|
|
91
95
|
self._list_of_fits = []
|
|
92
96
|
self.list_of_cverrors = []
|
|
@@ -161,6 +165,15 @@ class MultiVariableLinearRegression:
|
|
|
161
165
|
ref_fit.model.formula.rhs_termlist + [term],
|
|
162
166
|
)
|
|
163
167
|
fit = fm.ols(model_desc, data=self.data).fit()
|
|
168
|
+
|
|
169
|
+
# Check if the coefficient of the variable is allowed to be negative
|
|
170
|
+
if (
|
|
171
|
+
self.exogs__disallow_negative_coefficient is not None
|
|
172
|
+
and x in self.exogs__disallow_negative_coefficient
|
|
173
|
+
and fit.params[x] < 0
|
|
174
|
+
):
|
|
175
|
+
continue
|
|
176
|
+
|
|
164
177
|
if fit.bic < best_bic:
|
|
165
178
|
best_bic = fit.bic
|
|
166
179
|
best_fit = fit
|
|
@@ -174,20 +187,20 @@ class MultiVariableLinearRegression:
|
|
|
174
187
|
ref_fit.model.formula.rhs_termlist,
|
|
175
188
|
):
|
|
176
189
|
break
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
|
|
191
|
+
self._list_of_fits.append(best_fit)
|
|
192
|
+
all_model_terms_dict.pop(best_x)
|
|
193
|
+
|
|
194
|
+
# Check if `best_x` starts with a prefix that should only be used once
|
|
195
|
+
# If so, remove all other variables with the same prefix from the list of candidates
|
|
196
|
+
if self.single_use_exog_prefixes:
|
|
197
|
+
for prefix in self.single_use_exog_prefixes:
|
|
198
|
+
if best_x.startswith(prefix):
|
|
199
|
+
all_model_terms_dict = {
|
|
200
|
+
k: v
|
|
201
|
+
for k, v in all_model_terms_dict.items()
|
|
202
|
+
if not k.startswith(prefix)
|
|
203
|
+
}
|
|
191
204
|
|
|
192
205
|
self._fit = self._list_of_fits[-1]
|
|
193
206
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|