levimohle commited on
Commit
ee469ba
1 Parent(s): 59b2cc9

trained lstm on bigger set

Browse files
EnergyLSTM/EDA_lstm_energy.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": null,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -31,7 +31,7 @@
31
  },
32
  {
33
  "cell_type": "code",
34
- "execution_count": null,
35
  "metadata": {},
36
  "outputs": [],
37
  "source": [
@@ -50,7 +50,7 @@
50
  },
51
  {
52
  "cell_type": "code",
53
- "execution_count": null,
54
  "metadata": {
55
  "vscode": {
56
  "languageId": "ruby"
@@ -103,11 +103,22 @@
103
  },
104
  {
105
  "cell_type": "code",
106
- "execution_count": null,
107
  "metadata": {},
108
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
109
  "source": [
110
- "eed_1h[eed_1h['hvac_S'].isna()]"
111
  ]
112
  },
113
  {
@@ -134,11 +145,11 @@
134
  " secondTSr.index = indexr[:len(secondTSr)]\n",
135
  " \n",
136
  " #FORWARD \n",
137
- " es = ExponentialSmoothing(firstTS, seasonal_periods=seasonal_periods,seasonal='add').fit()\n",
138
  " forwardPrediction = es.predict(start=firstTS.index[-1]+one, end=secondTS.index[0]-one)\n",
139
  " \n",
140
  " #BACKWARD\n",
141
- " es = ExponentialSmoothing(secondTSr, seasonal_periods=seasonal_periods,seasonal='add').fit()\n",
142
  " backwardPrediction = es.predict(start=secondTSr.index[-1]+one, end=firstTSr.index[0]-one)\n",
143
  " \n",
144
  " #INTERPOLATION\n",
@@ -150,7 +161,7 @@
150
  },
151
  {
152
  "cell_type": "code",
153
- "execution_count": null,
154
  "metadata": {},
155
  "outputs": [],
156
  "source": [
@@ -160,7 +171,7 @@
160
  " # Prepare the DataFrame\n",
161
  " df = data.copy()\n",
162
  " df = df.reset_index()\n",
163
- " df= df.dropna()\n",
164
  " \n",
165
  " # Set the maximum allowable gap (e.g., 1 hour)\n",
166
  " max_gap = pd.Timedelta(hours=1)\n",
@@ -184,115 +195,191 @@
184
  },
185
  {
186
  "cell_type": "code",
187
- "execution_count": null,
188
  "metadata": {},
189
  "outputs": [],
190
  "source": [
191
- "seasonal_periods = 24\n",
192
- "dfs = split_dfs(eed_1h[['hvac_N']])\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  "\n",
194
- "# Interpolate the gaps between the DataFrames\n",
195
- "ip_df = pd.DataFrame()\n",
196
- "for ii in range(len(dfs)-1):\n",
197
- " if (len(dfs[ii]) > 2*seasonal_periods+10) and (len(dfs[ii+1]) > 2*seasonal_periods+10):\n",
198
- " interpolation = fillgap(dfs[ii]['hvac_N'], dfs[ii+1]['hvac_N'], seasonal_periods)\n",
199
- " ip_df = pd.concat([ip_df,interpolation])\n",
200
- " else:\n",
201
- " continue"
202
  ]
203
  },
204
  {
205
  "cell_type": "code",
206
- "execution_count": 7,
207
  "metadata": {},
208
  "outputs": [
209
  {
210
  "name": "stderr",
211
  "output_type": "stream",
212
  "text": [
213
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
214
- " self._init_dates(dates, freq)\n",
215
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
216
- " self._init_dates(dates, freq)\n",
217
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
218
- " self._init_dates(dates, freq)\n",
219
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
220
- " self._init_dates(dates, freq)\n",
221
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
222
- " self._init_dates(dates, freq)\n",
223
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
224
- " self._init_dates(dates, freq)\n",
225
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
226
- " self._init_dates(dates, freq)\n",
227
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
228
- " self._init_dates(dates, freq)\n",
229
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
230
- " self._init_dates(dates, freq)\n",
231
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
232
- " self._init_dates(dates, freq)\n",
233
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
234
- " self._init_dates(dates, freq)\n",
235
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
236
- " self._init_dates(dates, freq)\n",
237
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
238
- " self._init_dates(dates, freq)\n",
239
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
240
- " self._init_dates(dates, freq)\n",
241
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
242
- " self._init_dates(dates, freq)\n",
243
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
244
- " self._init_dates(dates, freq)\n",
245
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
246
- " self._init_dates(dates, freq)\n",
247
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
248
- " self._init_dates(dates, freq)\n",
249
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
250
- " self._init_dates(dates, freq)\n",
251
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
252
- " self._init_dates(dates, freq)\n",
253
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
254
  " warnings.warn(\n",
255
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
256
- " self._init_dates(dates, freq)\n",
257
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
258
  " warnings.warn(\n",
259
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
260
- " self._init_dates(dates, freq)\n",
261
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
262
  " warnings.warn(\n",
263
- "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency H will be used.\n",
264
- " self._init_dates(dates, freq)\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
266
  " warnings.warn(\n"
267
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  }
269
  ],
270
  "source": [
271
- "seasonal_periods = 24\n",
272
- "dfs = split_dfs(eed_1h[['hvac_N']])\n",
273
  "\n",
274
- "# Interpolate the gaps between the DataFrames\n",
275
- "ip_df = pd.DataFrame()\n",
276
- "for ii in range(len(dfs)-1):\n",
277
- " seasonal_periods = max(min([len(dfs[ii]), len(dfs[ii+1])]) // 2 - 10, 2)\n",
278
- " \n",
279
- " if seasonal_periods > 2*24*7 + 10: # Using more than 1 week of seasonal patterns is not necessary\n",
280
- " seasonal_periods = 24*7\n",
281
- " interpolation = fillgap(dfs[ii]['hvac_N'], dfs[ii+1]['hvac_N'], seasonal_periods)\n",
282
- " else:\n",
283
- " interpolation = fillgap(dfs[ii]['hvac_N'], dfs[ii+1]['hvac_N'], seasonal_periods)\n",
 
 
284
  "\n",
285
- " ip_df = pd.concat([ip_df,interpolation])\n"
286
  ]
287
  },
288
  {
289
  "cell_type": "code",
290
- "execution_count": 8,
291
  "metadata": {},
292
  "outputs": [],
293
  "source": [
294
  "%matplotlib qt\n",
295
- "plt.plot(eed_1h['hvac_N'])\n",
296
  "plt.plot(ip_df)\n",
297
  "\n",
298
  "plt.show()"
@@ -300,14 +387,15 @@
300
  },
301
  {
302
  "cell_type": "code",
303
- "execution_count": null,
304
  "metadata": {},
305
  "outputs": [],
306
  "source": [
307
- "seasonal_periods=2\n",
308
- "for ii in range(len(dfs)-1):\n",
309
- " interpolation = fillgap(dfs[ii]['hvac_N'], dfs[ii+1]['hvac_N'], seasonal_periods)\n",
310
- " ip_df = pd.concat([ip_df,interpolation])"
 
311
  ]
312
  },
313
  {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 60,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
31
  },
32
  {
33
  "cell_type": "code",
34
+ "execution_count": 61,
35
  "metadata": {},
36
  "outputs": [],
37
  "source": [
 
50
  },
51
  {
52
  "cell_type": "code",
53
+ "execution_count": 62,
54
  "metadata": {
55
  "vscode": {
56
  "languageId": "ruby"
 
103
  },
104
  {
105
  "cell_type": "code",
106
+ "execution_count": 63,
107
  "metadata": {},
108
+ "outputs": [
109
+ {
110
+ "data": {
111
+ "text/plain": [
112
+ "[<matplotlib.lines.Line2D at 0x1d98c8cdfd0>]"
113
+ ]
114
+ },
115
+ "execution_count": 63,
116
+ "metadata": {},
117
+ "output_type": "execute_result"
118
+ }
119
+ ],
120
  "source": [
121
+ "plt.plot(eed_1h['hvac_N'])"
122
  ]
123
  },
124
  {
 
145
  " secondTSr.index = indexr[:len(secondTSr)]\n",
146
  " \n",
147
  " #FORWARD \n",
148
+ " es = ExponentialSmoothing(firstTS, seasonal_periods=seasonal_periods,seasonal='add', freq='H').fit()\n",
149
  " forwardPrediction = es.predict(start=firstTS.index[-1]+one, end=secondTS.index[0]-one)\n",
150
  " \n",
151
  " #BACKWARD\n",
152
+ " es = ExponentialSmoothing(secondTSr, seasonal_periods=seasonal_periods,seasonal='add', freq='H').fit()\n",
153
  " backwardPrediction = es.predict(start=secondTSr.index[-1]+one, end=firstTSr.index[0]-one)\n",
154
  " \n",
155
  " #INTERPOLATION\n",
 
161
  },
162
  {
163
  "cell_type": "code",
164
+ "execution_count": 67,
165
  "metadata": {},
166
  "outputs": [],
167
  "source": [
 
171
  " # Prepare the DataFrame\n",
172
  " df = data.copy()\n",
173
  " df = df.reset_index()\n",
174
+ " df = df.dropna()\n",
175
  " \n",
176
  " # Set the maximum allowable gap (e.g., 1 hour)\n",
177
  " max_gap = pd.Timedelta(hours=1)\n",
 
195
  },
196
  {
197
  "cell_type": "code",
198
+ "execution_count": 68,
199
  "metadata": {},
200
  "outputs": [],
201
  "source": [
202
+ "def interpolate_gaps(data, col):\n",
203
+ "\n",
204
+ " # Split the data into multiple DataFrames based on the gaps\n",
205
+ " dfs = split_dfs(data[[col]])\n",
206
+ "\n",
207
+ " # Interpolate the gaps between the DataFrames\n",
208
+ " ip_df = pd.DataFrame()\n",
209
+ " for ii in range(len(dfs)-1):\n",
210
+ " seasonal_periods = max(min([len(dfs[ii]), len(dfs[ii+1])]) // 2 - 10, 2)\n",
211
+ " \n",
212
+ " if seasonal_periods > 2*24*7 + 10: # Using more than 1 week of seasonal patterns is not necessary\n",
213
+ " seasonal_periods = 24*7\n",
214
+ " interpolation = fillgap(dfs[ii][col], dfs[ii+1][col], seasonal_periods)\n",
215
+ " else:\n",
216
+ " interpolation = fillgap(dfs[ii][col], dfs[ii+1][col], seasonal_periods)\n",
217
  "\n",
218
+ " ip_df = pd.concat([ip_df,dfs[ii][col],interpolation])\n",
219
+ " \n",
220
+ " # Add the last DataFrame\n",
221
+ " ip_df = pd.concat([ip_df,dfs[-1][col]])\n",
222
+ "\n",
223
+ " return ip_df"
 
 
224
  ]
225
  },
226
  {
227
  "cell_type": "code",
228
+ "execution_count": 69,
229
  "metadata": {},
230
  "outputs": [
231
  {
232
  "name": "stderr",
233
  "output_type": "stream",
234
  "text": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
236
  " warnings.warn(\n",
 
 
237
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
238
  " warnings.warn(\n",
 
 
239
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
240
  " warnings.warn(\n",
241
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
242
+ " warnings.warn(\n",
243
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
244
+ " warnings.warn(\n",
245
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
246
+ " warnings.warn(\n",
247
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
248
+ " warnings.warn(\n",
249
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
250
+ " warnings.warn(\n",
251
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
252
+ " warnings.warn(\n",
253
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
254
+ " warnings.warn(\n",
255
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
256
+ " warnings.warn(\n",
257
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
258
+ " warnings.warn(\n",
259
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
260
+ " warnings.warn(\n",
261
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
262
+ " warnings.warn(\n",
263
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
264
+ " warnings.warn(\n",
265
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
266
+ " warnings.warn(\n",
267
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
268
+ " warnings.warn(\n",
269
+ "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
270
+ " warnings.warn(\n",
271
  "c:\\Users\\levim\\anaconda3\\envs\\experiments\\lib\\site-packages\\statsmodels\\tsa\\holtwinters\\model.py:917: ConvergenceWarning: Optimization failed to converge. Check mle_retvals.\n",
272
  " warnings.warn(\n"
273
  ]
274
+ },
275
+ {
276
+ "data": {
277
+ "text/html": [
278
+ "<div>\n",
279
+ "<style scoped>\n",
280
+ " .dataframe tbody tr th:only-of-type {\n",
281
+ " vertical-align: middle;\n",
282
+ " }\n",
283
+ "\n",
284
+ " .dataframe tbody tr th {\n",
285
+ " vertical-align: top;\n",
286
+ " }\n",
287
+ "\n",
288
+ " .dataframe thead th {\n",
289
+ " text-align: right;\n",
290
+ " }\n",
291
+ "</style>\n",
292
+ "<table border=\"1\" class=\"dataframe\">\n",
293
+ " <thead>\n",
294
+ " <tr style=\"text-align: right;\">\n",
295
+ " <th></th>\n",
296
+ " <th>hvac_N</th>\n",
297
+ " <th>hvac_S</th>\n",
298
+ " <th>air_temp_set_1</th>\n",
299
+ " <th>solar_radiation_set_1</th>\n",
300
+ " </tr>\n",
301
+ " </thead>\n",
302
+ " <tbody>\n",
303
+ " <tr>\n",
304
+ " <th>2018-01-01 01:00:00</th>\n",
305
+ " <td>37.525001</td>\n",
306
+ " <td>19.395</td>\n",
307
+ " <td>10.8900</td>\n",
308
+ " <td>2.125</td>\n",
309
+ " </tr>\n",
310
+ " <tr>\n",
311
+ " <th>2018-01-01 02:00:00</th>\n",
312
+ " <td>37.750001</td>\n",
313
+ " <td>22.775</td>\n",
314
+ " <td>10.7550</td>\n",
315
+ " <td>0.000</td>\n",
316
+ " </tr>\n",
317
+ " <tr>\n",
318
+ " <th>2018-01-01 03:00:00</th>\n",
319
+ " <td>37.550001</td>\n",
320
+ " <td>18.920</td>\n",
321
+ " <td>10.4775</td>\n",
322
+ " <td>0.000</td>\n",
323
+ " </tr>\n",
324
+ " <tr>\n",
325
+ " <th>2018-01-01 04:00:00</th>\n",
326
+ " <td>36.675001</td>\n",
327
+ " <td>21.600</td>\n",
328
+ " <td>9.9925</td>\n",
329
+ " <td>0.000</td>\n",
330
+ " </tr>\n",
331
+ " <tr>\n",
332
+ " <th>2018-01-01 05:00:00</th>\n",
333
+ " <td>37.272500</td>\n",
334
+ " <td>19.000</td>\n",
335
+ " <td>9.8050</td>\n",
336
+ " <td>0.000</td>\n",
337
+ " </tr>\n",
338
+ " </tbody>\n",
339
+ "</table>\n",
340
+ "</div>"
341
+ ],
342
+ "text/plain": [
343
+ " hvac_N hvac_S air_temp_set_1 solar_radiation_set_1\n",
344
+ "2018-01-01 01:00:00 37.525001 19.395 10.8900 2.125\n",
345
+ "2018-01-01 02:00:00 37.750001 22.775 10.7550 0.000\n",
346
+ "2018-01-01 03:00:00 37.550001 18.920 10.4775 0.000\n",
347
+ "2018-01-01 04:00:00 36.675001 21.600 9.9925 0.000\n",
348
+ "2018-01-01 05:00:00 37.272500 19.000 9.8050 0.000"
349
+ ]
350
+ },
351
+ "execution_count": 69,
352
+ "metadata": {},
353
+ "output_type": "execute_result"
354
  }
355
  ],
356
  "source": [
357
+ "# interpolation of the whole data set\n",
 
358
  "\n",
359
+ "ip_eed_1h = pd.DataFrame()\n",
360
+ "for ii in eed_1h.columns:\n",
361
+ " ip_df = interpolate_gaps(eed_1h, ii)\n",
362
+ " ip_eed_1h = pd.concat([ip_eed_1h, ip_df[0]], axis=1) # axis=1 for horizontal concat\n",
363
+ "ip_eed_1h.columns = list(eed_1h.columns)\n",
364
+ "\n",
365
+ "# Reset the index and rename the columns\n",
366
+ "ip_eed_1h = ip_eed_1h.reset_index()\n",
367
+ "ip_eed_1h = ip_eed_1h.rename(columns={'index': 'date'})\n",
368
+ "ip_eed_1h.head()\n",
369
+ "\n",
370
+ "ip_eed_1h.to_csv(dataPATH + r\"\\interpolated_energy_data.csv\")\n",
371
  "\n",
372
+ "ip_eed_1h.head()"
373
  ]
374
  },
375
  {
376
  "cell_type": "code",
377
+ "execution_count": null,
378
  "metadata": {},
379
  "outputs": [],
380
  "source": [
381
  "%matplotlib qt\n",
382
+ "# plt.plot(eed_1h['hvac_N'])\n",
383
  "plt.plot(ip_df)\n",
384
  "\n",
385
  "plt.show()"
 
387
  },
388
  {
389
  "cell_type": "code",
390
+ "execution_count": 73,
391
  "metadata": {},
392
  "outputs": [],
393
  "source": [
394
+ "# Reset the index and rename the columns\n",
395
+ "# ip_eed_1h = ip_eed_1h.set_index('date')\n",
396
+ "ip_eed_1h.head()\n",
397
+ "\n",
398
+ "ip_eed_1h.to_csv(dataPATH + r\"\\interpolated_energy_data.csv\")"
399
  ]
400
  },
401
  {
EnergyLSTM/lstm_energy.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 22,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -10,7 +10,6 @@
10
  "from datetime import datetime \n",
11
  "from datetime import date\n",
12
  "import matplotlib.pyplot as plt\n",
13
- "# import seaborn as sns\n",
14
  "import numpy as np\n",
15
  "import pandas as pd\n",
16
  "from keras.models import Sequential\n",
@@ -21,12 +20,45 @@
21
  "\n",
22
  "dataPATH = r\"C:\\Users\\levim\\OneDrive\\Documents\\MastersAI_ES\\TeamProject-5ARIP10\\smart-buildings\\Data\"\n",
23
  "# all_data = pd.read_csv(dataPATH + r\"\\long_merge.csv\")\n",
24
- "all_data = pd.read_csv(dataPATH + r\"\\extended_energy_data.csv\")"
 
25
  ]
26
  },
27
  {
28
  "cell_type": "code",
29
- "execution_count": 23,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "metadata": {},
31
  "outputs": [
32
  {
@@ -53,128 +85,106 @@
53
  " <th>date</th>\n",
54
  " <th>hvac_N</th>\n",
55
  " <th>hvac_S</th>\n",
 
56
  " <th>air_temp_set_1</th>\n",
57
  " <th>solar_radiation_set_1</th>\n",
58
  " </tr>\n",
59
  " </thead>\n",
60
  " <tbody>\n",
61
  " <tr>\n",
62
- " <th>0</th>\n",
63
- " <td>2018-01-01 00:00:00</td>\n",
64
- " <td>NaN</td>\n",
65
- " <td>NaN</td>\n",
66
- " <td>11.64</td>\n",
67
- " <td>86.70</td>\n",
 
68
  " </tr>\n",
69
  " <tr>\n",
70
- " <th>1</th>\n",
71
- " <td>2018-01-01 00:15:00</td>\n",
72
- " <td>NaN</td>\n",
73
- " <td>NaN</td>\n",
74
- " <td>11.49</td>\n",
75
- " <td>45.88</td>\n",
 
76
  " </tr>\n",
77
  " <tr>\n",
78
- " <th>2</th>\n",
79
- " <td>2018-01-01 00:30:00</td>\n",
80
- " <td>NaN</td>\n",
81
- " <td>NaN</td>\n",
82
- " <td>11.59</td>\n",
83
- " <td>51.62</td>\n",
 
84
  " </tr>\n",
85
  " <tr>\n",
86
- " <th>3</th>\n",
87
- " <td>2018-01-01 00:45:00</td>\n",
88
- " <td>NaN</td>\n",
89
- " <td>NaN</td>\n",
90
- " <td>11.44</td>\n",
91
- " <td>21.43</td>\n",
 
92
  " </tr>\n",
93
  " <tr>\n",
94
- " <th>4</th>\n",
95
- " <td>2018-01-01 01:00:00</td>\n",
96
- " <td>37.400002</td>\n",
97
- " <td>19.5</td>\n",
98
- " <td>11.12</td>\n",
99
- " <td>6.45</td>\n",
 
100
  " </tr>\n",
101
  " </tbody>\n",
102
  "</table>\n",
103
  "</div>"
104
  ],
105
  "text/plain": [
106
- " date hvac_N hvac_S air_temp_set_1 \\\n",
107
- "0 2018-01-01 00:00:00 NaN NaN 11.64 \n",
108
- "1 2018-01-01 00:15:00 NaN NaN 11.49 \n",
109
- "2 2018-01-01 00:30:00 NaN NaN 11.59 \n",
110
- "3 2018-01-01 00:45:00 NaN NaN 11.44 \n",
111
- "4 2018-01-01 01:00:00 37.400002 19.5 11.12 \n",
112
  "\n",
113
- " solar_radiation_set_1 \n",
114
- "0 86.70 \n",
115
- "1 45.88 \n",
116
- "2 51.62 \n",
117
- "3 21.43 \n",
118
- "4 6.45 "
119
  ]
120
  },
121
- "execution_count": 23,
122
  "metadata": {},
123
  "output_type": "execute_result"
124
  }
125
  ],
126
- "source": [
127
- "# Prepar energy data set with extended features\n",
128
- "feature_list = ['date', 'hvac_N', 'hvac_S', 'air_temp_set_1', 'solar_radiation_set_1']\n",
129
- "extended_energy_data = all_data[feature_list]\n",
130
- "\n",
131
- "extended_energy_data['date'] = pd.to_datetime(extended_energy_data['date'])\n",
132
- "extended_energy_data.set_index('date', inplace=True)\n",
133
- "\n",
134
- "eed_15m = extended_energy_data.resample('15T').mean()\n",
135
- "eed_1h = extended_energy_data.resample('60T').mean()\n",
136
- "\n",
137
- "eed_15m = eed_15m.reset_index(drop=False)\n",
138
- "eed_1h = eed_1h.reset_index(drop=False)\n",
139
- "\n",
140
- "window_size = 4*4 # 4 hours\n",
141
- "eed_15m_avg = eed_15m.copy()\n",
142
- "eed_15m_avg['hvac_N'] = eed_15m['hvac_N'].rolling(window=window_size).mean()\n",
143
- "eed_15m_avg['hvac_S'] = eed_15m['hvac_S'].rolling(window=window_size).mean()\n",
144
- "\n",
145
- "window_size = 4 # 4 hours\n",
146
- "eed_1h_avg = eed_1h.copy()\n",
147
- "eed_1h_avg['hvac_N'] = eed_1h['hvac_N'].rolling(window=window_size).mean()\n",
148
- "eed_1h_avg['hvac_S'] = eed_1h['hvac_S'].rolling(window=window_size).mean()\n",
149
- "\n",
150
- "eed_15m.head()"
151
- ]
152
- },
153
- {
154
- "cell_type": "code",
155
- "execution_count": 24,
156
- "metadata": {},
157
- "outputs": [],
158
  "source": [
159
  "# energy_data = pd.read_csv(dataPATH + r\"\\extended_energy_data.csv\")\n",
160
  "# energy_data = eed_15m\n",
161
- "energy_data = eed_15m_avg\n",
 
 
162
  "\n",
163
  "# Convert the date column to datetime\n",
164
  "energy_data['date'] = pd.to_datetime(energy_data['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
165
  "\n",
166
- "energy_data['day_of_week'] = energy_data['date'].dt.weekday\n",
167
  "# Filter the data for the year 2019\n",
168
- "df_filtered = energy_data[ (energy_data.date.dt.date >date(2019, 1, 20)) & (energy_data.date.dt.date< date(2019, 7, 26))]\n",
169
  "\n",
170
  "# Check for NA values in the DataFrame\n",
171
  "if df_filtered.isna().any().any():\n",
172
- " print(\"There are NA values in the DataFrame columns.\")"
 
 
173
  ]
174
  },
175
  {
176
  "cell_type": "code",
177
- "execution_count": 25,
178
  "metadata": {},
179
  "outputs": [
180
  {
@@ -183,15 +193,15 @@
183
  "[]"
184
  ]
185
  },
186
- "execution_count": 25,
187
  "metadata": {},
188
  "output_type": "execute_result"
189
  }
190
  ],
191
  "source": [
192
- "testdataset_df = df_filtered[(df_filtered.date.dt.date <date(2019, 2, 20))]\n",
193
  "\n",
194
- "traindataset_df = df_filtered[ (df_filtered.date.dt.date >date(2019, 2, 21))]\n",
195
  "\n",
196
  "testdataset = testdataset_df.drop(columns=[\"date\"]).values\n",
197
  "\n",
@@ -203,7 +213,7 @@
203
  },
204
  {
205
  "cell_type": "code",
206
- "execution_count": 26,
207
  "metadata": {},
208
  "outputs": [],
209
  "source": [
@@ -220,7 +230,7 @@
220
  },
221
  {
222
  "cell_type": "code",
223
- "execution_count": 48,
224
  "metadata": {},
225
  "outputs": [],
226
  "source": [
@@ -245,46 +255,9 @@
245
  },
246
  {
247
  "cell_type": "code",
248
- "execution_count": 35,
249
  "metadata": {},
250
- "outputs": [
251
- {
252
- "name": "stdout",
253
- "output_type": "stream",
254
- "text": [
255
- "Epoch 1/5\n",
256
- "225/229 [============================>.] - ETA: 0s - loss: 0.0130\n",
257
- "Epoch 1: val_loss improved from inf to 0.01885, saving model to lstm_energy_01.keras\n",
258
- "229/229 [==============================] - 8s 16ms/step - loss: 0.0129 - val_loss: 0.0189\n",
259
- "Epoch 2/5\n",
260
- "229/229 [==============================] - ETA: 0s - loss: 0.0058\n",
261
- "Epoch 2: val_loss did not improve from 0.01885\n",
262
- "229/229 [==============================] - 3s 11ms/step - loss: 0.0058 - val_loss: 0.0192\n",
263
- "Epoch 3/5\n",
264
- "225/229 [============================>.] - ETA: 0s - loss: 0.0052\n",
265
- "Epoch 3: val_loss improved from 0.01885 to 0.01818, saving model to lstm_energy_01.keras\n",
266
- "229/229 [==============================] - 3s 11ms/step - loss: 0.0052 - val_loss: 0.0182\n",
267
- "Epoch 4/5\n",
268
- "225/229 [============================>.] - ETA: 0s - loss: 0.0045\n",
269
- "Epoch 4: val_loss did not improve from 0.01818\n",
270
- "229/229 [==============================] - 3s 11ms/step - loss: 0.0045 - val_loss: 0.0190\n",
271
- "Epoch 5/5\n",
272
- "226/229 [============================>.] - ETA: 0s - loss: 0.0041\n",
273
- "Epoch 5: val_loss did not improve from 0.01818\n",
274
- "229/229 [==============================] - 3s 11ms/step - loss: 0.0041 - val_loss: 0.0186\n"
275
- ]
276
- },
277
- {
278
- "data": {
279
- "text/plain": [
280
- "<keras.callbacks.History at 0x25e69ac0370>"
281
- ]
282
- },
283
- "execution_count": 35,
284
- "metadata": {},
285
- "output_type": "execute_result"
286
- }
287
- ],
288
  "source": [
289
  "train,test = traindataset,testdataset\n",
290
  "steps_in_past = 3 \n",
@@ -318,19 +291,9 @@
318
  },
319
  {
320
  "cell_type": "code",
321
- "execution_count": 51,
322
  "metadata": {},
323
- "outputs": [
324
- {
325
- "name": "stdout",
326
- "output_type": "stream",
327
- "text": [
328
- "4/4 [==============================] - 0s 4ms/step - loss: 0.0153\n",
329
- "4/4 [==============================] - 1s 4ms/step\n",
330
- "Loss: 0.01531214825809002\n"
331
- ]
332
- }
333
- ],
334
  "source": [
335
  "loss = model.evaluate(X_test, y_test)\n",
336
  "test_predict1 = model.predict(X_test)\n",
@@ -343,21 +306,9 @@
343
  },
344
  {
345
  "cell_type": "code",
346
- "execution_count": 52,
347
  "metadata": {},
348
- "outputs": [
349
- {
350
- "ename": "IndexError",
351
- "evalue": "index 106 is out of bounds for axis 0 with size 106",
352
- "output_type": "error",
353
- "traceback": [
354
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
355
- "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
356
- "Cell \u001b[1;32mIn[52], line 10\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;66;03m# Loop over the value index\u001b[39;00m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, ax \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(axes\u001b[38;5;241m.\u001b[39mflat):\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# Plot your data or perform any other operations\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m ax\u001b[38;5;241m.\u001b[39mplot(\u001b[43my_test\u001b[49m\u001b[43m[\u001b[49m\u001b[43mvar\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mi\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mtime_step\u001b[49m\u001b[43m]\u001b[49m, label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOriginal Testing Data\u001b[39m\u001b[38;5;124m'\u001b[39m, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mblue\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 11\u001b[0m ax\u001b[38;5;241m.\u001b[39mplot(test_predict1[var\u001b[38;5;241m+\u001b[39mi,\u001b[38;5;241m0\u001b[39m:time_step], label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPredicted Testing Data\u001b[39m\u001b[38;5;124m'\u001b[39m, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mred\u001b[39m\u001b[38;5;124m'\u001b[39m,alpha\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.8\u001b[39m)\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# ax.set_title(f'Plot {i+1}')\u001b[39;00m\n",
357
- "\u001b[1;31mIndexError\u001b[0m: index 106 is out of bounds for axis 0 with size 106"
358
- ]
359
- }
360
- ],
361
  "source": [
362
  "%matplotlib qt\n",
363
  "\n",
@@ -418,7 +369,7 @@
418
  },
419
  {
420
  "cell_type": "code",
421
- "execution_count": 50,
422
  "metadata": {},
423
  "outputs": [
424
  {
@@ -426,94 +377,94 @@
426
  "output_type": "stream",
427
  "text": [
428
  "Epoch 1/20\n",
429
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0850 \n",
430
- "Epoch 1: val_loss improved from inf to 0.07467, saving model to lstm_energy_01.keras\n",
431
- "10/10 [==============================] - 7s 131ms/step - loss: 0.0791 - val_loss: 0.0747\n",
432
  "Epoch 2/20\n",
433
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0487\n",
434
- "Epoch 2: val_loss improved from 0.07467 to 0.03484, saving model to lstm_energy_01.keras\n",
435
- "10/10 [==============================] - 0s 20ms/step - loss: 0.0419 - val_loss: 0.0348\n",
436
  "Epoch 3/20\n",
437
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0262\n",
438
- "Epoch 3: val_loss improved from 0.03484 to 0.02388, saving model to lstm_energy_01.keras\n",
439
- "10/10 [==============================] - 0s 17ms/step - loss: 0.0241 - val_loss: 0.0239\n",
440
  "Epoch 4/20\n",
441
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0180\n",
442
- "Epoch 4: val_loss improved from 0.02388 to 0.02059, saving model to lstm_energy_01.keras\n",
443
- "10/10 [==============================] - 0s 18ms/step - loss: 0.0174 - val_loss: 0.0206\n",
444
  "Epoch 5/20\n",
445
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0134\n",
446
- "Epoch 5: val_loss improved from 0.02059 to 0.01839, saving model to lstm_energy_01.keras\n",
447
- "10/10 [==============================] - 0s 18ms/step - loss: 0.0130 - val_loss: 0.0184\n",
448
  "Epoch 6/20\n",
449
- " 8/10 [=======================>......] - ETA: 0s - loss: 0.0107\n",
450
- "Epoch 6: val_loss did not improve from 0.01839\n",
451
- "10/10 [==============================] - 0s 21ms/step - loss: 0.0106 - val_loss: 0.0255\n",
452
  "Epoch 7/20\n",
453
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0090\n",
454
- "Epoch 7: val_loss did not improve from 0.01839\n",
455
- "10/10 [==============================] - 0s 14ms/step - loss: 0.0090 - val_loss: 0.0261\n",
456
  "Epoch 8/20\n",
457
- "10/10 [==============================] - ETA: 0s - loss: 0.0085\n",
458
- "Epoch 8: val_loss did not improve from 0.01839\n",
459
- "10/10 [==============================] - 0s 18ms/step - loss: 0.0085 - val_loss: 0.0197\n",
460
  "Epoch 9/20\n",
461
- " 9/10 [==========================>...] - ETA: 0s - loss: 0.0074\n",
462
- "Epoch 9: val_loss improved from 0.01839 to 0.01687, saving model to lstm_energy_01.keras\n",
463
- "10/10 [==============================] - 0s 22ms/step - loss: 0.0074 - val_loss: 0.0169\n",
464
  "Epoch 10/20\n",
465
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0066\n",
466
- "Epoch 10: val_loss did not improve from 0.01687\n",
467
- "10/10 [==============================] - 0s 14ms/step - loss: 0.0068 - val_loss: 0.0171\n",
468
  "Epoch 11/20\n",
469
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0063\n",
470
- "Epoch 11: val_loss did not improve from 0.01687\n",
471
- "10/10 [==============================] - 0s 14ms/step - loss: 0.0061 - val_loss: 0.0191\n",
472
  "Epoch 12/20\n",
473
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0057\n",
474
- "Epoch 12: val_loss improved from 0.01687 to 0.01678, saving model to lstm_energy_01.keras\n",
475
- "10/10 [==============================] - 0s 18ms/step - loss: 0.0057 - val_loss: 0.0168\n",
476
  "Epoch 13/20\n",
477
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0052\n",
478
- "Epoch 13: val_loss did not improve from 0.01678\n",
479
- "10/10 [==============================] - 0s 13ms/step - loss: 0.0058 - val_loss: 0.0206\n",
480
  "Epoch 14/20\n",
481
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0058\n",
482
- "Epoch 14: val_loss improved from 0.01678 to 0.01612, saving model to lstm_energy_01.keras\n",
483
- "10/10 [==============================] - 0s 20ms/step - loss: 0.0062 - val_loss: 0.0161\n",
484
  "Epoch 15/20\n",
485
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0061\n",
486
- "Epoch 15: val_loss did not improve from 0.01612\n",
487
- "10/10 [==============================] - 0s 14ms/step - loss: 0.0059 - val_loss: 0.0184\n",
488
  "Epoch 16/20\n",
489
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0054\n",
490
- "Epoch 16: val_loss improved from 0.01612 to 0.01561, saving model to lstm_energy_01.keras\n",
491
- "10/10 [==============================] - 0s 17ms/step - loss: 0.0053 - val_loss: 0.0156\n",
492
  "Epoch 17/20\n",
493
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0046\n",
494
- "Epoch 17: val_loss did not improve from 0.01561\n",
495
- "10/10 [==============================] - 0s 13ms/step - loss: 0.0048 - val_loss: 0.0166\n",
496
  "Epoch 18/20\n",
497
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0054\n",
498
- "Epoch 18: val_loss improved from 0.01561 to 0.01503, saving model to lstm_energy_01.keras\n",
499
- "10/10 [==============================] - 0s 18ms/step - loss: 0.0052 - val_loss: 0.0150\n",
500
  "Epoch 19/20\n",
501
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0050\n",
502
- "Epoch 19: val_loss did not improve from 0.01503\n",
503
- "10/10 [==============================] - 0s 13ms/step - loss: 0.0046 - val_loss: 0.0156\n",
504
  "Epoch 20/20\n",
505
- " 6/10 [=================>............] - ETA: 0s - loss: 0.0045\n",
506
- "Epoch 20: val_loss did not improve from 0.01503\n",
507
- "10/10 [==============================] - 0s 14ms/step - loss: 0.0045 - val_loss: 0.0153\n"
508
  ]
509
  },
510
  {
511
  "data": {
512
  "text/plain": [
513
- "<keras.callbacks.History at 0x25e3a8cf640>"
514
  ]
515
  },
516
- "execution_count": 50,
517
  "metadata": {},
518
  "output_type": "execute_result"
519
  }
@@ -551,10 +502,58 @@
551
  },
552
  {
553
  "cell_type": "code",
554
- "execution_count": null,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  "metadata": {},
556
  "outputs": [],
557
- "source": []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  },
559
  {
560
  "cell_type": "code",
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 61,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
10
  "from datetime import datetime \n",
11
  "from datetime import date\n",
12
  "import matplotlib.pyplot as plt\n",
 
13
  "import numpy as np\n",
14
  "import pandas as pd\n",
15
  "from keras.models import Sequential\n",
 
20
  "\n",
21
  "dataPATH = r\"C:\\Users\\levim\\OneDrive\\Documents\\MastersAI_ES\\TeamProject-5ARIP10\\smart-buildings\\Data\"\n",
22
  "# all_data = pd.read_csv(dataPATH + r\"\\long_merge.csv\")\n",
23
+ "all_data = pd.read_csv(dataPATH + r\"\\extended_energy_data.csv\")\n",
24
+ "interpolated_data = pd.read_csv(dataPATH + r\"\\interpolated_energy_data.csv\", index_col=0)"
25
  ]
26
  },
27
  {
28
  "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "# Prepar energy data set with extended features\n",
34
+ "feature_list = ['date', 'hvac_N', 'hvac_S', 'air_temp_set_1', 'solar_radiation_set_1']\n",
35
+ "extended_energy_data = all_data[feature_list]\n",
36
+ "\n",
37
+ "extended_energy_data['date'] = pd.to_datetime(extended_energy_data['date'])\n",
38
+ "extended_energy_data.set_index('date', inplace=True)\n",
39
+ "\n",
40
+ "eed_15m = extended_energy_data.resample('15T').mean()\n",
41
+ "eed_1h = extended_energy_data.resample('60T').mean()\n",
42
+ "\n",
43
+ "eed_15m = eed_15m.reset_index(drop=False)\n",
44
+ "eed_1h = eed_1h.reset_index(drop=False)\n",
45
+ "\n",
46
+ "window_size = 4*4 # 4 hours\n",
47
+ "eed_15m_avg = eed_15m.copy()\n",
48
+ "eed_15m_avg['hvac_N'] = eed_15m['hvac_N'].rolling(window=window_size).mean()\n",
49
+ "eed_15m_avg['hvac_S'] = eed_15m['hvac_S'].rolling(window=window_size).mean()\n",
50
+ "\n",
51
+ "window_size = 4 # 4 hours\n",
52
+ "eed_1h_avg = eed_1h.copy()\n",
53
+ "eed_1h_avg['hvac_N'] = eed_1h['hvac_N'].rolling(window=window_size).mean()\n",
54
+ "eed_1h_avg['hvac_S'] = eed_1h['hvac_S'].rolling(window=window_size).mean()\n",
55
+ "\n",
56
+ "eed_15m.head()"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 62,
62
  "metadata": {},
63
  "outputs": [
64
  {
 
85
  " <th>date</th>\n",
86
  " <th>hvac_N</th>\n",
87
  " <th>hvac_S</th>\n",
88
+ " <th>day_of_week</th>\n",
89
  " <th>air_temp_set_1</th>\n",
90
  " <th>solar_radiation_set_1</th>\n",
91
  " </tr>\n",
92
  " </thead>\n",
93
  " <tbody>\n",
94
  " <tr>\n",
95
+ " <th>23</th>\n",
96
+ " <td>2018-01-02 00:00:00</td>\n",
97
+ " <td>38.225000</td>\n",
98
+ " <td>26.4000</td>\n",
99
+ " <td>1</td>\n",
100
+ " <td>14.9550</td>\n",
101
+ " <td>87.4450</td>\n",
102
  " </tr>\n",
103
  " <tr>\n",
104
+ " <th>24</th>\n",
105
+ " <td>2018-01-02 01:00:00</td>\n",
106
+ " <td>38.297501</td>\n",
107
+ " <td>21.1750</td>\n",
108
+ " <td>1</td>\n",
109
+ " <td>14.2125</td>\n",
110
+ " <td>2.8675</td>\n",
111
  " </tr>\n",
112
  " <tr>\n",
113
+ " <th>25</th>\n",
114
+ " <td>2018-01-02 02:00:00</td>\n",
115
+ " <td>38.072500</td>\n",
116
+ " <td>21.7225</td>\n",
117
+ " <td>1</td>\n",
118
+ " <td>14.2700</td>\n",
119
+ " <td>0.0925</td>\n",
120
  " </tr>\n",
121
  " <tr>\n",
122
+ " <th>26</th>\n",
123
+ " <td>2018-01-02 03:00:00</td>\n",
124
+ " <td>39.147500</td>\n",
125
+ " <td>21.7000</td>\n",
126
+ " <td>1</td>\n",
127
+ " <td>14.1375</td>\n",
128
+ " <td>0.1175</td>\n",
129
  " </tr>\n",
130
  " <tr>\n",
131
+ " <th>27</th>\n",
132
+ " <td>2018-01-02 04:00:00</td>\n",
133
+ " <td>38.172500</td>\n",
134
+ " <td>21.6250</td>\n",
135
+ " <td>1</td>\n",
136
+ " <td>13.9850</td>\n",
137
+ " <td>0.0725</td>\n",
138
  " </tr>\n",
139
  " </tbody>\n",
140
  "</table>\n",
141
  "</div>"
142
  ],
143
  "text/plain": [
144
+ " date hvac_N hvac_S day_of_week air_temp_set_1 \\\n",
145
+ "23 2018-01-02 00:00:00 38.225000 26.4000 1 14.9550 \n",
146
+ "24 2018-01-02 01:00:00 38.297501 21.1750 1 14.2125 \n",
147
+ "25 2018-01-02 02:00:00 38.072500 21.7225 1 14.2700 \n",
148
+ "26 2018-01-02 03:00:00 39.147500 21.7000 1 14.1375 \n",
149
+ "27 2018-01-02 04:00:00 38.172500 21.6250 1 13.9850 \n",
150
  "\n",
151
+ " solar_radiation_set_1 \n",
152
+ "23 87.4450 \n",
153
+ "24 2.8675 \n",
154
+ "25 0.0925 \n",
155
+ "26 0.1175 \n",
156
+ "27 0.0725 "
157
  ]
158
  },
159
+ "execution_count": 62,
160
  "metadata": {},
161
  "output_type": "execute_result"
162
  }
163
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  "source": [
165
  "# energy_data = pd.read_csv(dataPATH + r\"\\extended_energy_data.csv\")\n",
166
  "# energy_data = eed_15m\n",
167
+ "# energy_data = eed_15m_avg\n",
168
+ "energy_data = interpolated_data.copy()\n",
169
+ "energy_data = energy_data.reset_index()\n",
170
  "\n",
171
  "# Convert the date column to datetime\n",
172
  "energy_data['date'] = pd.to_datetime(energy_data['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
173
  "\n",
174
+ "energy_data.insert(3, 'day_of_week', energy_data['date'].dt.weekday)\n",
175
  "# Filter the data for the year 2019\n",
176
+ "df_filtered = energy_data[ (energy_data.date.dt.date >date(2018, 1, 1)) & (energy_data.date.dt.date< date(2021, 1, 1))]\n",
177
  "\n",
178
  "# Check for NA values in the DataFrame\n",
179
  "if df_filtered.isna().any().any():\n",
180
+ " print(\"There are NA values in the DataFrame columns.\")\n",
181
+ "\n",
182
+ "df_filtered.head()"
183
  ]
184
  },
185
  {
186
  "cell_type": "code",
187
+ "execution_count": 70,
188
  "metadata": {},
189
  "outputs": [
190
  {
 
193
  "[]"
194
  ]
195
  },
196
+ "execution_count": 70,
197
  "metadata": {},
198
  "output_type": "execute_result"
199
  }
200
  ],
201
  "source": [
202
+ "testdataset_df = df_filtered[(df_filtered.date.dt.date >=date(2019, 3, 1)) & (df_filtered.date.dt.date <= date(2019, 6, 1))]\n",
203
  "\n",
204
+ "traindataset_df = df_filtered[ (df_filtered.date.dt.date <date(2019, 3, 1)) | (df_filtered.date.dt.date > date(2019, 6, 1))]\n",
205
  "\n",
206
  "testdataset = testdataset_df.drop(columns=[\"date\"]).values\n",
207
  "\n",
 
213
  },
214
  {
215
  "cell_type": "code",
216
+ "execution_count": 71,
217
  "metadata": {},
218
  "outputs": [],
219
  "source": [
 
230
  },
231
  {
232
  "cell_type": "code",
233
+ "execution_count": null,
234
  "metadata": {},
235
  "outputs": [],
236
  "source": [
 
255
  },
256
  {
257
  "cell_type": "code",
258
+ "execution_count": null,
259
  "metadata": {},
260
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  "source": [
262
  "train,test = traindataset,testdataset\n",
263
  "steps_in_past = 3 \n",
 
291
  },
292
  {
293
  "cell_type": "code",
294
+ "execution_count": null,
295
  "metadata": {},
296
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
297
  "source": [
298
  "loss = model.evaluate(X_test, y_test)\n",
299
  "test_predict1 = model.predict(X_test)\n",
 
306
  },
307
  {
308
  "cell_type": "code",
309
+ "execution_count": null,
310
  "metadata": {},
311
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
312
  "source": [
313
  "%matplotlib qt\n",
314
  "\n",
 
369
  },
370
  {
371
  "cell_type": "code",
372
+ "execution_count": 79,
373
  "metadata": {},
374
  "outputs": [
375
  {
 
377
  "output_type": "stream",
378
  "text": [
379
  "Epoch 1/20\n",
380
+ "16/16 [==============================] - ETA: 0s - loss: 0.1003\n",
381
+ "Epoch 1: val_loss improved from inf to 0.04277, saving model to lstm_energy_01.keras\n",
382
+ "16/16 [==============================] - 6s 89ms/step - loss: 0.1003 - val_loss: 0.0428\n",
383
  "Epoch 2/20\n",
384
+ "16/16 [==============================] - ETA: 0s - loss: 0.0340\n",
385
+ "Epoch 2: val_loss improved from 0.04277 to 0.03142, saving model to lstm_energy_01.keras\n",
386
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0340 - val_loss: 0.0314\n",
387
  "Epoch 3/20\n",
388
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0270\n",
389
+ "Epoch 3: val_loss improved from 0.03142 to 0.02204, saving model to lstm_energy_01.keras\n",
390
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0268 - val_loss: 0.0220\n",
391
  "Epoch 4/20\n",
392
+ "15/16 [===========================>..] - ETA: 0s - loss: 0.0220\n",
393
+ "Epoch 4: val_loss improved from 0.02204 to 0.01482, saving model to lstm_energy_01.keras\n",
394
+ "16/16 [==============================] - 0s 15ms/step - loss: 0.0220 - val_loss: 0.0148\n",
395
  "Epoch 5/20\n",
396
+ "13/16 [=======================>......] - ETA: 0s - loss: 0.0197\n",
397
+ "Epoch 5: val_loss improved from 0.01482 to 0.01388, saving model to lstm_energy_01.keras\n",
398
+ "16/16 [==============================] - 0s 18ms/step - loss: 0.0192 - val_loss: 0.0139\n",
399
  "Epoch 6/20\n",
400
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0176\n",
401
+ "Epoch 6: val_loss did not improve from 0.01388\n",
402
+ "16/16 [==============================] - 0s 15ms/step - loss: 0.0177 - val_loss: 0.0156\n",
403
  "Epoch 7/20\n",
404
+ "15/16 [===========================>..] - ETA: 0s - loss: 0.0177\n",
405
+ "Epoch 7: val_loss improved from 0.01388 to 0.01233, saving model to lstm_energy_01.keras\n",
406
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0177 - val_loss: 0.0123\n",
407
  "Epoch 8/20\n",
408
+ "13/16 [=======================>......] - ETA: 0s - loss: 0.0172\n",
409
+ "Epoch 8: val_loss improved from 0.01233 to 0.01210, saving model to lstm_energy_01.keras\n",
410
+ "16/16 [==============================] - 0s 14ms/step - loss: 0.0171 - val_loss: 0.0121\n",
411
  "Epoch 9/20\n",
412
+ "13/16 [=======================>......] - ETA: 0s - loss: 0.0174\n",
413
+ "Epoch 9: val_loss did not improve from 0.01210\n",
414
+ "16/16 [==============================] - 0s 15ms/step - loss: 0.0174 - val_loss: 0.0126\n",
415
  "Epoch 10/20\n",
416
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0162\n",
417
+ "Epoch 10: val_loss did not improve from 0.01210\n",
418
+ "16/16 [==============================] - 0s 16ms/step - loss: 0.0165 - val_loss: 0.0138\n",
419
  "Epoch 11/20\n",
420
+ "16/16 [==============================] - ETA: 0s - loss: 0.0164\n",
421
+ "Epoch 11: val_loss did not improve from 0.01210\n",
422
+ "16/16 [==============================] - 0s 13ms/step - loss: 0.0164 - val_loss: 0.0141\n",
423
  "Epoch 12/20\n",
424
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0167\n",
425
+ "Epoch 12: val_loss did not improve from 0.01210\n",
426
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0166 - val_loss: 0.0139\n",
427
  "Epoch 13/20\n",
428
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0165\n",
429
+ "Epoch 13: val_loss did not improve from 0.01210\n",
430
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0162 - val_loss: 0.0137\n",
431
  "Epoch 14/20\n",
432
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0158\n",
433
+ "Epoch 14: val_loss did not improve from 0.01210\n",
434
+ "16/16 [==============================] - 0s 16ms/step - loss: 0.0156 - val_loss: 0.0122\n",
435
  "Epoch 15/20\n",
436
+ "14/16 [=========================>....] - ETA: 0s - loss: 0.0150\n",
437
+ "Epoch 15: val_loss improved from 0.01210 to 0.01155, saving model to lstm_energy_01.keras\n",
438
+ "16/16 [==============================] - 0s 17ms/step - loss: 0.0153 - val_loss: 0.0116\n",
439
  "Epoch 16/20\n",
440
+ "12/16 [=====================>........] - ETA: 0s - loss: 0.0157\n",
441
+ "Epoch 16: val_loss did not improve from 0.01155\n",
442
+ "16/16 [==============================] - 0s 12ms/step - loss: 0.0158 - val_loss: 0.0116\n",
443
  "Epoch 17/20\n",
444
+ "16/16 [==============================] - ETA: 0s - loss: 0.0149\n",
445
+ "Epoch 17: val_loss did not improve from 0.01155\n",
446
+ "16/16 [==============================] - 0s 14ms/step - loss: 0.0149 - val_loss: 0.0118\n",
447
  "Epoch 18/20\n",
448
+ "15/16 [===========================>..] - ETA: 0s - loss: 0.0142\n",
449
+ "Epoch 18: val_loss did not improve from 0.01155\n",
450
+ "16/16 [==============================] - 0s 15ms/step - loss: 0.0144 - val_loss: 0.0118\n",
451
  "Epoch 19/20\n",
452
+ "16/16 [==============================] - ETA: 0s - loss: 0.0142\n",
453
+ "Epoch 19: val_loss improved from 0.01155 to 0.01153, saving model to lstm_energy_01.keras\n",
454
+ "16/16 [==============================] - 0s 15ms/step - loss: 0.0142 - val_loss: 0.0115\n",
455
  "Epoch 20/20\n",
456
+ "12/16 [=====================>........] - ETA: 0s - loss: 0.0147\n",
457
+ "Epoch 20: val_loss did not improve from 0.01153\n",
458
+ "16/16 [==============================] - 0s 12ms/step - loss: 0.0142 - val_loss: 0.0125\n"
459
  ]
460
  },
461
  {
462
  "data": {
463
  "text/plain": [
464
+ "<keras.callbacks.History at 0x1da5016dcd0>"
465
  ]
466
  },
467
+ "execution_count": 79,
468
  "metadata": {},
469
  "output_type": "execute_result"
470
  }
 
502
  },
503
  {
504
  "cell_type": "code",
505
+ "execution_count": 80,
506
+ "metadata": {},
507
+ "outputs": [
508
+ {
509
+ "name": "stdout",
510
+ "output_type": "stream",
511
+ "text": [
512
+ "3/3 [==============================] - 0s 3ms/step - loss: 0.0125\n",
513
+ "3/3 [==============================] - 1s 4ms/step\n",
514
+ "Loss: 0.012460779398679733\n"
515
+ ]
516
+ }
517
+ ],
518
+ "source": [
519
+ "loss = model.evaluate(X_test, y_test)\n",
520
+ "test_predict1 = model.predict(X_test)\n",
521
+ "print(\"Loss: \", loss)\n",
522
+ "# Converting values back to the original scale\n",
523
+ "scalerBack = MinMaxScaler(feature_range=(mintest, maxtest))\n",
524
+ "test_predict2 = scalerBack.fit_transform(test_predict1)\n",
525
+ "y_test1 = scalerBack.fit_transform(y_test)\n"
526
+ ]
527
+ },
528
+ {
529
+ "cell_type": "code",
530
+ "execution_count": 81,
531
  "metadata": {},
532
  "outputs": [],
533
+ "source": [
534
+ "%matplotlib qt\n",
535
+ "\n",
536
+ "# Create a 3x3 grid of subplots\n",
537
+ "fig, axes = plt.subplots(3, 3, figsize=(10, 10))\n",
538
+ "\n",
539
+ "var = 1\n",
540
+ "# Loop over the value index\n",
541
+ "for i, ax in enumerate(axes.flat):\n",
542
+ " # Plot your data or perform any other operations\n",
543
+ " ax.plot(y_test1[var+i,0:time_step], label='Original Testing Data', color='blue')\n",
544
+ " ax.plot(test_predict2[var+i,0:time_step], label='Predicted Testing Data', color='red',alpha=0.8)\n",
545
+ " # ax.set_title(f'Plot {i+1}')\n",
546
+ " ax.set_title('Testing Data - Predicted vs Actual')\n",
547
+ " ax.set_xlabel('Time [hours]')\n",
548
+ " ax.set_ylabel('Energy Consumption [kW]') \n",
549
+ " ax.legend()\n",
550
+ "\n",
551
+ "# Adjust the spacing between subplots\n",
552
+ "plt.tight_layout()\n",
553
+ "\n",
554
+ "# Show the plot\n",
555
+ "plt.show()"
556
+ ]
557
  },
558
  {
559
  "cell_type": "code",