Spaces:
Sleeping
Sleeping
akshayballal
commited on
Commit
•
e8d4213
1
Parent(s):
10e6dfd
Refactored VAV
Browse files- physLSTM/lstm_vav_01.keras +0 -0
- physLSTM/lstm_vav_rtu1.ipynb +165 -566
- src/main.py +7 -0
- src/rtu/RTUAnomalizer.py +103 -1
- src/vav/VAVAnomalizer.py +176 -0
- src/vav/VAVPipeline.py +100 -0
- src/vav/models/kmeans_vav_1.pkl +3 -0
- src/vav/models/lstm_vav_01.keras +0 -0
- src/vav/models/scaler_vav_1.pkl +3 -0
physLSTM/lstm_vav_01.keras
ADDED
Binary file (658 kB). View file
|
|
physLSTM/lstm_vav_rtu1.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -17,7 +17,8 @@
|
|
17 |
"from sklearn.model_selection import train_test_split\n",
|
18 |
"from sklearn.preprocessing import MinMaxScaler,StandardScaler\n",
|
19 |
"from keras.callbacks import ModelCheckpoint\n",
|
20 |
-
"import tensorflow as tf"
|
|
|
21 |
]
|
22 |
},
|
23 |
{
|
@@ -31,46 +32,64 @@
|
|
31 |
},
|
32 |
{
|
33 |
"cell_type": "code",
|
34 |
-
"execution_count":
|
35 |
"metadata": {},
|
36 |
"outputs": [],
|
37 |
"source": [
|
38 |
-
"zones = [69, 68,67, 66,65, 64, 42,41,40,39,38,37,36]\n",
|
39 |
-
"
|
40 |
"cols = []\n",
|
41 |
"\n",
|
42 |
"for zone in zones:\n",
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
"\n",
|
47 |
-
"for zone in zones:\n",
|
48 |
-
" for column in merged.columns:\n",
|
49 |
-
" if f\"zone_0{zone}\" in column: \n",
|
50 |
-
" if \"cooling_sp\" in column or \"heating_sp\" in column:\n",
|
51 |
-
" cols.append(column)\n",
|
52 |
"# for rtu in rtus:\n",
|
53 |
"# for column in merged.columns:\n",
|
54 |
-
"# if f\"rtu_00{rtu}_fltrd_sa\" in column:\n",
|
55 |
"# cols.append(column)\n",
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
"input_dataset = merged[cols]"
|
62 |
]
|
63 |
},
|
64 |
{
|
65 |
"cell_type": "code",
|
66 |
-
"execution_count":
|
67 |
"metadata": {},
|
68 |
"outputs": [
|
69 |
{
|
70 |
"name": "stderr",
|
71 |
"output_type": "stream",
|
72 |
"text": [
|
73 |
-
"C:\\Users\\arbal\\AppData\\Local\\Temp\\
|
74 |
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
75 |
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
76 |
"\n",
|
@@ -96,430 +115,7 @@
|
|
96 |
},
|
97 |
{
|
98 |
"cell_type": "code",
|
99 |
-
"execution_count":
|
100 |
-
"metadata": {},
|
101 |
-
"outputs": [
|
102 |
-
{
|
103 |
-
"data": {
|
104 |
-
"text/html": [
|
105 |
-
"<div>\n",
|
106 |
-
"<style scoped>\n",
|
107 |
-
" .dataframe tbody tr th:only-of-type {\n",
|
108 |
-
" vertical-align: middle;\n",
|
109 |
-
" }\n",
|
110 |
-
"\n",
|
111 |
-
" .dataframe tbody tr th {\n",
|
112 |
-
" vertical-align: top;\n",
|
113 |
-
" }\n",
|
114 |
-
"\n",
|
115 |
-
" .dataframe thead th {\n",
|
116 |
-
" text-align: right;\n",
|
117 |
-
" }\n",
|
118 |
-
"</style>\n",
|
119 |
-
"<table border=\"1\" class=\"dataframe\">\n",
|
120 |
-
" <thead>\n",
|
121 |
-
" <tr style=\"text-align: right;\">\n",
|
122 |
-
" <th></th>\n",
|
123 |
-
" <th>date</th>\n",
|
124 |
-
" <th>zone_069_temp</th>\n",
|
125 |
-
" <th>zone_069_fan_spd</th>\n",
|
126 |
-
" <th>zone_068_temp</th>\n",
|
127 |
-
" <th>zone_068_fan_spd</th>\n",
|
128 |
-
" <th>zone_067_temp</th>\n",
|
129 |
-
" <th>zone_067_fan_spd</th>\n",
|
130 |
-
" <th>zone_066_temp</th>\n",
|
131 |
-
" <th>zone_066_fan_spd</th>\n",
|
132 |
-
" <th>zone_042_temp</th>\n",
|
133 |
-
" <th>...</th>\n",
|
134 |
-
" <th>zone_038_heating_sp</th>\n",
|
135 |
-
" <th>zone_037_cooling_sp</th>\n",
|
136 |
-
" <th>zone_037_heating_sp</th>\n",
|
137 |
-
" <th>zone_036_cooling_sp</th>\n",
|
138 |
-
" <th>zone_036_heating_sp</th>\n",
|
139 |
-
" <th>air_temp_set_1</th>\n",
|
140 |
-
" <th>air_temp_set_2</th>\n",
|
141 |
-
" <th>dew_point_temperature_set_1d</th>\n",
|
142 |
-
" <th>relative_humidity_set_1</th>\n",
|
143 |
-
" <th>solar_radiation_set_1</th>\n",
|
144 |
-
" </tr>\n",
|
145 |
-
" </thead>\n",
|
146 |
-
" <tbody>\n",
|
147 |
-
" <tr>\n",
|
148 |
-
" <th>438785</th>\n",
|
149 |
-
" <td>2019-01-08 20:55:00</td>\n",
|
150 |
-
" <td>70.9</td>\n",
|
151 |
-
" <td>NaN</td>\n",
|
152 |
-
" <td>72.4</td>\n",
|
153 |
-
" <td>20.0</td>\n",
|
154 |
-
" <td>70.2</td>\n",
|
155 |
-
" <td>NaN</td>\n",
|
156 |
-
" <td>70.9</td>\n",
|
157 |
-
" <td>NaN</td>\n",
|
158 |
-
" <td>72.3</td>\n",
|
159 |
-
" <td>...</td>\n",
|
160 |
-
" <td>72.0</td>\n",
|
161 |
-
" <td>73.0</td>\n",
|
162 |
-
" <td>70.0</td>\n",
|
163 |
-
" <td>75.0</td>\n",
|
164 |
-
" <td>72.0</td>\n",
|
165 |
-
" <td>12.850</td>\n",
|
166 |
-
" <td>12.930</td>\n",
|
167 |
-
" <td>9.10</td>\n",
|
168 |
-
" <td>78.15</td>\n",
|
169 |
-
" <td>48.7</td>\n",
|
170 |
-
" </tr>\n",
|
171 |
-
" <tr>\n",
|
172 |
-
" <th>438786</th>\n",
|
173 |
-
" <td>2019-01-08 20:56:00</td>\n",
|
174 |
-
" <td>70.9</td>\n",
|
175 |
-
" <td>NaN</td>\n",
|
176 |
-
" <td>72.4</td>\n",
|
177 |
-
" <td>20.0</td>\n",
|
178 |
-
" <td>70.2</td>\n",
|
179 |
-
" <td>NaN</td>\n",
|
180 |
-
" <td>70.9</td>\n",
|
181 |
-
" <td>NaN</td>\n",
|
182 |
-
" <td>72.3</td>\n",
|
183 |
-
" <td>...</td>\n",
|
184 |
-
" <td>72.0</td>\n",
|
185 |
-
" <td>73.0</td>\n",
|
186 |
-
" <td>70.0</td>\n",
|
187 |
-
" <td>75.0</td>\n",
|
188 |
-
" <td>72.0</td>\n",
|
189 |
-
" <td>12.850</td>\n",
|
190 |
-
" <td>12.930</td>\n",
|
191 |
-
" <td>9.10</td>\n",
|
192 |
-
" <td>78.15</td>\n",
|
193 |
-
" <td>48.7</td>\n",
|
194 |
-
" </tr>\n",
|
195 |
-
" <tr>\n",
|
196 |
-
" <th>438787</th>\n",
|
197 |
-
" <td>2019-01-08 20:57:00</td>\n",
|
198 |
-
" <td>70.9</td>\n",
|
199 |
-
" <td>NaN</td>\n",
|
200 |
-
" <td>72.4</td>\n",
|
201 |
-
" <td>20.0</td>\n",
|
202 |
-
" <td>70.2</td>\n",
|
203 |
-
" <td>NaN</td>\n",
|
204 |
-
" <td>70.9</td>\n",
|
205 |
-
" <td>NaN</td>\n",
|
206 |
-
" <td>72.3</td>\n",
|
207 |
-
" <td>...</td>\n",
|
208 |
-
" <td>72.0</td>\n",
|
209 |
-
" <td>73.0</td>\n",
|
210 |
-
" <td>70.0</td>\n",
|
211 |
-
" <td>75.0</td>\n",
|
212 |
-
" <td>72.0</td>\n",
|
213 |
-
" <td>12.850</td>\n",
|
214 |
-
" <td>12.930</td>\n",
|
215 |
-
" <td>9.10</td>\n",
|
216 |
-
" <td>78.15</td>\n",
|
217 |
-
" <td>48.7</td>\n",
|
218 |
-
" </tr>\n",
|
219 |
-
" <tr>\n",
|
220 |
-
" <th>438788</th>\n",
|
221 |
-
" <td>2019-01-08 20:58:00</td>\n",
|
222 |
-
" <td>70.9</td>\n",
|
223 |
-
" <td>NaN</td>\n",
|
224 |
-
" <td>72.4</td>\n",
|
225 |
-
" <td>20.0</td>\n",
|
226 |
-
" <td>70.2</td>\n",
|
227 |
-
" <td>NaN</td>\n",
|
228 |
-
" <td>70.9</td>\n",
|
229 |
-
" <td>NaN</td>\n",
|
230 |
-
" <td>72.3</td>\n",
|
231 |
-
" <td>...</td>\n",
|
232 |
-
" <td>72.0</td>\n",
|
233 |
-
" <td>73.0</td>\n",
|
234 |
-
" <td>70.0</td>\n",
|
235 |
-
" <td>75.0</td>\n",
|
236 |
-
" <td>72.0</td>\n",
|
237 |
-
" <td>12.850</td>\n",
|
238 |
-
" <td>12.930</td>\n",
|
239 |
-
" <td>9.10</td>\n",
|
240 |
-
" <td>78.15</td>\n",
|
241 |
-
" <td>48.7</td>\n",
|
242 |
-
" </tr>\n",
|
243 |
-
" <tr>\n",
|
244 |
-
" <th>438789</th>\n",
|
245 |
-
" <td>2019-01-08 20:59:00</td>\n",
|
246 |
-
" <td>70.9</td>\n",
|
247 |
-
" <td>NaN</td>\n",
|
248 |
-
" <td>72.4</td>\n",
|
249 |
-
" <td>20.0</td>\n",
|
250 |
-
" <td>70.2</td>\n",
|
251 |
-
" <td>NaN</td>\n",
|
252 |
-
" <td>70.9</td>\n",
|
253 |
-
" <td>NaN</td>\n",
|
254 |
-
" <td>72.3</td>\n",
|
255 |
-
" <td>...</td>\n",
|
256 |
-
" <td>72.0</td>\n",
|
257 |
-
" <td>73.0</td>\n",
|
258 |
-
" <td>70.0</td>\n",
|
259 |
-
" <td>75.0</td>\n",
|
260 |
-
" <td>72.0</td>\n",
|
261 |
-
" <td>12.850</td>\n",
|
262 |
-
" <td>12.930</td>\n",
|
263 |
-
" <td>9.10</td>\n",
|
264 |
-
" <td>78.15</td>\n",
|
265 |
-
" <td>48.7</td>\n",
|
266 |
-
" </tr>\n",
|
267 |
-
" <tr>\n",
|
268 |
-
" <th>...</th>\n",
|
269 |
-
" <td>...</td>\n",
|
270 |
-
" <td>...</td>\n",
|
271 |
-
" <td>...</td>\n",
|
272 |
-
" <td>...</td>\n",
|
273 |
-
" <td>...</td>\n",
|
274 |
-
" <td>...</td>\n",
|
275 |
-
" <td>...</td>\n",
|
276 |
-
" <td>...</td>\n",
|
277 |
-
" <td>...</td>\n",
|
278 |
-
" <td>...</td>\n",
|
279 |
-
" <td>...</td>\n",
|
280 |
-
" <td>...</td>\n",
|
281 |
-
" <td>...</td>\n",
|
282 |
-
" <td>...</td>\n",
|
283 |
-
" <td>...</td>\n",
|
284 |
-
" <td>...</td>\n",
|
285 |
-
" <td>...</td>\n",
|
286 |
-
" <td>...</td>\n",
|
287 |
-
" <td>...</td>\n",
|
288 |
-
" <td>...</td>\n",
|
289 |
-
" <td>...</td>\n",
|
290 |
-
" </tr>\n",
|
291 |
-
" <tr>\n",
|
292 |
-
" <th>2072148</th>\n",
|
293 |
-
" <td>2020-12-31 23:57:00</td>\n",
|
294 |
-
" <td>68.8</td>\n",
|
295 |
-
" <td>20.0</td>\n",
|
296 |
-
" <td>71.7</td>\n",
|
297 |
-
" <td>20.0</td>\n",
|
298 |
-
" <td>70.4</td>\n",
|
299 |
-
" <td>20.0</td>\n",
|
300 |
-
" <td>68.6</td>\n",
|
301 |
-
" <td>35.0</td>\n",
|
302 |
-
" <td>71.4</td>\n",
|
303 |
-
" <td>...</td>\n",
|
304 |
-
" <td>71.0</td>\n",
|
305 |
-
" <td>74.0</td>\n",
|
306 |
-
" <td>68.0</td>\n",
|
307 |
-
" <td>74.0</td>\n",
|
308 |
-
" <td>68.0</td>\n",
|
309 |
-
" <td>13.994</td>\n",
|
310 |
-
" <td>13.528</td>\n",
|
311 |
-
" <td>4.11</td>\n",
|
312 |
-
" <td>51.61</td>\n",
|
313 |
-
" <td>188.8</td>\n",
|
314 |
-
" </tr>\n",
|
315 |
-
" <tr>\n",
|
316 |
-
" <th>2072149</th>\n",
|
317 |
-
" <td>2020-12-31 23:58:00</td>\n",
|
318 |
-
" <td>68.8</td>\n",
|
319 |
-
" <td>20.0</td>\n",
|
320 |
-
" <td>71.7</td>\n",
|
321 |
-
" <td>20.0</td>\n",
|
322 |
-
" <td>70.4</td>\n",
|
323 |
-
" <td>20.0</td>\n",
|
324 |
-
" <td>68.6</td>\n",
|
325 |
-
" <td>35.0</td>\n",
|
326 |
-
" <td>71.4</td>\n",
|
327 |
-
" <td>...</td>\n",
|
328 |
-
" <td>71.0</td>\n",
|
329 |
-
" <td>74.0</td>\n",
|
330 |
-
" <td>68.0</td>\n",
|
331 |
-
" <td>74.0</td>\n",
|
332 |
-
" <td>68.0</td>\n",
|
333 |
-
" <td>13.994</td>\n",
|
334 |
-
" <td>13.528</td>\n",
|
335 |
-
" <td>4.11</td>\n",
|
336 |
-
" <td>51.61</td>\n",
|
337 |
-
" <td>188.8</td>\n",
|
338 |
-
" </tr>\n",
|
339 |
-
" <tr>\n",
|
340 |
-
" <th>2072150</th>\n",
|
341 |
-
" <td>2020-12-31 23:58:00</td>\n",
|
342 |
-
" <td>68.8</td>\n",
|
343 |
-
" <td>20.0</td>\n",
|
344 |
-
" <td>71.7</td>\n",
|
345 |
-
" <td>20.0</td>\n",
|
346 |
-
" <td>70.4</td>\n",
|
347 |
-
" <td>20.0</td>\n",
|
348 |
-
" <td>68.6</td>\n",
|
349 |
-
" <td>35.0</td>\n",
|
350 |
-
" <td>71.4</td>\n",
|
351 |
-
" <td>...</td>\n",
|
352 |
-
" <td>71.0</td>\n",
|
353 |
-
" <td>74.0</td>\n",
|
354 |
-
" <td>68.0</td>\n",
|
355 |
-
" <td>74.0</td>\n",
|
356 |
-
" <td>68.0</td>\n",
|
357 |
-
" <td>13.994</td>\n",
|
358 |
-
" <td>13.528</td>\n",
|
359 |
-
" <td>4.11</td>\n",
|
360 |
-
" <td>51.61</td>\n",
|
361 |
-
" <td>188.8</td>\n",
|
362 |
-
" </tr>\n",
|
363 |
-
" <tr>\n",
|
364 |
-
" <th>2072151</th>\n",
|
365 |
-
" <td>2020-12-31 23:59:00</td>\n",
|
366 |
-
" <td>68.8</td>\n",
|
367 |
-
" <td>20.0</td>\n",
|
368 |
-
" <td>71.7</td>\n",
|
369 |
-
" <td>20.0</td>\n",
|
370 |
-
" <td>70.4</td>\n",
|
371 |
-
" <td>20.0</td>\n",
|
372 |
-
" <td>68.6</td>\n",
|
373 |
-
" <td>35.0</td>\n",
|
374 |
-
" <td>71.4</td>\n",
|
375 |
-
" <td>...</td>\n",
|
376 |
-
" <td>71.0</td>\n",
|
377 |
-
" <td>74.0</td>\n",
|
378 |
-
" <td>68.0</td>\n",
|
379 |
-
" <td>74.0</td>\n",
|
380 |
-
" <td>68.0</td>\n",
|
381 |
-
" <td>13.994</td>\n",
|
382 |
-
" <td>13.528</td>\n",
|
383 |
-
" <td>4.11</td>\n",
|
384 |
-
" <td>51.61</td>\n",
|
385 |
-
" <td>188.8</td>\n",
|
386 |
-
" </tr>\n",
|
387 |
-
" <tr>\n",
|
388 |
-
" <th>2072152</th>\n",
|
389 |
-
" <td>2020-12-31 23:59:00</td>\n",
|
390 |
-
" <td>68.8</td>\n",
|
391 |
-
" <td>20.0</td>\n",
|
392 |
-
" <td>71.7</td>\n",
|
393 |
-
" <td>20.0</td>\n",
|
394 |
-
" <td>70.4</td>\n",
|
395 |
-
" <td>20.0</td>\n",
|
396 |
-
" <td>68.6</td>\n",
|
397 |
-
" <td>35.0</td>\n",
|
398 |
-
" <td>71.4</td>\n",
|
399 |
-
" <td>...</td>\n",
|
400 |
-
" <td>71.0</td>\n",
|
401 |
-
" <td>74.0</td>\n",
|
402 |
-
" <td>68.0</td>\n",
|
403 |
-
" <td>74.0</td>\n",
|
404 |
-
" <td>68.0</td>\n",
|
405 |
-
" <td>13.994</td>\n",
|
406 |
-
" <td>13.528</td>\n",
|
407 |
-
" <td>4.11</td>\n",
|
408 |
-
" <td>51.61</td>\n",
|
409 |
-
" <td>188.8</td>\n",
|
410 |
-
" </tr>\n",
|
411 |
-
" </tbody>\n",
|
412 |
-
"</table>\n",
|
413 |
-
"<p>1633368 rows × 46 columns</p>\n",
|
414 |
-
"</div>"
|
415 |
-
],
|
416 |
-
"text/plain": [
|
417 |
-
" date zone_069_temp zone_069_fan_spd zone_068_temp \\\n",
|
418 |
-
"438785 2019-01-08 20:55:00 70.9 NaN 72.4 \n",
|
419 |
-
"438786 2019-01-08 20:56:00 70.9 NaN 72.4 \n",
|
420 |
-
"438787 2019-01-08 20:57:00 70.9 NaN 72.4 \n",
|
421 |
-
"438788 2019-01-08 20:58:00 70.9 NaN 72.4 \n",
|
422 |
-
"438789 2019-01-08 20:59:00 70.9 NaN 72.4 \n",
|
423 |
-
"... ... ... ... ... \n",
|
424 |
-
"2072148 2020-12-31 23:57:00 68.8 20.0 71.7 \n",
|
425 |
-
"2072149 2020-12-31 23:58:00 68.8 20.0 71.7 \n",
|
426 |
-
"2072150 2020-12-31 23:58:00 68.8 20.0 71.7 \n",
|
427 |
-
"2072151 2020-12-31 23:59:00 68.8 20.0 71.7 \n",
|
428 |
-
"2072152 2020-12-31 23:59:00 68.8 20.0 71.7 \n",
|
429 |
-
"\n",
|
430 |
-
" zone_068_fan_spd zone_067_temp zone_067_fan_spd zone_066_temp \\\n",
|
431 |
-
"438785 20.0 70.2 NaN 70.9 \n",
|
432 |
-
"438786 20.0 70.2 NaN 70.9 \n",
|
433 |
-
"438787 20.0 70.2 NaN 70.9 \n",
|
434 |
-
"438788 20.0 70.2 NaN 70.9 \n",
|
435 |
-
"438789 20.0 70.2 NaN 70.9 \n",
|
436 |
-
"... ... ... ... ... \n",
|
437 |
-
"2072148 20.0 70.4 20.0 68.6 \n",
|
438 |
-
"2072149 20.0 70.4 20.0 68.6 \n",
|
439 |
-
"2072150 20.0 70.4 20.0 68.6 \n",
|
440 |
-
"2072151 20.0 70.4 20.0 68.6 \n",
|
441 |
-
"2072152 20.0 70.4 20.0 68.6 \n",
|
442 |
-
"\n",
|
443 |
-
" zone_066_fan_spd zone_042_temp ... zone_038_heating_sp \\\n",
|
444 |
-
"438785 NaN 72.3 ... 72.0 \n",
|
445 |
-
"438786 NaN 72.3 ... 72.0 \n",
|
446 |
-
"438787 NaN 72.3 ... 72.0 \n",
|
447 |
-
"438788 NaN 72.3 ... 72.0 \n",
|
448 |
-
"438789 NaN 72.3 ... 72.0 \n",
|
449 |
-
"... ... ... ... ... \n",
|
450 |
-
"2072148 35.0 71.4 ... 71.0 \n",
|
451 |
-
"2072149 35.0 71.4 ... 71.0 \n",
|
452 |
-
"2072150 35.0 71.4 ... 71.0 \n",
|
453 |
-
"2072151 35.0 71.4 ... 71.0 \n",
|
454 |
-
"2072152 35.0 71.4 ... 71.0 \n",
|
455 |
-
"\n",
|
456 |
-
" zone_037_cooling_sp zone_037_heating_sp zone_036_cooling_sp \\\n",
|
457 |
-
"438785 73.0 70.0 75.0 \n",
|
458 |
-
"438786 73.0 70.0 75.0 \n",
|
459 |
-
"438787 73.0 70.0 75.0 \n",
|
460 |
-
"438788 73.0 70.0 75.0 \n",
|
461 |
-
"438789 73.0 70.0 75.0 \n",
|
462 |
-
"... ... ... ... \n",
|
463 |
-
"2072148 74.0 68.0 74.0 \n",
|
464 |
-
"2072149 74.0 68.0 74.0 \n",
|
465 |
-
"2072150 74.0 68.0 74.0 \n",
|
466 |
-
"2072151 74.0 68.0 74.0 \n",
|
467 |
-
"2072152 74.0 68.0 74.0 \n",
|
468 |
-
"\n",
|
469 |
-
" zone_036_heating_sp air_temp_set_1 air_temp_set_2 \\\n",
|
470 |
-
"438785 72.0 12.850 12.930 \n",
|
471 |
-
"438786 72.0 12.850 12.930 \n",
|
472 |
-
"438787 72.0 12.850 12.930 \n",
|
473 |
-
"438788 72.0 12.850 12.930 \n",
|
474 |
-
"438789 72.0 12.850 12.930 \n",
|
475 |
-
"... ... ... ... \n",
|
476 |
-
"2072148 68.0 13.994 13.528 \n",
|
477 |
-
"2072149 68.0 13.994 13.528 \n",
|
478 |
-
"2072150 68.0 13.994 13.528 \n",
|
479 |
-
"2072151 68.0 13.994 13.528 \n",
|
480 |
-
"2072152 68.0 13.994 13.528 \n",
|
481 |
-
"\n",
|
482 |
-
" dew_point_temperature_set_1d relative_humidity_set_1 \\\n",
|
483 |
-
"438785 9.10 78.15 \n",
|
484 |
-
"438786 9.10 78.15 \n",
|
485 |
-
"438787 9.10 78.15 \n",
|
486 |
-
"438788 9.10 78.15 \n",
|
487 |
-
"438789 9.10 78.15 \n",
|
488 |
-
"... ... ... \n",
|
489 |
-
"2072148 4.11 51.61 \n",
|
490 |
-
"2072149 4.11 51.61 \n",
|
491 |
-
"2072150 4.11 51.61 \n",
|
492 |
-
"2072151 4.11 51.61 \n",
|
493 |
-
"2072152 4.11 51.61 \n",
|
494 |
-
"\n",
|
495 |
-
" solar_radiation_set_1 \n",
|
496 |
-
"438785 48.7 \n",
|
497 |
-
"438786 48.7 \n",
|
498 |
-
"438787 48.7 \n",
|
499 |
-
"438788 48.7 \n",
|
500 |
-
"438789 48.7 \n",
|
501 |
-
"... ... \n",
|
502 |
-
"2072148 188.8 \n",
|
503 |
-
"2072149 188.8 \n",
|
504 |
-
"2072150 188.8 \n",
|
505 |
-
"2072151 188.8 \n",
|
506 |
-
"2072152 188.8 \n",
|
507 |
-
"\n",
|
508 |
-
"[1633368 rows x 46 columns]"
|
509 |
-
]
|
510 |
-
},
|
511 |
-
"execution_count": 5,
|
512 |
-
"metadata": {},
|
513 |
-
"output_type": "execute_result"
|
514 |
-
}
|
515 |
-
],
|
516 |
-
"source": [
|
517 |
-
"df_filtered"
|
518 |
-
]
|
519 |
-
},
|
520 |
-
{
|
521 |
-
"cell_type": "code",
|
522 |
-
"execution_count": 6,
|
523 |
"metadata": {},
|
524 |
"outputs": [
|
525 |
{
|
@@ -528,7 +124,7 @@
|
|
528 |
"[]"
|
529 |
]
|
530 |
},
|
531 |
-
"execution_count":
|
532 |
"metadata": {},
|
533 |
"output_type": "execute_result"
|
534 |
}
|
@@ -548,7 +144,7 @@
|
|
548 |
},
|
549 |
{
|
550 |
"cell_type": "code",
|
551 |
-
"execution_count":
|
552 |
"metadata": {},
|
553 |
"outputs": [
|
554 |
{
|
@@ -565,7 +161,7 @@
|
|
565 |
},
|
566 |
{
|
567 |
"cell_type": "code",
|
568 |
-
"execution_count":
|
569 |
"metadata": {},
|
570 |
"outputs": [
|
571 |
{
|
@@ -574,7 +170,7 @@
|
|
574 |
"(1073512, 391818)"
|
575 |
]
|
576 |
},
|
577 |
-
"execution_count":
|
578 |
"metadata": {},
|
579 |
"output_type": "execute_result"
|
580 |
}
|
@@ -585,41 +181,34 @@
|
|
585 |
},
|
586 |
{
|
587 |
"cell_type": "code",
|
588 |
-
"execution_count":
|
589 |
-
"metadata": {},
|
590 |
-
"outputs": [],
|
591 |
-
"source": [
|
592 |
-
"traindataset = traindataset.astype('float32')\n",
|
593 |
-
"testdataset = testdataset.astype('float32')\n",
|
594 |
-
"\n",
|
595 |
-
"scaler = StandardScaler()\n",
|
596 |
-
"traindataset = scaler.fit_transform(traindataset)\n",
|
597 |
-
"testdataset = scaler.transform(testdataset)"
|
598 |
-
]
|
599 |
-
},
|
600 |
-
{
|
601 |
-
"cell_type": "code",
|
602 |
-
"execution_count": 10,
|
603 |
"metadata": {},
|
604 |
"outputs": [
|
605 |
{
|
606 |
"data": {
|
607 |
"text/plain": [
|
608 |
-
"
|
609 |
]
|
610 |
},
|
611 |
-
"execution_count":
|
612 |
"metadata": {},
|
613 |
"output_type": "execute_result"
|
614 |
}
|
615 |
],
|
616 |
"source": [
|
617 |
-
"traindataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
618 |
]
|
619 |
},
|
620 |
{
|
621 |
"cell_type": "code",
|
622 |
-
"execution_count":
|
623 |
"metadata": {},
|
624 |
"outputs": [],
|
625 |
"source": [
|
@@ -630,7 +219,7 @@
|
|
630 |
" Y = []\n",
|
631 |
" for i in range(len(dataset) - time_step - 1):\n",
|
632 |
" x.append(dataset[i:(i+time_step),:])\n",
|
633 |
-
" Y.append(dataset[i+time_step,0:
|
634 |
" x= np.array(x)\n",
|
635 |
" Y = np.array(Y)\n",
|
636 |
" return x,Y\n",
|
@@ -642,16 +231,16 @@
|
|
642 |
},
|
643 |
{
|
644 |
"cell_type": "code",
|
645 |
-
"execution_count":
|
646 |
"metadata": {},
|
647 |
"outputs": [
|
648 |
{
|
649 |
"data": {
|
650 |
"text/plain": [
|
651 |
-
"((1073481, 30,
|
652 |
]
|
653 |
},
|
654 |
-
"execution_count":
|
655 |
"metadata": {},
|
656 |
"output_type": "execute_result"
|
657 |
}
|
@@ -662,51 +251,19 @@
|
|
662 |
},
|
663 |
{
|
664 |
"cell_type": "code",
|
665 |
-
"execution_count":
|
666 |
"metadata": {},
|
667 |
"outputs": [
|
668 |
{
|
669 |
"name": "stdout",
|
670 |
"output_type": "stream",
|
671 |
"text": [
|
672 |
-
"Epoch 1/
|
673 |
-
"
|
674 |
-
"Epoch 1: val_loss improved from inf to 0.
|
675 |
-
"
|
676 |
-
|
677 |
-
|
678 |
-
{
|
679 |
-
"name": "stderr",
|
680 |
-
"output_type": "stream",
|
681 |
-
"text": [
|
682 |
-
"INFO:tensorflow:Assets written to: lstm_vav_01.tf\\assets\n"
|
683 |
-
]
|
684 |
-
},
|
685 |
-
{
|
686 |
-
"name": "stdout",
|
687 |
-
"output_type": "stream",
|
688 |
-
"text": [
|
689 |
-
"8387/8387 [==============================] - 307s 36ms/step - loss: 0.0178 - val_loss: 0.4231\n",
|
690 |
-
"Epoch 2/5\n",
|
691 |
-
"8387/8387 [==============================] - ETA: 0s - loss: 0.0032\n",
|
692 |
-
"Epoch 2: val_loss improved from 0.42313 to 0.40364, saving model to lstm_vav_01.tf\n",
|
693 |
-
"INFO:tensorflow:Assets written to: lstm_vav_01.tf\\assets\n"
|
694 |
-
]
|
695 |
-
},
|
696 |
-
{
|
697 |
-
"name": "stderr",
|
698 |
-
"output_type": "stream",
|
699 |
-
"text": [
|
700 |
-
"INFO:tensorflow:Assets written to: lstm_vav_01.tf\\assets\n"
|
701 |
-
]
|
702 |
-
},
|
703 |
-
{
|
704 |
-
"name": "stdout",
|
705 |
-
"output_type": "stream",
|
706 |
-
"text": [
|
707 |
-
"8387/8387 [==============================] - 274s 33ms/step - loss: 0.0032 - val_loss: 0.4036\n",
|
708 |
-
"Epoch 3/5\n",
|
709 |
-
" 259/8387 [..............................] - ETA: 4:02 - loss: 0.0028"
|
710 |
]
|
711 |
},
|
712 |
{
|
@@ -716,17 +273,18 @@
|
|
716 |
"traceback": [
|
717 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
718 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
719 |
-
"Cell \u001b[1;32mIn[
|
720 |
-
"File \u001b[1;32md:\\
|
721 |
-
"File \u001b[1;32md:\\
|
722 |
-
"File \u001b[1;32md:\\
|
723 |
-
"File \u001b[1;32md:\\
|
724 |
-
"File \u001b[1;32md:\\
|
725 |
-
"File \u001b[1;32md:\\
|
726 |
-
"File \u001b[1;32md:\\
|
727 |
-
"File \u001b[1;32md:\\
|
728 |
-
"File \u001b[1;32md:\\
|
729 |
-
"File \u001b[1;32md:\\
|
|
|
730 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
731 |
]
|
732 |
}
|
@@ -741,41 +299,30 @@
|
|
741 |
"\n",
|
742 |
"model.compile(optimizer='adam', loss='mean_squared_error')\n",
|
743 |
"\n",
|
744 |
-
"checkpoint_path = \"lstm_vav_01.
|
745 |
"checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
|
746 |
-
"model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=
|
747 |
]
|
748 |
},
|
749 |
{
|
750 |
"cell_type": "code",
|
751 |
-
"execution_count":
|
752 |
"metadata": {},
|
753 |
-
"outputs": [
|
754 |
-
{
|
755 |
-
"data": {
|
756 |
-
"text/plain": [
|
757 |
-
"<tensorflow.python.checkpoint.checkpoint.CheckpointLoadStatus at 0x2a4b2344610>"
|
758 |
-
]
|
759 |
-
},
|
760 |
-
"execution_count": 14,
|
761 |
-
"metadata": {},
|
762 |
-
"output_type": "execute_result"
|
763 |
-
}
|
764 |
-
],
|
765 |
"source": [
|
766 |
"model.load_weights(checkpoint_path)"
|
767 |
]
|
768 |
},
|
769 |
{
|
770 |
"cell_type": "code",
|
771 |
-
"execution_count":
|
772 |
"metadata": {},
|
773 |
"outputs": [
|
774 |
{
|
775 |
"name": "stdout",
|
776 |
"output_type": "stream",
|
777 |
"text": [
|
778 |
-
"
|
779 |
]
|
780 |
}
|
781 |
],
|
@@ -785,52 +332,91 @@
|
|
785 |
},
|
786 |
{
|
787 |
"cell_type": "code",
|
788 |
-
"execution_count":
|
789 |
"metadata": {},
|
790 |
"outputs": [
|
791 |
{
|
792 |
"data": {
|
793 |
"text/plain": [
|
794 |
-
"
|
795 |
-
"
|
796 |
-
"
|
797 |
-
"
|
798 |
-
"
|
799 |
-
"
|
800 |
-
"
|
801 |
-
"
|
802 |
-
"
|
803 |
-
"
|
804 |
-
"
|
805 |
-
"
|
806 |
-
"
|
807 |
-
"
|
808 |
-
"
|
809 |
-
"
|
810 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
811 |
]
|
812 |
},
|
813 |
-
"execution_count":
|
814 |
"metadata": {},
|
815 |
"output_type": "execute_result"
|
816 |
}
|
817 |
],
|
818 |
"source": [
|
819 |
-
"traindataset_df.columns"
|
|
|
820 |
]
|
821 |
},
|
822 |
{
|
823 |
"cell_type": "code",
|
824 |
-
"execution_count":
|
825 |
"metadata": {},
|
826 |
"outputs": [],
|
827 |
"source": [
|
828 |
"%matplotlib qt\n",
|
829 |
"plt.figure()\n",
|
830 |
-
"var =
|
831 |
"plt.plot(y_test[:,var], label='Original Testing Data', color='blue')\n",
|
832 |
"plt.plot(test_predict1[:,var], label='Predicted Testing Data', color='red',alpha=0.8)\n",
|
833 |
-
"anomalies = np.where(abs(test_predict1[:,var] - y_test[:,var]) > 0.
|
834 |
"plt.scatter(anomalies,test_predict1[anomalies,var], color='black',marker =\"o\",s=100 )\n",
|
835 |
"\n",
|
836 |
"\n",
|
@@ -881,9 +467,20 @@
|
|
881 |
},
|
882 |
{
|
883 |
"cell_type": "code",
|
884 |
-
"execution_count":
|
885 |
"metadata": {},
|
886 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
887 |
"source": [
|
888 |
"from sklearn.cluster import KMeans\n",
|
889 |
"import numpy as np\n",
|
@@ -894,7 +491,7 @@
|
|
894 |
"np.random.seed(0)\n",
|
895 |
"X = (test_predict1 - y_test)\n",
|
896 |
"\n",
|
897 |
-
"k =
|
898 |
"\n",
|
899 |
"kmeans = KMeans(n_clusters=k)\n",
|
900 |
"\n",
|
@@ -917,7 +514,9 @@
|
|
917 |
"plt.title('KMeans Clustering')\n",
|
918 |
"plt.xlabel('Feature 1')\n",
|
919 |
"plt.ylabel('Feature 2')\n",
|
920 |
-
"plt.show()\n"
|
|
|
|
|
921 |
]
|
922 |
},
|
923 |
{
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 35,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
17 |
"from sklearn.model_selection import train_test_split\n",
|
18 |
"from sklearn.preprocessing import MinMaxScaler,StandardScaler\n",
|
19 |
"from keras.callbacks import ModelCheckpoint\n",
|
20 |
+
"import tensorflow as tf\n",
|
21 |
+
"import joblib"
|
22 |
]
|
23 |
},
|
24 |
{
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": 31,
|
36 |
"metadata": {},
|
37 |
"outputs": [],
|
38 |
"source": [
|
39 |
+
"zones = [69, 68, 67, 66, 65, 64, 42, 41, 40, 39, 38, 37, 36]\n",
|
40 |
+
"rtu = 1\n",
|
41 |
"cols = []\n",
|
42 |
"\n",
|
43 |
"for zone in zones:\n",
|
44 |
+
" for column in merged.columns:\n",
|
45 |
+
" if (\n",
|
46 |
+
" f\"zone_0{zone}\" in column\n",
|
47 |
+
" and \"co2\" not in column\n",
|
48 |
+
" and \"hw_valve\" not in column\n",
|
49 |
+
" and \"cooling_sp\" not in column\n",
|
50 |
+
" and \"heating_sp\" not in column\n",
|
51 |
+
" ):\n",
|
52 |
+
" cols.append(column)\n",
|
53 |
+
"\n",
|
54 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
55 |
"# for rtu in rtus:\n",
|
56 |
"# for column in merged.columns:\n",
|
57 |
+
"# if f\"rtu_00{rtu}_fltrd_sa\" or f\"rtu_00{rtu}_sa_temp\" in column:\n",
|
58 |
"# cols.append(column)\n",
|
59 |
+
"\n",
|
60 |
+
"cols = (\n",
|
61 |
+
" [\"date\"]\n",
|
62 |
+
" + cols\n",
|
63 |
+
" + [\n",
|
64 |
+
" f\"rtu_00{rtu}_fltrd_sa_flow_tn\",\n",
|
65 |
+
" f\"rtu_00{rtu}_sa_temp\", \n",
|
66 |
+
" \"air_temp_set_1\",\n",
|
67 |
+
" \"air_temp_set_2\",\n",
|
68 |
+
" \"dew_point_temperature_set_1d\",\n",
|
69 |
+
" \"relative_humidity_set_1\",\n",
|
70 |
+
" \"solar_radiation_set_1\",\n",
|
71 |
+
" ]\n",
|
72 |
+
")\n",
|
73 |
+
"\n",
|
74 |
+
"for zone in zones:\n",
|
75 |
+
" for column in merged.columns:\n",
|
76 |
+
" if f\"zone_0{zone}\" in column:\n",
|
77 |
+
" if \"cooling_sp\" in column or \"heating_sp\" in column:\n",
|
78 |
+
" cols.append(column)\n",
|
79 |
+
" \n",
|
80 |
"input_dataset = merged[cols]"
|
81 |
]
|
82 |
},
|
83 |
{
|
84 |
"cell_type": "code",
|
85 |
+
"execution_count": 32,
|
86 |
"metadata": {},
|
87 |
"outputs": [
|
88 |
{
|
89 |
"name": "stderr",
|
90 |
"output_type": "stream",
|
91 |
"text": [
|
92 |
+
"C:\\Users\\arbal\\AppData\\Local\\Temp\\ipykernel_29192\\4293840618.py:1: SettingWithCopyWarning: \n",
|
93 |
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
94 |
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
95 |
"\n",
|
|
|
115 |
},
|
116 |
{
|
117 |
"cell_type": "code",
|
118 |
+
"execution_count": 36,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
"metadata": {},
|
120 |
"outputs": [
|
121 |
{
|
|
|
124 |
"[]"
|
125 |
]
|
126 |
},
|
127 |
+
"execution_count": 36,
|
128 |
"metadata": {},
|
129 |
"output_type": "execute_result"
|
130 |
}
|
|
|
144 |
},
|
145 |
{
|
146 |
"cell_type": "code",
|
147 |
+
"execution_count": 37,
|
148 |
"metadata": {},
|
149 |
"outputs": [
|
150 |
{
|
|
|
161 |
},
|
162 |
{
|
163 |
"cell_type": "code",
|
164 |
+
"execution_count": 38,
|
165 |
"metadata": {},
|
166 |
"outputs": [
|
167 |
{
|
|
|
170 |
"(1073512, 391818)"
|
171 |
]
|
172 |
},
|
173 |
+
"execution_count": 38,
|
174 |
"metadata": {},
|
175 |
"output_type": "execute_result"
|
176 |
}
|
|
|
181 |
},
|
182 |
{
|
183 |
"cell_type": "code",
|
184 |
+
"execution_count": 39,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
"metadata": {},
|
186 |
"outputs": [
|
187 |
{
|
188 |
"data": {
|
189 |
"text/plain": [
|
190 |
+
"['scaler_vav_1.pkl']"
|
191 |
]
|
192 |
},
|
193 |
+
"execution_count": 39,
|
194 |
"metadata": {},
|
195 |
"output_type": "execute_result"
|
196 |
}
|
197 |
],
|
198 |
"source": [
|
199 |
+
"traindataset = traindataset.astype('float32')\n",
|
200 |
+
"testdataset = testdataset.astype('float32')\n",
|
201 |
+
"\n",
|
202 |
+
"scaler = StandardScaler()\n",
|
203 |
+
"traindataset = scaler.fit_transform(traindataset)\n",
|
204 |
+
"testdataset = scaler.transform(testdataset)\n",
|
205 |
+
"\n",
|
206 |
+
"joblib.dump(scaler, 'scaler_vav_1.pkl')"
|
207 |
]
|
208 |
},
|
209 |
{
|
210 |
"cell_type": "code",
|
211 |
+
"execution_count": 51,
|
212 |
"metadata": {},
|
213 |
"outputs": [],
|
214 |
"source": [
|
|
|
219 |
" Y = []\n",
|
220 |
" for i in range(len(dataset) - time_step - 1):\n",
|
221 |
" x.append(dataset[i:(i+time_step),:])\n",
|
222 |
+
" Y.append(dataset[i+time_step,0:26])\n",
|
223 |
" x= np.array(x)\n",
|
224 |
" Y = np.array(Y)\n",
|
225 |
" return x,Y\n",
|
|
|
231 |
},
|
232 |
{
|
233 |
"cell_type": "code",
|
234 |
+
"execution_count": 52,
|
235 |
"metadata": {},
|
236 |
"outputs": [
|
237 |
{
|
238 |
"data": {
|
239 |
"text/plain": [
|
240 |
+
"((1073481, 30, 55), (1073481, 26))"
|
241 |
]
|
242 |
},
|
243 |
+
"execution_count": 52,
|
244 |
"metadata": {},
|
245 |
"output_type": "execute_result"
|
246 |
}
|
|
|
251 |
},
|
252 |
{
|
253 |
"cell_type": "code",
|
254 |
+
"execution_count": 54,
|
255 |
"metadata": {},
|
256 |
"outputs": [
|
257 |
{
|
258 |
"name": "stdout",
|
259 |
"output_type": "stream",
|
260 |
"text": [
|
261 |
+
"Epoch 1/3\n",
|
262 |
+
"\u001b[1m8387/8387\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 58ms/step - loss: 0.0696\n",
|
263 |
+
"Epoch 1: val_loss improved from inf to 0.65445, saving model to lstm_vav_01.keras\n",
|
264 |
+
"\u001b[1m8387/8387\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m589s\u001b[0m 69ms/step - loss: 0.0696 - val_loss: 0.6544\n",
|
265 |
+
"Epoch 2/3\n",
|
266 |
+
"\u001b[1m 449/8387\u001b[0m \u001b[32m━\u001b[0m\u001b[37m━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[1m7:16\u001b[0m 55ms/step - loss: 0.0033"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
]
|
268 |
},
|
269 |
{
|
|
|
273 |
"traceback": [
|
274 |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
275 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
276 |
+
"Cell \u001b[1;32mIn[54], line 11\u001b[0m\n\u001b[0;32m 9\u001b[0m checkpoint_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlstm_vav_01.keras\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 10\u001b[0m checkpoint_callback \u001b[38;5;241m=\u001b[39m ModelCheckpoint(filepath\u001b[38;5;241m=\u001b[39mcheckpoint_path, monitor\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mval_loss\u001b[39m\u001b[38;5;124m'\u001b[39m, verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m, save_best_only\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmin\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX_train\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my_train\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalidation_data\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mX_test\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my_test\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mepochs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbatch_size\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m128\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mcheckpoint_callback\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
|
277 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\keras\\src\\utils\\traceback_utils.py:117\u001b[0m, in \u001b[0;36mfilter_traceback.<locals>.error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 115\u001b[0m filtered_tb \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 116\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 117\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 119\u001b[0m filtered_tb \u001b[38;5;241m=\u001b[39m _process_traceback_frames(e\u001b[38;5;241m.\u001b[39m__traceback__)\n",
|
278 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\keras\\src\\backend\\tensorflow\\trainer.py:314\u001b[0m, in \u001b[0;36mTensorFlowTrainer.fit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq)\u001b[0m\n\u001b[0;32m 312\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m step, iterator \u001b[38;5;129;01min\u001b[39;00m epoch_iterator\u001b[38;5;241m.\u001b[39menumerate_epoch():\n\u001b[0;32m 313\u001b[0m callbacks\u001b[38;5;241m.\u001b[39mon_train_batch_begin(step)\n\u001b[1;32m--> 314\u001b[0m logs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrain_function\u001b[49m\u001b[43m(\u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 315\u001b[0m logs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_pythonify_logs(logs)\n\u001b[0;32m 316\u001b[0m callbacks\u001b[38;5;241m.\u001b[39mon_train_batch_end(step, logs)\n",
|
279 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\util\\traceback_utils.py:150\u001b[0m, in \u001b[0;36mfilter_traceback.<locals>.error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 148\u001b[0m filtered_tb \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 149\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 150\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 151\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 152\u001b[0m filtered_tb \u001b[38;5;241m=\u001b[39m _process_traceback_frames(e\u001b[38;5;241m.\u001b[39m__traceback__)\n",
|
280 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\polymorphic_function.py:833\u001b[0m, in \u001b[0;36mFunction.__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 830\u001b[0m compiler \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxla\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_jit_compile \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnonXla\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 832\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m OptionalXlaContext(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_jit_compile):\n\u001b[1;32m--> 833\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 835\u001b[0m new_tracing_count \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mexperimental_get_tracing_count()\n\u001b[0;32m 836\u001b[0m without_tracing \u001b[38;5;241m=\u001b[39m (tracing_count \u001b[38;5;241m==\u001b[39m new_tracing_count)\n",
|
281 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\polymorphic_function.py:878\u001b[0m, in \u001b[0;36mFunction._call\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 875\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lock\u001b[38;5;241m.\u001b[39mrelease()\n\u001b[0;32m 876\u001b[0m \u001b[38;5;66;03m# In this case we have not created variables on the first call. So we can\u001b[39;00m\n\u001b[0;32m 877\u001b[0m \u001b[38;5;66;03m# run the first trace but we should fail if variables are created.\u001b[39;00m\n\u001b[1;32m--> 878\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[43mtracing_compilation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 879\u001b[0m \u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwds\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_variable_creation_config\u001b[49m\n\u001b[0;32m 880\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 881\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_created_variables:\n\u001b[0;32m 882\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCreating variables on a non-first call to a function\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 883\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m decorated with tf.function.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
282 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\tracing_compilation.py:139\u001b[0m, in \u001b[0;36mcall_function\u001b[1;34m(args, kwargs, tracing_options)\u001b[0m\n\u001b[0;32m 137\u001b[0m bound_args \u001b[38;5;241m=\u001b[39m function\u001b[38;5;241m.\u001b[39mfunction_type\u001b[38;5;241m.\u001b[39mbind(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 138\u001b[0m flat_inputs \u001b[38;5;241m=\u001b[39m function\u001b[38;5;241m.\u001b[39mfunction_type\u001b[38;5;241m.\u001b[39munpack_inputs(bound_args)\n\u001b[1;32m--> 139\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunction\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_flat\u001b[49m\u001b[43m(\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# pylint: disable=protected-access\u001b[39;49;00m\n\u001b[0;32m 140\u001b[0m \u001b[43m \u001b[49m\u001b[43mflat_inputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcaptured_inputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfunction\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcaptured_inputs\u001b[49m\n\u001b[0;32m 141\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
|
283 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\concrete_function.py:1322\u001b[0m, in \u001b[0;36mConcreteFunction._call_flat\u001b[1;34m(self, tensor_inputs, captured_inputs)\u001b[0m\n\u001b[0;32m 1318\u001b[0m possible_gradient_type \u001b[38;5;241m=\u001b[39m gradients_util\u001b[38;5;241m.\u001b[39mPossibleTapeGradientTypes(args)\n\u001b[0;32m 1319\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (possible_gradient_type \u001b[38;5;241m==\u001b[39m gradients_util\u001b[38;5;241m.\u001b[39mPOSSIBLE_GRADIENT_TYPES_NONE\n\u001b[0;32m 1320\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m executing_eagerly):\n\u001b[0;32m 1321\u001b[0m \u001b[38;5;66;03m# No tape is watching; skip to running the function.\u001b[39;00m\n\u001b[1;32m-> 1322\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_inference_function\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_preflattened\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1323\u001b[0m forward_backward \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_select_forward_and_backward_functions(\n\u001b[0;32m 1324\u001b[0m args,\n\u001b[0;32m 1325\u001b[0m possible_gradient_type,\n\u001b[0;32m 1326\u001b[0m executing_eagerly)\n\u001b[0;32m 1327\u001b[0m forward_function, args_with_tangents \u001b[38;5;241m=\u001b[39m forward_backward\u001b[38;5;241m.\u001b[39mforward()\n",
|
284 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\atomic_function.py:216\u001b[0m, in \u001b[0;36mAtomicFunction.call_preflattened\u001b[1;34m(self, args)\u001b[0m\n\u001b[0;32m 214\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcall_preflattened\u001b[39m(\u001b[38;5;28mself\u001b[39m, args: Sequence[core\u001b[38;5;241m.\u001b[39mTensor]) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Any:\n\u001b[0;32m 215\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Calls with flattened tensor inputs and returns the structured output.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 216\u001b[0m flat_outputs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_flat\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 217\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfunction_type\u001b[38;5;241m.\u001b[39mpack_output(flat_outputs)\n",
|
285 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\polymorphic_function\\atomic_function.py:251\u001b[0m, in \u001b[0;36mAtomicFunction.call_flat\u001b[1;34m(self, *args)\u001b[0m\n\u001b[0;32m 249\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m record\u001b[38;5;241m.\u001b[39mstop_recording():\n\u001b[0;32m 250\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_bound_context\u001b[38;5;241m.\u001b[39mexecuting_eagerly():\n\u001b[1;32m--> 251\u001b[0m outputs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_bound_context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 252\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 253\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 254\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfunction_type\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mflat_outputs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 255\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 256\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 257\u001b[0m outputs \u001b[38;5;241m=\u001b[39m make_call_op_in_graph(\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 259\u001b[0m \u001b[38;5;28mlist\u001b[39m(args),\n\u001b[0;32m 260\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_bound_context\u001b[38;5;241m.\u001b[39mfunction_call_options\u001b[38;5;241m.\u001b[39mas_attrs(),\n\u001b[0;32m 261\u001b[0m )\n",
|
286 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\context.py:1500\u001b[0m, in \u001b[0;36mContext.call_function\u001b[1;34m(self, name, tensor_inputs, num_outputs)\u001b[0m\n\u001b[0;32m 1498\u001b[0m cancellation_context \u001b[38;5;241m=\u001b[39m cancellation\u001b[38;5;241m.\u001b[39mcontext()\n\u001b[0;32m 1499\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cancellation_context \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1500\u001b[0m outputs \u001b[38;5;241m=\u001b[39m \u001b[43mexecute\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexecute\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1501\u001b[0m \u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdecode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mutf-8\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1502\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_outputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_outputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1503\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtensor_inputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1504\u001b[0m \u001b[43m \u001b[49m\u001b[43mattrs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mattrs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1505\u001b[0m \u001b[43m \u001b[49m\u001b[43mctx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1506\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1507\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1508\u001b[0m outputs \u001b[38;5;241m=\u001b[39m execute\u001b[38;5;241m.\u001b[39mexecute_with_cancellation(\n\u001b[0;32m 1509\u001b[0m name\u001b[38;5;241m.\u001b[39mdecode(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mutf-8\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 1510\u001b[0m num_outputs\u001b[38;5;241m=\u001b[39mnum_outputs,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1514\u001b[0m cancellation_manager\u001b[38;5;241m=\u001b[39mcancellation_context,\n\u001b[0;32m 1515\u001b[0m )\n",
|
287 |
+
"File \u001b[1;32md:\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\tensorflow\\python\\eager\\execute.py:53\u001b[0m, in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 52\u001b[0m ctx\u001b[38;5;241m.\u001b[39mensure_initialized()\n\u001b[1;32m---> 53\u001b[0m tensors \u001b[38;5;241m=\u001b[39m \u001b[43mpywrap_tfe\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mTFE_Py_Execute\u001b[49m\u001b[43m(\u001b[49m\u001b[43mctx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_handle\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mop_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 54\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mattrs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_outputs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m core\u001b[38;5;241m.\u001b[39m_NotOkStatusException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 56\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
|
288 |
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
289 |
]
|
290 |
}
|
|
|
299 |
"\n",
|
300 |
"model.compile(optimizer='adam', loss='mean_squared_error')\n",
|
301 |
"\n",
|
302 |
+
"checkpoint_path = \"lstm_vav_01.keras\"\n",
|
303 |
"checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
|
304 |
+
"model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=3, batch_size=128, verbose=1, callbacks=[checkpoint_callback])"
|
305 |
]
|
306 |
},
|
307 |
{
|
308 |
"cell_type": "code",
|
309 |
+
"execution_count": 55,
|
310 |
"metadata": {},
|
311 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
"source": [
|
313 |
"model.load_weights(checkpoint_path)"
|
314 |
]
|
315 |
},
|
316 |
{
|
317 |
"cell_type": "code",
|
318 |
+
"execution_count": 56,
|
319 |
"metadata": {},
|
320 |
"outputs": [
|
321 |
{
|
322 |
"name": "stdout",
|
323 |
"output_type": "stream",
|
324 |
"text": [
|
325 |
+
"\u001b[1m12244/12244\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m110s\u001b[0m 9ms/step\n"
|
326 |
]
|
327 |
}
|
328 |
],
|
|
|
332 |
},
|
333 |
{
|
334 |
"cell_type": "code",
|
335 |
+
"execution_count": 60,
|
336 |
"metadata": {},
|
337 |
"outputs": [
|
338 |
{
|
339 |
"data": {
|
340 |
"text/plain": [
|
341 |
+
"{0: 'zone_069_temp',\n",
|
342 |
+
" 1: 'zone_069_fan_spd',\n",
|
343 |
+
" 2: 'zone_068_temp',\n",
|
344 |
+
" 3: 'zone_068_fan_spd',\n",
|
345 |
+
" 4: 'zone_067_temp',\n",
|
346 |
+
" 5: 'zone_067_fan_spd',\n",
|
347 |
+
" 6: 'zone_066_temp',\n",
|
348 |
+
" 7: 'zone_066_fan_spd',\n",
|
349 |
+
" 8: 'zone_065_temp',\n",
|
350 |
+
" 9: 'zone_065_fan_spd',\n",
|
351 |
+
" 10: 'zone_064_temp',\n",
|
352 |
+
" 11: 'zone_064_fan_spd',\n",
|
353 |
+
" 12: 'zone_042_temp',\n",
|
354 |
+
" 13: 'zone_042_fan_spd',\n",
|
355 |
+
" 14: 'zone_041_temp',\n",
|
356 |
+
" 15: 'zone_041_fan_spd',\n",
|
357 |
+
" 16: 'zone_040_temp',\n",
|
358 |
+
" 17: 'zone_040_fan_spd',\n",
|
359 |
+
" 18: 'zone_039_temp',\n",
|
360 |
+
" 19: 'zone_039_fan_spd',\n",
|
361 |
+
" 20: 'zone_038_temp',\n",
|
362 |
+
" 21: 'zone_038_fan_spd',\n",
|
363 |
+
" 22: 'zone_037_temp',\n",
|
364 |
+
" 23: 'zone_037_fan_spd',\n",
|
365 |
+
" 24: 'zone_036_temp',\n",
|
366 |
+
" 25: 'zone_036_fan_spd',\n",
|
367 |
+
" 26: 'rtu_001_fltrd_sa_flow_tn',\n",
|
368 |
+
" 27: 'rtu_001_sa_temp',\n",
|
369 |
+
" 28: 'air_temp_set_1',\n",
|
370 |
+
" 29: 'air_temp_set_2',\n",
|
371 |
+
" 30: 'dew_point_temperature_set_1d',\n",
|
372 |
+
" 31: 'relative_humidity_set_1',\n",
|
373 |
+
" 32: 'solar_radiation_set_1',\n",
|
374 |
+
" 33: 'zone_069_cooling_sp',\n",
|
375 |
+
" 34: 'zone_069_heating_sp',\n",
|
376 |
+
" 35: 'zone_067_cooling_sp',\n",
|
377 |
+
" 36: 'zone_067_heating_sp',\n",
|
378 |
+
" 37: 'zone_066_cooling_sp',\n",
|
379 |
+
" 38: 'zone_066_heating_sp',\n",
|
380 |
+
" 39: 'zone_065_cooling_sp',\n",
|
381 |
+
" 40: 'zone_065_heating_sp',\n",
|
382 |
+
" 41: 'zone_064_cooling_sp',\n",
|
383 |
+
" 42: 'zone_064_heating_sp',\n",
|
384 |
+
" 43: 'zone_042_cooling_sp',\n",
|
385 |
+
" 44: 'zone_042_heating_sp',\n",
|
386 |
+
" 45: 'zone_041_cooling_sp',\n",
|
387 |
+
" 46: 'zone_041_heating_sp',\n",
|
388 |
+
" 47: 'zone_039_cooling_sp',\n",
|
389 |
+
" 48: 'zone_039_heating_sp',\n",
|
390 |
+
" 49: 'zone_038_cooling_sp',\n",
|
391 |
+
" 50: 'zone_038_heating_sp',\n",
|
392 |
+
" 51: 'zone_037_cooling_sp',\n",
|
393 |
+
" 52: 'zone_037_heating_sp',\n",
|
394 |
+
" 53: 'zone_036_cooling_sp',\n",
|
395 |
+
" 54: 'zone_036_heating_sp'}"
|
396 |
]
|
397 |
},
|
398 |
+
"execution_count": 60,
|
399 |
"metadata": {},
|
400 |
"output_type": "execute_result"
|
401 |
}
|
402 |
],
|
403 |
"source": [
|
404 |
+
"idx_to_col = {i:col for i,col in enumerate(traindataset_df.drop(columns = ['date']).columns)}\n",
|
405 |
+
"idx_to_col"
|
406 |
]
|
407 |
},
|
408 |
{
|
409 |
"cell_type": "code",
|
410 |
+
"execution_count": 84,
|
411 |
"metadata": {},
|
412 |
"outputs": [],
|
413 |
"source": [
|
414 |
"%matplotlib qt\n",
|
415 |
"plt.figure()\n",
|
416 |
+
"var = 10\n",
|
417 |
"plt.plot(y_test[:,var], label='Original Testing Data', color='blue')\n",
|
418 |
"plt.plot(test_predict1[:,var], label='Predicted Testing Data', color='red',alpha=0.8)\n",
|
419 |
+
"anomalies = np.where(abs(test_predict1[:,var] - y_test[:,var]) > 0.5)\n",
|
420 |
"plt.scatter(anomalies,test_predict1[anomalies,var], color='black',marker =\"o\",s=100 )\n",
|
421 |
"\n",
|
422 |
"\n",
|
|
|
467 |
},
|
468 |
{
|
469 |
"cell_type": "code",
|
470 |
+
"execution_count": 86,
|
471 |
"metadata": {},
|
472 |
+
"outputs": [
|
473 |
+
{
|
474 |
+
"data": {
|
475 |
+
"text/plain": [
|
476 |
+
"['kmeans_vav_1.pkl']"
|
477 |
+
]
|
478 |
+
},
|
479 |
+
"execution_count": 86,
|
480 |
+
"metadata": {},
|
481 |
+
"output_type": "execute_result"
|
482 |
+
}
|
483 |
+
],
|
484 |
"source": [
|
485 |
"from sklearn.cluster import KMeans\n",
|
486 |
"import numpy as np\n",
|
|
|
491 |
"np.random.seed(0)\n",
|
492 |
"X = (test_predict1 - y_test)\n",
|
493 |
"\n",
|
494 |
+
"k = 2\n",
|
495 |
"\n",
|
496 |
"kmeans = KMeans(n_clusters=k)\n",
|
497 |
"\n",
|
|
|
514 |
"plt.title('KMeans Clustering')\n",
|
515 |
"plt.xlabel('Feature 1')\n",
|
516 |
"plt.ylabel('Feature 2')\n",
|
517 |
+
"plt.show()\n",
|
518 |
+
"\n",
|
519 |
+
"joblib.dump(kmeans, 'kmeans_vav_1.pkl')"
|
520 |
]
|
521 |
},
|
522 |
{
|
src/main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import json
|
2 |
from rtu.RTUAnomalizer import RTUAnomalizer
|
3 |
from rtu.RTUPipeline import RTUPipeline
|
|
|
4 |
import paho.mqtt.client as mqtt
|
5 |
|
6 |
|
@@ -19,6 +20,12 @@ def main():
|
|
19 |
num_outputs=rtu_data_pipeline.num_outputs,
|
20 |
)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def on_message(client, userdata, message):
|
23 |
# print(json.loads(message.payload.decode()))
|
24 |
df_new, df_trans = rtu_data_pipeline.fit(message)
|
|
|
1 |
import json
|
2 |
from rtu.RTUAnomalizer import RTUAnomalizer
|
3 |
from rtu.RTUPipeline import RTUPipeline
|
4 |
+
from vav.VAVPipeline import VAVPipeline
|
5 |
import paho.mqtt.client as mqtt
|
6 |
|
7 |
|
|
|
20 |
num_outputs=rtu_data_pipeline.num_outputs,
|
21 |
)
|
22 |
|
23 |
+
# vav_pipeline = VAVPipeline(rtu_id=1)
|
24 |
+
|
25 |
+
# print(vav_pipeline.input_col_names)
|
26 |
+
|
27 |
+
# print(len(vav_pipeline.output_col_names))
|
28 |
+
|
29 |
def on_message(client, userdata, message):
|
30 |
# print(json.loads(message.payload.decode()))
|
31 |
df_new, df_trans = rtu_data_pipeline.fit(message)
|
src/rtu/RTUAnomalizer.py
CHANGED
@@ -4,6 +4,10 @@ import joblib
|
|
4 |
|
5 |
|
6 |
class RTUAnomalizer:
|
|
|
|
|
|
|
|
|
7 |
model = None
|
8 |
kmeans_models = []
|
9 |
|
@@ -14,31 +18,84 @@ class RTUAnomalizer:
|
|
14 |
num_inputs=None,
|
15 |
num_outputs=None,
|
16 |
):
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
self.num_inputs = num_inputs
|
19 |
self.num_outputs = num_outputs
|
20 |
-
if
|
21 |
self.load_models(prediction_model_path, clustering_model_paths)
|
22 |
|
23 |
def initialize_lists(self, size=30):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
initial_values = [0] * size
|
25 |
return initial_values.copy(), initial_values.copy(), initial_values.copy()
|
26 |
|
27 |
def load_models(self, prediction_model_path, clustering_model_paths):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
self.model = load_model(prediction_model_path)
|
29 |
|
30 |
for path in clustering_model_paths:
|
31 |
self.kmeans_models.append(joblib.load(path))
|
32 |
|
33 |
def predict(self, df_new):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return self.model.predict(df_new)
|
35 |
|
36 |
def calculate_residuals(self, df_trans, pred):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
actual = df_trans[30, : self.num_outputs]
|
38 |
resid = actual - pred
|
39 |
return actual, resid
|
40 |
|
41 |
def resize_prediction(self, pred, df_trans):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
pred = np.resize(
|
43 |
pred, (pred.shape[0], pred.shape[1] + len(df_trans[30, self.num_outputs :]))
|
44 |
)
|
@@ -48,11 +105,36 @@ class RTUAnomalizer:
|
|
48 |
return pred
|
49 |
|
50 |
def inverse_transform(self, scaler, pred, df_trans):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
pred = scaler.inverse_transform(np.array(pred))
|
52 |
actual = scaler.inverse_transform(np.array([df_trans[30, :]]))
|
53 |
return actual, pred
|
54 |
|
55 |
def update_lists(self, actual_list, pred_list, resid_list, actual, pred, resid):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
actual_list.pop(0)
|
57 |
pred_list.pop(0)
|
58 |
resid_list.pop(0)
|
@@ -62,6 +144,15 @@ class RTUAnomalizer:
|
|
62 |
return actual_list, pred_list, resid_list
|
63 |
|
64 |
def calculate_distances(self, resid):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
dist = []
|
66 |
for i, model in enumerate(self.kmeans_models):
|
67 |
dist.append(
|
@@ -75,6 +166,17 @@ class RTUAnomalizer:
|
|
75 |
return np.array(dist)
|
76 |
|
77 |
def pipeline(self, df_new, df_trans, scaler):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
actual_list, pred_list, resid_list = self.initialize_lists()
|
79 |
pred = self.predict(df_new)
|
80 |
actual, resid = self.calculate_residuals(df_trans, pred)
|
|
|
4 |
|
5 |
|
6 |
class RTUAnomalizer:
|
7 |
+
"""
|
8 |
+
Class for performing anomaly detection on RTU (Roof Top Unit) data.
|
9 |
+
"""
|
10 |
+
|
11 |
model = None
|
12 |
kmeans_models = []
|
13 |
|
|
|
18 |
num_inputs=None,
|
19 |
num_outputs=None,
|
20 |
):
|
21 |
+
"""
|
22 |
+
Initialize the RTUAnomalizer object.
|
23 |
|
24 |
+
Args:
|
25 |
+
prediction_model_path (str): Path to the prediction model file.
|
26 |
+
clustering_model_paths (list): List of paths to the clustering model files.
|
27 |
+
num_inputs (int): Number of input features.
|
28 |
+
num_outputs (int): Number of output features.
|
29 |
+
"""
|
30 |
self.num_inputs = num_inputs
|
31 |
self.num_outputs = num_outputs
|
32 |
+
if prediction_model_path is not None and clustering_model_paths is not None:
|
33 |
self.load_models(prediction_model_path, clustering_model_paths)
|
34 |
|
35 |
def initialize_lists(self, size=30):
|
36 |
+
"""
|
37 |
+
Initialize lists for storing actual, predicted, and residual values.
|
38 |
+
|
39 |
+
Args:
|
40 |
+
size (int): Size of the lists.
|
41 |
+
|
42 |
+
Returns:
|
43 |
+
tuple: A tuple containing three lists initialized with zeros.
|
44 |
+
"""
|
45 |
initial_values = [0] * size
|
46 |
return initial_values.copy(), initial_values.copy(), initial_values.copy()
|
47 |
|
48 |
def load_models(self, prediction_model_path, clustering_model_paths):
|
49 |
+
"""
|
50 |
+
Load the prediction and clustering models.
|
51 |
+
|
52 |
+
Args:
|
53 |
+
prediction_model_path (str): Path to the prediction model file.
|
54 |
+
clustering_model_paths (list): List of paths to the clustering model files.
|
55 |
+
"""
|
56 |
self.model = load_model(prediction_model_path)
|
57 |
|
58 |
for path in clustering_model_paths:
|
59 |
self.kmeans_models.append(joblib.load(path))
|
60 |
|
61 |
def predict(self, df_new):
|
62 |
+
"""
|
63 |
+
Make predictions using the prediction model.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
df_new (DataFrame): Input data for prediction.
|
67 |
+
|
68 |
+
Returns:
|
69 |
+
array: Predicted values.
|
70 |
+
"""
|
71 |
return self.model.predict(df_new)
|
72 |
|
73 |
def calculate_residuals(self, df_trans, pred):
|
74 |
+
"""
|
75 |
+
Calculate the residuals between actual and predicted values.
|
76 |
+
|
77 |
+
Args:
|
78 |
+
df_trans (DataFrame): Transformed input data.
|
79 |
+
pred (array): Predicted values.
|
80 |
+
|
81 |
+
Returns:
|
82 |
+
tuple: A tuple containing the actual values and residuals.
|
83 |
+
"""
|
84 |
actual = df_trans[30, : self.num_outputs]
|
85 |
resid = actual - pred
|
86 |
return actual, resid
|
87 |
|
88 |
def resize_prediction(self, pred, df_trans):
|
89 |
+
"""
|
90 |
+
Resize the predicted values to match the shape of the transformed input data.
|
91 |
+
|
92 |
+
Args:
|
93 |
+
pred (array): Predicted values.
|
94 |
+
df_trans (DataFrame): Transformed input data.
|
95 |
+
|
96 |
+
Returns:
|
97 |
+
array: Resized predicted values.
|
98 |
+
"""
|
99 |
pred = np.resize(
|
100 |
pred, (pred.shape[0], pred.shape[1] + len(df_trans[30, self.num_outputs :]))
|
101 |
)
|
|
|
105 |
return pred
|
106 |
|
107 |
def inverse_transform(self, scaler, pred, df_trans):
|
108 |
+
"""
|
109 |
+
Inverse transform the predicted and actual values.
|
110 |
+
|
111 |
+
Args:
|
112 |
+
scaler (object): Scaler object for inverse transformation.
|
113 |
+
pred (array): Predicted values.
|
114 |
+
df_trans (DataFrame): Transformed input data.
|
115 |
+
|
116 |
+
Returns:
|
117 |
+
tuple: A tuple containing the actual and predicted values after inverse transformation.
|
118 |
+
"""
|
119 |
pred = scaler.inverse_transform(np.array(pred))
|
120 |
actual = scaler.inverse_transform(np.array([df_trans[30, :]]))
|
121 |
return actual, pred
|
122 |
|
123 |
def update_lists(self, actual_list, pred_list, resid_list, actual, pred, resid):
|
124 |
+
"""
|
125 |
+
Update the lists of actual, predicted, and residual values.
|
126 |
+
|
127 |
+
Args:
|
128 |
+
actual_list (list): List of actual values.
|
129 |
+
pred_list (list): List of predicted values.
|
130 |
+
resid_list (list): List of residual values.
|
131 |
+
actual (array): Actual values.
|
132 |
+
pred (array): Predicted values.
|
133 |
+
resid (array): Residual values.
|
134 |
+
|
135 |
+
Returns:
|
136 |
+
tuple: A tuple containing the updated lists of actual, predicted, and residual values.
|
137 |
+
"""
|
138 |
actual_list.pop(0)
|
139 |
pred_list.pop(0)
|
140 |
resid_list.pop(0)
|
|
|
144 |
return actual_list, pred_list, resid_list
|
145 |
|
146 |
def calculate_distances(self, resid):
|
147 |
+
"""
|
148 |
+
Calculate the distances between residuals and cluster centers.
|
149 |
+
|
150 |
+
Args:
|
151 |
+
resid (array): Residual values.
|
152 |
+
|
153 |
+
Returns:
|
154 |
+
array: Array of distances.
|
155 |
+
"""
|
156 |
dist = []
|
157 |
for i, model in enumerate(self.kmeans_models):
|
158 |
dist.append(
|
|
|
166 |
return np.array(dist)
|
167 |
|
168 |
def pipeline(self, df_new, df_trans, scaler):
|
169 |
+
"""
|
170 |
+
Perform the anomaly detection pipeline.
|
171 |
+
|
172 |
+
Args:
|
173 |
+
df_new (DataFrame): Input data for prediction.
|
174 |
+
df_trans (DataFrame): Transformed input data.
|
175 |
+
scaler (object): Scaler object for inverse transformation.
|
176 |
+
|
177 |
+
Returns:
|
178 |
+
tuple: A tuple containing the lists of actual, predicted, and residual values, and the distances.
|
179 |
+
"""
|
180 |
actual_list, pred_list, resid_list = self.initialize_lists()
|
181 |
pred = self.predict(df_new)
|
182 |
actual, resid = self.calculate_residuals(df_trans, pred)
|
src/vav/VAVAnomalizer.py
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
|
6 |
+
class VAVAnomalizer:
|
7 |
+
def __init__(
|
8 |
+
self,
|
9 |
+
rtu_id,
|
10 |
+
prediction_model_path,
|
11 |
+
clustering_model_path,
|
12 |
+
num_inputs,
|
13 |
+
num_outputs,
|
14 |
+
):
|
15 |
+
"""
|
16 |
+
Initializes a VAVAnomalizer object.
|
17 |
+
|
18 |
+
Args:
|
19 |
+
rtu_id (int): The ID of the RTU (Roof Top Unit) associated with the VAV (Variable Air Volume) system.
|
20 |
+
prediction_model_path (str): The file path to the prediction model.
|
21 |
+
clustering_model_path (str): The file path to the clustering model.
|
22 |
+
num_inputs (int): The number of input features for the prediction model.
|
23 |
+
num_outputs (int): The number of output features for the prediction model.
|
24 |
+
"""
|
25 |
+
self.rtu_id = rtu_id
|
26 |
+
self.num_inputs = num_inputs
|
27 |
+
self.num_outputs = num_outputs
|
28 |
+
self.load_models(prediction_model_path, clustering_model_path)
|
29 |
+
|
30 |
+
def load_models(self, prediction_model_path, clustering_model_path):
|
31 |
+
"""
|
32 |
+
Loads the prediction model and clustering model.
|
33 |
+
|
34 |
+
Args:
|
35 |
+
prediction_model_path (str): The file path to the prediction model.
|
36 |
+
clustering_model_path (str): The file path to the clustering model.
|
37 |
+
"""
|
38 |
+
self.model = load_model(prediction_model_path)
|
39 |
+
self.kmeans_model = joblib.load(clustering_model_path)
|
40 |
+
|
41 |
+
def initialize_lists(self, size=30):
|
42 |
+
"""
|
43 |
+
Initialize lists for storing actual, predicted, and residual values.
|
44 |
+
|
45 |
+
Args:
|
46 |
+
size (int): Size of the lists.
|
47 |
+
|
48 |
+
Returns:
|
49 |
+
tuple: A tuple containing three lists initialized with zeros.
|
50 |
+
"""
|
51 |
+
initial_values = [0] * size
|
52 |
+
return initial_values.copy(), initial_values.copy(), initial_values.copy()
|
53 |
+
|
54 |
+
def predict(self, df_new):
|
55 |
+
"""
|
56 |
+
Makes predictions using the prediction model.
|
57 |
+
|
58 |
+
Args:
|
59 |
+
df_new (numpy.ndarray): The new data for prediction.
|
60 |
+
|
61 |
+
Returns:
|
62 |
+
numpy.ndarray: The predicted values.
|
63 |
+
"""
|
64 |
+
return self.model.predict(df_new)
|
65 |
+
|
66 |
+
def calculate_residuals(self, df_trans, pred):
|
67 |
+
"""
|
68 |
+
Calculates the residuals between the actual values and the predicted values.
|
69 |
+
|
70 |
+
Args:
|
71 |
+
df_trans (numpy.ndarray): The transformed data.
|
72 |
+
pred (numpy.ndarray): The predicted values.
|
73 |
+
|
74 |
+
Returns:
|
75 |
+
numpy.ndarray: The actual values.
|
76 |
+
numpy.ndarray: The residuals.
|
77 |
+
"""
|
78 |
+
actual = df_trans[30, : self.num_outputs]
|
79 |
+
resid = actual - pred
|
80 |
+
return actual, resid
|
81 |
+
|
82 |
+
def calculate_distances(self, resid):
|
83 |
+
"""
|
84 |
+
Calculate the distances between residuals and cluster centers.
|
85 |
+
|
86 |
+
Args:
|
87 |
+
resid (array): Residual values.
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
array: Array of distances.
|
91 |
+
"""
|
92 |
+
dist = []
|
93 |
+
dist.append(np.linalg.norm(resid - self.kmeans_model.cluster_centers_[0]))
|
94 |
+
|
95 |
+
return np.array(dist)
|
96 |
+
|
97 |
+
def resize_prediction(self, pred, df_trans):
|
98 |
+
"""
|
99 |
+
Resize the predicted values to match the shape of the transformed input data.
|
100 |
+
|
101 |
+
Args:
|
102 |
+
pred (array): Predicted values.
|
103 |
+
df_trans (DataFrame): Transformed input data.
|
104 |
+
|
105 |
+
Returns:
|
106 |
+
array: Resized predicted values.
|
107 |
+
"""
|
108 |
+
pred = np.resize(
|
109 |
+
pred, (pred.shape[0], pred.shape[1] + len(df_trans[30, self.num_outputs :]))
|
110 |
+
)
|
111 |
+
pred[:, -len(df_trans[30, self.num_outputs :]) :] = df_trans[
|
112 |
+
30, self.num_outputs :
|
113 |
+
]
|
114 |
+
return pred
|
115 |
+
|
116 |
+
def inverse_transform(self, scaler, pred, df_trans):
|
117 |
+
"""
|
118 |
+
Inverse transform the predicted and actual values.
|
119 |
+
|
120 |
+
Args:
|
121 |
+
scaler (object): Scaler object for inverse transformation.
|
122 |
+
pred (array): Predicted values.
|
123 |
+
df_trans (DataFrame): Transformed input data.
|
124 |
+
|
125 |
+
Returns:
|
126 |
+
tuple: A tuple containing the actual and predicted values after inverse transformation.
|
127 |
+
"""
|
128 |
+
pred = scaler.inverse_transform(np.array(pred))
|
129 |
+
actual = scaler.inverse_transform(np.array([df_trans[30, :]]))
|
130 |
+
return actual, pred
|
131 |
+
|
132 |
+
def update_lists(self, actual_list, pred_list, resid_list, actual, pred, resid):
|
133 |
+
"""
|
134 |
+
Update the lists of actual, predicted, and residual values.
|
135 |
+
|
136 |
+
Args:
|
137 |
+
actual_list (list): List of actual values.
|
138 |
+
pred_list (list): List of predicted values.
|
139 |
+
resid_list (list): List of residual values.
|
140 |
+
actual (array): Actual values.
|
141 |
+
pred (array): Predicted values.
|
142 |
+
resid (array): Residual values.
|
143 |
+
|
144 |
+
Returns:
|
145 |
+
tuple: A tuple containing the updated lists of actual, predicted, and residual values.
|
146 |
+
"""
|
147 |
+
actual_list.pop(0)
|
148 |
+
pred_list.pop(0)
|
149 |
+
resid_list.pop(0)
|
150 |
+
actual_list.append(actual[0, 1])
|
151 |
+
pred_list.append(pred[0, 1])
|
152 |
+
resid_list.append(resid[0, 1])
|
153 |
+
return actual_list, pred_list, resid_list
|
154 |
+
|
155 |
+
def pipeline(self, df_new, df_trans, scaler):
|
156 |
+
"""
|
157 |
+
Perform the anomaly detection pipeline.
|
158 |
+
|
159 |
+
Args:
|
160 |
+
df_new (DataFrame): Input data for prediction.
|
161 |
+
df_trans (DataFrame): Transformed input data.
|
162 |
+
scaler (object): Scaler object for inverse transformation.
|
163 |
+
|
164 |
+
Returns:
|
165 |
+
tuple: A tuple containing the lists of actual, predicted, and residual values, and the distances.
|
166 |
+
"""
|
167 |
+
actual_list, pred_list, resid_list = self.initialize_lists()
|
168 |
+
pred = self.predict(df_new)
|
169 |
+
actual, resid = self.calculate_residuals(df_trans, pred)
|
170 |
+
pred = self.resize_prediction(pred, df_trans)
|
171 |
+
actual, pred = self.inverse_transform(scaler, pred, df_trans)
|
172 |
+
actual_list, pred_list, resid_list = self.update_lists(
|
173 |
+
actual_list, pred_list, resid_list, actual, pred, resid
|
174 |
+
)
|
175 |
+
dist = self.calculate_distances(resid)
|
176 |
+
return actual_list, pred_list, resid_list, dist
|
src/vav/VAVPipeline.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from sklearn.preprocessing import StandardScaler
|
3 |
+
from pickle import load
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
class VAVPipeline:
|
8 |
+
|
9 |
+
def __init__(self, rtu_id, scaler_path=None, window_size=30):
|
10 |
+
|
11 |
+
self.window_size = window_size
|
12 |
+
|
13 |
+
if rtu_id == 1:
|
14 |
+
self.zones = [69, 68, 67, 66, 65, 64, 42, 41, 40, 39, 38, 37, 36]
|
15 |
+
if rtu_id == 2:
|
16 |
+
self.zones = [
|
17 |
+
72,
|
18 |
+
71,
|
19 |
+
63,
|
20 |
+
62,
|
21 |
+
60,
|
22 |
+
59,
|
23 |
+
58,
|
24 |
+
57,
|
25 |
+
50,
|
26 |
+
49,
|
27 |
+
44,
|
28 |
+
43,
|
29 |
+
35,
|
30 |
+
34,
|
31 |
+
33,
|
32 |
+
32,
|
33 |
+
31,
|
34 |
+
30,
|
35 |
+
29,
|
36 |
+
28,
|
37 |
+
]
|
38 |
+
|
39 |
+
outputs = ["temp", "fan_speed"]
|
40 |
+
inputs = ["cooling_sp", "heating_sp"]
|
41 |
+
self.output_col_names = []
|
42 |
+
self.input_col_names = [
|
43 |
+
f"rtu_00{rtu_id}_fltrd_sa_flow_tn",
|
44 |
+
f"rtu_00{rtu_id}_sa_temp",
|
45 |
+
"air_temp_set_1",
|
46 |
+
"air_temp_set_2",
|
47 |
+
"dew_point_temperature_set_1d",
|
48 |
+
"relative_humidity_set_1",
|
49 |
+
"solar_radiation_set_1",
|
50 |
+
]
|
51 |
+
for zone in self.zones:
|
52 |
+
for output in outputs:
|
53 |
+
self.output_col_names.append(f"zone_0{zone}_{output}")
|
54 |
+
for input in inputs:
|
55 |
+
self.input_col_names.append(f"zone_0{zone}_{input}")
|
56 |
+
|
57 |
+
self.column_names = self.output_col_names + self.input_col_names
|
58 |
+
|
59 |
+
if scaler_path:
|
60 |
+
self.scaler = self.get_scaler(scaler_path)
|
61 |
+
|
62 |
+
def get_scaler(self, scaler_path):
|
63 |
+
return load(scaler_path)
|
64 |
+
|
65 |
+
def get_window(self, df):
|
66 |
+
len_df = len(df)
|
67 |
+
if len_df > self.window_size:
|
68 |
+
return df[len_df - (self.window_size + 1) : len_df].astype("float32")
|
69 |
+
else:
|
70 |
+
return None
|
71 |
+
|
72 |
+
def transform_window(self, df_window):
|
73 |
+
return self.scaler.transform(df_window)
|
74 |
+
|
75 |
+
def prepare_input(self, df_trans):
|
76 |
+
return df_trans[: self.window_size, :].reshape(
|
77 |
+
(1, self.window_size, len(self.column_names))
|
78 |
+
)
|
79 |
+
|
80 |
+
def extract_data_from_message(self, message):
|
81 |
+
payload = json.loads(message.payload.decode())
|
82 |
+
|
83 |
+
len_df = len(self.df)
|
84 |
+
|
85 |
+
k = {}
|
86 |
+
for col in self.column_names:
|
87 |
+
k[col] = payload[col]
|
88 |
+
self.df.loc[len_df] = k
|
89 |
+
return self.df
|
90 |
+
|
91 |
+
def fit(self, message):
|
92 |
+
df = self.extract_data_from_message(message)
|
93 |
+
df_window = self.get_window(df)
|
94 |
+
if df_window is not None:
|
95 |
+
df_trans = self.transform_window(df_window)
|
96 |
+
df_new = self.prepare_input(df_trans)
|
97 |
+
else:
|
98 |
+
df_new = None
|
99 |
+
df_trans = None
|
100 |
+
return df_new, df_trans
|
src/vav/models/kmeans_vav_1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:086d45b9d2c98baaea5b0588cd6d228d84eb141b707fe845b11316b3ddc58774
|
3 |
+
size 1568153
|
src/vav/models/lstm_vav_01.keras
ADDED
Binary file (658 kB). View file
|
|
src/vav/models/scaler_vav_1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:293ee3c9082e7104dfc96425cecad2a44e5914bbd1f43c25a0fd8c36507b103a
|
3 |
+
size 1925
|