jerin commited on
Commit
e93e440
β€’
1 Parent(s): f226f2c
Files changed (1) hide show
  1. file_info.ipynb +615 -87
file_info.ipynb CHANGED
@@ -2,19 +2,26 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
  "import pandas as pd \n",
10
  "from datetime import datetime \n",
 
11
  "import matplotlib.pyplot as plt\n",
12
- "import seaborn as sns\n"
 
 
 
 
 
 
13
  ]
14
  },
15
  {
16
  "cell_type": "code",
17
- "execution_count": 2,
18
  "metadata": {},
19
  "outputs": [
20
  {
@@ -39,17 +46,18 @@
39
  " <tr style=\"text-align: right;\">\n",
40
  " <th></th>\n",
41
  " <th>date</th>\n",
42
- " <th>zone_017_hw_valve</th>\n",
43
  " <th>rtu_004_sat_sp_tn</th>\n",
44
- " <th>zone_017_temp</th>\n",
45
- " <th>zone_017_fan_spd</th>\n",
46
  " <th>rtu_004_fltrd_sa_flow_tn</th>\n",
47
  " <th>rtu_004_sa_temp</th>\n",
48
  " <th>rtu_004_pa_static_stpt_tn</th>\n",
49
  " <th>rtu_004_oa_flow_tn</th>\n",
50
  " <th>rtu_004_oadmpr_pct</th>\n",
51
  " <th>...</th>\n",
52
- " <th>zone_017_heating_sp</th>\n",
 
53
  " <th>hvac_S</th>\n",
54
  " <th>hp_hws_temp</th>\n",
55
  " <th>aru_001_cwr_temp</th>\n",
@@ -58,7 +66,6 @@
58
  " <th>aru_001_hwr_temp</th>\n",
59
  " <th>aru_001_hws_fr_gpm</th>\n",
60
  " <th>aru_001_hws_temp</th>\n",
61
- " <th>hp_hws_temp</th>\n",
62
  " </tr>\n",
63
  " </thead>\n",
64
  " <tbody>\n",
@@ -67,7 +74,7 @@
67
  " <td>2018-01-01 00:00:00</td>\n",
68
  " <td>100.0</td>\n",
69
  " <td>69.0</td>\n",
70
- " <td>66.7</td>\n",
71
  " <td>20.0</td>\n",
72
  " <td>9265.604</td>\n",
73
  " <td>66.1</td>\n",
@@ -77,6 +84,7 @@
77
  " <td>...</td>\n",
78
  " <td>NaN</td>\n",
79
  " <td>NaN</td>\n",
 
80
  " <td>75.3</td>\n",
81
  " <td>NaN</td>\n",
82
  " <td>NaN</td>\n",
@@ -84,14 +92,13 @@
84
  " <td>NaN</td>\n",
85
  " <td>NaN</td>\n",
86
  " <td>NaN</td>\n",
87
- " <td>75.3</td>\n",
88
  " </tr>\n",
89
  " <tr>\n",
90
  " <th>1</th>\n",
91
  " <td>2018-01-01 00:01:00</td>\n",
92
  " <td>100.0</td>\n",
93
  " <td>69.0</td>\n",
94
- " <td>66.7</td>\n",
95
  " <td>20.0</td>\n",
96
  " <td>9265.604</td>\n",
97
  " <td>66.0</td>\n",
@@ -101,6 +108,7 @@
101
  " <td>...</td>\n",
102
  " <td>NaN</td>\n",
103
  " <td>NaN</td>\n",
 
104
  " <td>75.3</td>\n",
105
  " <td>NaN</td>\n",
106
  " <td>NaN</td>\n",
@@ -108,14 +116,13 @@
108
  " <td>NaN</td>\n",
109
  " <td>NaN</td>\n",
110
  " <td>NaN</td>\n",
111
- " <td>75.3</td>\n",
112
  " </tr>\n",
113
  " <tr>\n",
114
  " <th>2</th>\n",
115
  " <td>2018-01-01 00:02:00</td>\n",
116
  " <td>100.0</td>\n",
117
  " <td>69.0</td>\n",
118
- " <td>66.7</td>\n",
119
  " <td>20.0</td>\n",
120
  " <td>9708.240</td>\n",
121
  " <td>66.1</td>\n",
@@ -125,6 +132,7 @@
125
  " <td>...</td>\n",
126
  " <td>NaN</td>\n",
127
  " <td>NaN</td>\n",
 
128
  " <td>75.3</td>\n",
129
  " <td>NaN</td>\n",
130
  " <td>NaN</td>\n",
@@ -132,14 +140,13 @@
132
  " <td>NaN</td>\n",
133
  " <td>NaN</td>\n",
134
  " <td>NaN</td>\n",
135
- " <td>75.3</td>\n",
136
  " </tr>\n",
137
  " <tr>\n",
138
  " <th>3</th>\n",
139
  " <td>2018-01-01 00:03:00</td>\n",
140
  " <td>100.0</td>\n",
141
  " <td>69.0</td>\n",
142
- " <td>66.7</td>\n",
143
  " <td>20.0</td>\n",
144
  " <td>9611.638</td>\n",
145
  " <td>66.1</td>\n",
@@ -149,6 +156,7 @@
149
  " <td>...</td>\n",
150
  " <td>NaN</td>\n",
151
  " <td>NaN</td>\n",
 
152
  " <td>75.3</td>\n",
153
  " <td>NaN</td>\n",
154
  " <td>NaN</td>\n",
@@ -156,14 +164,13 @@
156
  " <td>NaN</td>\n",
157
  " <td>NaN</td>\n",
158
  " <td>NaN</td>\n",
159
- " <td>75.3</td>\n",
160
  " </tr>\n",
161
  " <tr>\n",
162
  " <th>4</th>\n",
163
  " <td>2018-01-01 00:04:00</td>\n",
164
  " <td>100.0</td>\n",
165
  " <td>69.0</td>\n",
166
- " <td>66.7</td>\n",
167
  " <td>20.0</td>\n",
168
  " <td>9215.110</td>\n",
169
  " <td>66.0</td>\n",
@@ -173,6 +180,7 @@
173
  " <td>...</td>\n",
174
  " <td>NaN</td>\n",
175
  " <td>NaN</td>\n",
 
176
  " <td>75.3</td>\n",
177
  " <td>NaN</td>\n",
178
  " <td>NaN</td>\n",
@@ -180,7 +188,6 @@
180
  " <td>NaN</td>\n",
181
  " <td>NaN</td>\n",
182
  " <td>NaN</td>\n",
183
- " <td>75.3</td>\n",
184
  " </tr>\n",
185
  " <tr>\n",
186
  " <th>...</th>\n",
@@ -211,8 +218,8 @@
211
  " <td>2020-12-31 23:58:00</td>\n",
212
  " <td>100.0</td>\n",
213
  " <td>68.0</td>\n",
214
- " <td>63.5</td>\n",
215
- " <td>40.0</td>\n",
216
  " <td>18884.834</td>\n",
217
  " <td>64.4</td>\n",
218
  " <td>0.06</td>\n",
@@ -220,6 +227,7 @@
220
  " <td>23.4</td>\n",
221
  " <td>...</td>\n",
222
  " <td>71.0</td>\n",
 
223
  " <td>23.145000</td>\n",
224
  " <td>123.8</td>\n",
225
  " <td>56.25</td>\n",
@@ -228,15 +236,14 @@
228
  " <td>123.42</td>\n",
229
  " <td>61.6</td>\n",
230
  " <td>122.36</td>\n",
231
- " <td>123.8</td>\n",
232
  " </tr>\n",
233
  " <tr>\n",
234
  " <th>2072150</th>\n",
235
  " <td>2020-12-31 23:58:00</td>\n",
236
  " <td>100.0</td>\n",
237
  " <td>68.0</td>\n",
238
- " <td>63.5</td>\n",
239
- " <td>40.0</td>\n",
240
  " <td>18884.834</td>\n",
241
  " <td>64.4</td>\n",
242
  " <td>0.06</td>\n",
@@ -244,6 +251,7 @@
244
  " <td>23.4</td>\n",
245
  " <td>...</td>\n",
246
  " <td>71.0</td>\n",
 
247
  " <td>23.145000</td>\n",
248
  " <td>123.8</td>\n",
249
  " <td>56.25</td>\n",
@@ -252,15 +260,14 @@
252
  " <td>123.42</td>\n",
253
  " <td>61.6</td>\n",
254
  " <td>122.36</td>\n",
255
- " <td>123.8</td>\n",
256
  " </tr>\n",
257
  " <tr>\n",
258
  " <th>2072151</th>\n",
259
  " <td>2020-12-31 23:59:00</td>\n",
260
  " <td>100.0</td>\n",
261
  " <td>68.0</td>\n",
262
- " <td>63.5</td>\n",
263
- " <td>40.0</td>\n",
264
  " <td>19345.508</td>\n",
265
  " <td>64.3</td>\n",
266
  " <td>0.06</td>\n",
@@ -268,6 +275,7 @@
268
  " <td>23.4</td>\n",
269
  " <td>...</td>\n",
270
  " <td>71.0</td>\n",
 
271
  " <td>23.145000</td>\n",
272
  " <td>123.8</td>\n",
273
  " <td>56.25</td>\n",
@@ -276,15 +284,14 @@
276
  " <td>123.42</td>\n",
277
  " <td>61.6</td>\n",
278
  " <td>122.36</td>\n",
279
- " <td>123.8</td>\n",
280
  " </tr>\n",
281
  " <tr>\n",
282
  " <th>2072152</th>\n",
283
  " <td>2020-12-31 23:59:00</td>\n",
284
  " <td>100.0</td>\n",
285
  " <td>68.0</td>\n",
286
- " <td>63.5</td>\n",
287
- " <td>40.0</td>\n",
288
  " <td>19345.508</td>\n",
289
  " <td>64.3</td>\n",
290
  " <td>0.06</td>\n",
@@ -292,6 +299,7 @@
292
  " <td>23.4</td>\n",
293
  " <td>...</td>\n",
294
  " <td>71.0</td>\n",
 
295
  " <td>23.145000</td>\n",
296
  " <td>123.8</td>\n",
297
  " <td>56.25</td>\n",
@@ -300,15 +308,14 @@
300
  " <td>123.42</td>\n",
301
  " <td>61.6</td>\n",
302
  " <td>122.36</td>\n",
303
- " <td>123.8</td>\n",
304
  " </tr>\n",
305
  " <tr>\n",
306
  " <th>2072153</th>\n",
307
  " <td>2021-01-01 00:00:00</td>\n",
308
  " <td>100.0</td>\n",
309
  " <td>68.0</td>\n",
310
- " <td>63.5</td>\n",
311
- " <td>40.0</td>\n",
312
  " <td>18650.232</td>\n",
313
  " <td>64.1</td>\n",
314
  " <td>0.06</td>\n",
@@ -316,6 +323,7 @@
316
  " <td>22.9</td>\n",
317
  " <td>...</td>\n",
318
  " <td>71.0</td>\n",
 
319
  " <td>23.788947</td>\n",
320
  " <td>123.8</td>\n",
321
  " <td>56.25</td>\n",
@@ -324,15 +332,14 @@
324
  " <td>123.42</td>\n",
325
  " <td>61.6</td>\n",
326
  " <td>122.36</td>\n",
327
- " <td>123.8</td>\n",
328
  " </tr>\n",
329
  " </tbody>\n",
330
  "</table>\n",
331
- "<p>2072154 rows Γ— 29 columns</p>\n",
332
  "</div>"
333
  ],
334
  "text/plain": [
335
- " date zone_017_hw_valve rtu_004_sat_sp_tn \\\n",
336
  "0 2018-01-01 00:00:00 100.0 69.0 \n",
337
  "1 2018-01-01 00:01:00 100.0 69.0 \n",
338
  "2 2018-01-01 00:02:00 100.0 69.0 \n",
@@ -345,18 +352,18 @@
345
  "2072152 2020-12-31 23:59:00 100.0 68.0 \n",
346
  "2072153 2021-01-01 00:00:00 100.0 68.0 \n",
347
  "\n",
348
- " zone_017_temp zone_017_fan_spd rtu_004_fltrd_sa_flow_tn \\\n",
349
- "0 66.7 20.0 9265.604 \n",
350
- "1 66.7 20.0 9265.604 \n",
351
- "2 66.7 20.0 9708.240 \n",
352
- "3 66.7 20.0 9611.638 \n",
353
- "4 66.7 20.0 9215.110 \n",
354
  "... ... ... ... \n",
355
- "2072149 63.5 40.0 18884.834 \n",
356
- "2072150 63.5 40.0 18884.834 \n",
357
- "2072151 63.5 40.0 19345.508 \n",
358
- "2072152 63.5 40.0 19345.508 \n",
359
- "2072153 63.5 40.0 18650.232 \n",
360
  "\n",
361
  " rtu_004_sa_temp rtu_004_pa_static_stpt_tn rtu_004_oa_flow_tn \\\n",
362
  "0 66.1 0.06 0.000000 \n",
@@ -371,57 +378,70 @@
371
  "2072152 64.3 0.06 3154.390000 \n",
372
  "2072153 64.1 0.06 3076.270000 \n",
373
  "\n",
374
- " rtu_004_oadmpr_pct ... zone_017_heating_sp hvac_S hp_hws_temp \\\n",
375
- "0 28.0 ... NaN NaN 75.3 \n",
376
- "1 28.0 ... NaN NaN 75.3 \n",
377
- "2 28.0 ... NaN NaN 75.3 \n",
378
- "3 28.0 ... NaN NaN 75.3 \n",
379
- "4 28.0 ... NaN NaN 75.3 \n",
380
- "... ... ... ... ... ... \n",
381
- "2072149 23.4 ... 71.0 23.145000 123.8 \n",
382
- "2072150 23.4 ... 71.0 23.145000 123.8 \n",
383
- "2072151 23.4 ... 71.0 23.145000 123.8 \n",
384
- "2072152 23.4 ... 71.0 23.145000 123.8 \n",
385
- "2072153 22.9 ... 71.0 23.788947 123.8 \n",
386
  "\n",
387
- " aru_001_cwr_temp aru_001_cws_fr_gpm aru_001_cws_temp \\\n",
388
- "0 NaN NaN NaN \n",
389
- "1 NaN NaN NaN \n",
390
- "2 NaN NaN NaN \n",
391
- "3 NaN NaN NaN \n",
392
- "4 NaN NaN NaN \n",
393
- "... ... ... ... \n",
394
- "2072149 56.25 54.71 56.4 \n",
395
- "2072150 56.25 54.71 56.4 \n",
396
- "2072151 56.25 54.71 56.4 \n",
397
- "2072152 56.25 54.71 56.4 \n",
398
- "2072153 56.25 54.71 56.4 \n",
399
  "\n",
400
- " aru_001_hwr_temp aru_001_hws_fr_gpm aru_001_hws_temp hp_hws_temp \n",
401
- "0 NaN NaN NaN 75.3 \n",
402
- "1 NaN NaN NaN 75.3 \n",
403
- "2 NaN NaN NaN 75.3 \n",
404
- "3 NaN NaN NaN 75.3 \n",
405
- "4 NaN NaN NaN 75.3 \n",
406
- "... ... ... ... ... \n",
407
- "2072149 123.42 61.6 122.36 123.8 \n",
408
- "2072150 123.42 61.6 122.36 123.8 \n",
409
- "2072151 123.42 61.6 122.36 123.8 \n",
410
- "2072152 123.42 61.6 122.36 123.8 \n",
411
- "2072153 123.42 61.6 122.36 123.8 \n",
412
  "\n",
413
- "[2072154 rows x 29 columns]"
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  ]
415
  },
416
- "execution_count": 2,
417
  "metadata": {},
418
  "output_type": "execute_result"
419
  }
420
  ],
421
  "source": [
422
- "merged = pd.read_csv(r'data/long_merge.csv')\n",
423
  "\n",
424
- "zone = \"17\"\n",
425
  "\n",
426
  "if zone in [\"36\", \"37\", \"38\", \"39\", \"40\", \"41\", \"42\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\", \"70\"]:\n",
427
  " rtu = \"rtu_001\"\n",
@@ -436,10 +456,518 @@
436
  " rtu = \"rtu_002\"\n",
437
  " wing = \"hvac_N\"\n",
438
  "#merged is the dataframe\n",
439
- "sorted = merged[[\"date\"]+[col for col in merged.columns if zone in col or rtu in col or wing in col]+[\"hp_hws_temp\", \"aru_001_cwr_temp\" , \"aru_001_cws_fr_gpm\" ,\"aru_001_cws_temp\",\"aru_001_hwr_temp\" ,\"aru_001_hws_fr_gpm\" ,\"aru_001_hws_temp\",\"hp_hws_temp\"]]\n",
440
  "sorted"
441
  ]
442
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  {
444
  "cell_type": "code",
445
  "execution_count": null,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 2,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
9
  "import pandas as pd \n",
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",
17
+ "from keras.layers import LSTM, Dense\n",
18
+ "from sklearn.model_selection import train_test_split\n",
19
+ "from sklearn.preprocessing import MinMaxScaler\n"
20
  ]
21
  },
22
  {
23
  "cell_type": "code",
24
+ "execution_count": 3,
25
  "metadata": {},
26
  "outputs": [
27
  {
 
46
  " <tr style=\"text-align: right;\">\n",
47
  " <th></th>\n",
48
  " <th>date</th>\n",
49
+ " <th>zone_047_hw_valve</th>\n",
50
  " <th>rtu_004_sat_sp_tn</th>\n",
51
+ " <th>zone_047_temp</th>\n",
52
+ " <th>zone_047_fan_spd</th>\n",
53
  " <th>rtu_004_fltrd_sa_flow_tn</th>\n",
54
  " <th>rtu_004_sa_temp</th>\n",
55
  " <th>rtu_004_pa_static_stpt_tn</th>\n",
56
  " <th>rtu_004_oa_flow_tn</th>\n",
57
  " <th>rtu_004_oadmpr_pct</th>\n",
58
  " <th>...</th>\n",
59
+ " <th>zone_047_heating_sp</th>\n",
60
+ " <th>Unnamed: 47_y</th>\n",
61
  " <th>hvac_S</th>\n",
62
  " <th>hp_hws_temp</th>\n",
63
  " <th>aru_001_cwr_temp</th>\n",
 
66
  " <th>aru_001_hwr_temp</th>\n",
67
  " <th>aru_001_hws_fr_gpm</th>\n",
68
  " <th>aru_001_hws_temp</th>\n",
 
69
  " </tr>\n",
70
  " </thead>\n",
71
  " <tbody>\n",
 
74
  " <td>2018-01-01 00:00:00</td>\n",
75
  " <td>100.0</td>\n",
76
  " <td>69.0</td>\n",
77
+ " <td>67.5</td>\n",
78
  " <td>20.0</td>\n",
79
  " <td>9265.604</td>\n",
80
  " <td>66.1</td>\n",
 
84
  " <td>...</td>\n",
85
  " <td>NaN</td>\n",
86
  " <td>NaN</td>\n",
87
+ " <td>NaN</td>\n",
88
  " <td>75.3</td>\n",
89
  " <td>NaN</td>\n",
90
  " <td>NaN</td>\n",
 
92
  " <td>NaN</td>\n",
93
  " <td>NaN</td>\n",
94
  " <td>NaN</td>\n",
 
95
  " </tr>\n",
96
  " <tr>\n",
97
  " <th>1</th>\n",
98
  " <td>2018-01-01 00:01:00</td>\n",
99
  " <td>100.0</td>\n",
100
  " <td>69.0</td>\n",
101
+ " <td>67.5</td>\n",
102
  " <td>20.0</td>\n",
103
  " <td>9265.604</td>\n",
104
  " <td>66.0</td>\n",
 
108
  " <td>...</td>\n",
109
  " <td>NaN</td>\n",
110
  " <td>NaN</td>\n",
111
+ " <td>NaN</td>\n",
112
  " <td>75.3</td>\n",
113
  " <td>NaN</td>\n",
114
  " <td>NaN</td>\n",
 
116
  " <td>NaN</td>\n",
117
  " <td>NaN</td>\n",
118
  " <td>NaN</td>\n",
 
119
  " </tr>\n",
120
  " <tr>\n",
121
  " <th>2</th>\n",
122
  " <td>2018-01-01 00:02:00</td>\n",
123
  " <td>100.0</td>\n",
124
  " <td>69.0</td>\n",
125
+ " <td>67.5</td>\n",
126
  " <td>20.0</td>\n",
127
  " <td>9708.240</td>\n",
128
  " <td>66.1</td>\n",
 
132
  " <td>...</td>\n",
133
  " <td>NaN</td>\n",
134
  " <td>NaN</td>\n",
135
+ " <td>NaN</td>\n",
136
  " <td>75.3</td>\n",
137
  " <td>NaN</td>\n",
138
  " <td>NaN</td>\n",
 
140
  " <td>NaN</td>\n",
141
  " <td>NaN</td>\n",
142
  " <td>NaN</td>\n",
 
143
  " </tr>\n",
144
  " <tr>\n",
145
  " <th>3</th>\n",
146
  " <td>2018-01-01 00:03:00</td>\n",
147
  " <td>100.0</td>\n",
148
  " <td>69.0</td>\n",
149
+ " <td>67.5</td>\n",
150
  " <td>20.0</td>\n",
151
  " <td>9611.638</td>\n",
152
  " <td>66.1</td>\n",
 
156
  " <td>...</td>\n",
157
  " <td>NaN</td>\n",
158
  " <td>NaN</td>\n",
159
+ " <td>NaN</td>\n",
160
  " <td>75.3</td>\n",
161
  " <td>NaN</td>\n",
162
  " <td>NaN</td>\n",
 
164
  " <td>NaN</td>\n",
165
  " <td>NaN</td>\n",
166
  " <td>NaN</td>\n",
 
167
  " </tr>\n",
168
  " <tr>\n",
169
  " <th>4</th>\n",
170
  " <td>2018-01-01 00:04:00</td>\n",
171
  " <td>100.0</td>\n",
172
  " <td>69.0</td>\n",
173
+ " <td>67.5</td>\n",
174
  " <td>20.0</td>\n",
175
  " <td>9215.110</td>\n",
176
  " <td>66.0</td>\n",
 
180
  " <td>...</td>\n",
181
  " <td>NaN</td>\n",
182
  " <td>NaN</td>\n",
183
+ " <td>NaN</td>\n",
184
  " <td>75.3</td>\n",
185
  " <td>NaN</td>\n",
186
  " <td>NaN</td>\n",
 
188
  " <td>NaN</td>\n",
189
  " <td>NaN</td>\n",
190
  " <td>NaN</td>\n",
 
191
  " </tr>\n",
192
  " <tr>\n",
193
  " <th>...</th>\n",
 
218
  " <td>2020-12-31 23:58:00</td>\n",
219
  " <td>100.0</td>\n",
220
  " <td>68.0</td>\n",
221
+ " <td>63.2</td>\n",
222
+ " <td>20.0</td>\n",
223
  " <td>18884.834</td>\n",
224
  " <td>64.4</td>\n",
225
  " <td>0.06</td>\n",
 
227
  " <td>23.4</td>\n",
228
  " <td>...</td>\n",
229
  " <td>71.0</td>\n",
230
+ " <td>69.0</td>\n",
231
  " <td>23.145000</td>\n",
232
  " <td>123.8</td>\n",
233
  " <td>56.25</td>\n",
 
236
  " <td>123.42</td>\n",
237
  " <td>61.6</td>\n",
238
  " <td>122.36</td>\n",
 
239
  " </tr>\n",
240
  " <tr>\n",
241
  " <th>2072150</th>\n",
242
  " <td>2020-12-31 23:58:00</td>\n",
243
  " <td>100.0</td>\n",
244
  " <td>68.0</td>\n",
245
+ " <td>63.2</td>\n",
246
+ " <td>20.0</td>\n",
247
  " <td>18884.834</td>\n",
248
  " <td>64.4</td>\n",
249
  " <td>0.06</td>\n",
 
251
  " <td>23.4</td>\n",
252
  " <td>...</td>\n",
253
  " <td>71.0</td>\n",
254
+ " <td>69.0</td>\n",
255
  " <td>23.145000</td>\n",
256
  " <td>123.8</td>\n",
257
  " <td>56.25</td>\n",
 
260
  " <td>123.42</td>\n",
261
  " <td>61.6</td>\n",
262
  " <td>122.36</td>\n",
 
263
  " </tr>\n",
264
  " <tr>\n",
265
  " <th>2072151</th>\n",
266
  " <td>2020-12-31 23:59:00</td>\n",
267
  " <td>100.0</td>\n",
268
  " <td>68.0</td>\n",
269
+ " <td>63.2</td>\n",
270
+ " <td>20.0</td>\n",
271
  " <td>19345.508</td>\n",
272
  " <td>64.3</td>\n",
273
  " <td>0.06</td>\n",
 
275
  " <td>23.4</td>\n",
276
  " <td>...</td>\n",
277
  " <td>71.0</td>\n",
278
+ " <td>69.0</td>\n",
279
  " <td>23.145000</td>\n",
280
  " <td>123.8</td>\n",
281
  " <td>56.25</td>\n",
 
284
  " <td>123.42</td>\n",
285
  " <td>61.6</td>\n",
286
  " <td>122.36</td>\n",
 
287
  " </tr>\n",
288
  " <tr>\n",
289
  " <th>2072152</th>\n",
290
  " <td>2020-12-31 23:59:00</td>\n",
291
  " <td>100.0</td>\n",
292
  " <td>68.0</td>\n",
293
+ " <td>63.2</td>\n",
294
+ " <td>20.0</td>\n",
295
  " <td>19345.508</td>\n",
296
  " <td>64.3</td>\n",
297
  " <td>0.06</td>\n",
 
299
  " <td>23.4</td>\n",
300
  " <td>...</td>\n",
301
  " <td>71.0</td>\n",
302
+ " <td>69.0</td>\n",
303
  " <td>23.145000</td>\n",
304
  " <td>123.8</td>\n",
305
  " <td>56.25</td>\n",
 
308
  " <td>123.42</td>\n",
309
  " <td>61.6</td>\n",
310
  " <td>122.36</td>\n",
 
311
  " </tr>\n",
312
  " <tr>\n",
313
  " <th>2072153</th>\n",
314
  " <td>2021-01-01 00:00:00</td>\n",
315
  " <td>100.0</td>\n",
316
  " <td>68.0</td>\n",
317
+ " <td>63.2</td>\n",
318
+ " <td>20.0</td>\n",
319
  " <td>18650.232</td>\n",
320
  " <td>64.1</td>\n",
321
  " <td>0.06</td>\n",
 
323
  " <td>22.9</td>\n",
324
  " <td>...</td>\n",
325
  " <td>71.0</td>\n",
326
+ " <td>69.0</td>\n",
327
  " <td>23.788947</td>\n",
328
  " <td>123.8</td>\n",
329
  " <td>56.25</td>\n",
 
332
  " <td>123.42</td>\n",
333
  " <td>61.6</td>\n",
334
  " <td>122.36</td>\n",
 
335
  " </tr>\n",
336
  " </tbody>\n",
337
  "</table>\n",
338
+ "<p>2072154 rows Γ— 30 columns</p>\n",
339
  "</div>"
340
  ],
341
  "text/plain": [
342
+ " date zone_047_hw_valve rtu_004_sat_sp_tn \\\n",
343
  "0 2018-01-01 00:00:00 100.0 69.0 \n",
344
  "1 2018-01-01 00:01:00 100.0 69.0 \n",
345
  "2 2018-01-01 00:02:00 100.0 69.0 \n",
 
352
  "2072152 2020-12-31 23:59:00 100.0 68.0 \n",
353
  "2072153 2021-01-01 00:00:00 100.0 68.0 \n",
354
  "\n",
355
+ " zone_047_temp zone_047_fan_spd rtu_004_fltrd_sa_flow_tn \\\n",
356
+ "0 67.5 20.0 9265.604 \n",
357
+ "1 67.5 20.0 9265.604 \n",
358
+ "2 67.5 20.0 9708.240 \n",
359
+ "3 67.5 20.0 9611.638 \n",
360
+ "4 67.5 20.0 9215.110 \n",
361
  "... ... ... ... \n",
362
+ "2072149 63.2 20.0 18884.834 \n",
363
+ "2072150 63.2 20.0 18884.834 \n",
364
+ "2072151 63.2 20.0 19345.508 \n",
365
+ "2072152 63.2 20.0 19345.508 \n",
366
+ "2072153 63.2 20.0 18650.232 \n",
367
  "\n",
368
  " rtu_004_sa_temp rtu_004_pa_static_stpt_tn rtu_004_oa_flow_tn \\\n",
369
  "0 66.1 0.06 0.000000 \n",
 
378
  "2072152 64.3 0.06 3154.390000 \n",
379
  "2072153 64.1 0.06 3076.270000 \n",
380
  "\n",
381
+ " rtu_004_oadmpr_pct ... zone_047_heating_sp Unnamed: 47_y \\\n",
382
+ "0 28.0 ... NaN NaN \n",
383
+ "1 28.0 ... NaN NaN \n",
384
+ "2 28.0 ... NaN NaN \n",
385
+ "3 28.0 ... NaN NaN \n",
386
+ "4 28.0 ... NaN NaN \n",
387
+ "... ... ... ... ... \n",
388
+ "2072149 23.4 ... 71.0 69.0 \n",
389
+ "2072150 23.4 ... 71.0 69.0 \n",
390
+ "2072151 23.4 ... 71.0 69.0 \n",
391
+ "2072152 23.4 ... 71.0 69.0 \n",
392
+ "2072153 22.9 ... 71.0 69.0 \n",
393
  "\n",
394
+ " hvac_S hp_hws_temp aru_001_cwr_temp aru_001_cws_fr_gpm \\\n",
395
+ "0 NaN 75.3 NaN NaN \n",
396
+ "1 NaN 75.3 NaN NaN \n",
397
+ "2 NaN 75.3 NaN NaN \n",
398
+ "3 NaN 75.3 NaN NaN \n",
399
+ "4 NaN 75.3 NaN NaN \n",
400
+ "... ... ... ... ... \n",
401
+ "2072149 23.145000 123.8 56.25 54.71 \n",
402
+ "2072150 23.145000 123.8 56.25 54.71 \n",
403
+ "2072151 23.145000 123.8 56.25 54.71 \n",
404
+ "2072152 23.145000 123.8 56.25 54.71 \n",
405
+ "2072153 23.788947 123.8 56.25 54.71 \n",
406
  "\n",
407
+ " aru_001_cws_temp aru_001_hwr_temp aru_001_hws_fr_gpm \\\n",
408
+ "0 NaN NaN NaN \n",
409
+ "1 NaN NaN NaN \n",
410
+ "2 NaN NaN NaN \n",
411
+ "3 NaN NaN NaN \n",
412
+ "4 NaN NaN NaN \n",
413
+ "... ... ... ... \n",
414
+ "2072149 56.4 123.42 61.6 \n",
415
+ "2072150 56.4 123.42 61.6 \n",
416
+ "2072151 56.4 123.42 61.6 \n",
417
+ "2072152 56.4 123.42 61.6 \n",
418
+ "2072153 56.4 123.42 61.6 \n",
419
  "\n",
420
+ " aru_001_hws_temp \n",
421
+ "0 NaN \n",
422
+ "1 NaN \n",
423
+ "2 NaN \n",
424
+ "3 NaN \n",
425
+ "4 NaN \n",
426
+ "... ... \n",
427
+ "2072149 122.36 \n",
428
+ "2072150 122.36 \n",
429
+ "2072151 122.36 \n",
430
+ "2072152 122.36 \n",
431
+ "2072153 122.36 \n",
432
+ "\n",
433
+ "[2072154 rows x 30 columns]"
434
  ]
435
  },
436
+ "execution_count": 3,
437
  "metadata": {},
438
  "output_type": "execute_result"
439
  }
440
  ],
441
  "source": [
442
+ "merged = pd.read_csv(r'C:\\Users\\jerin\\Downloads\\lbnlbldg59\\lbnlbldg59\\lbnlbldg59.processed\\LBNLBLDG59\\clean_Bldg59_2018to2020\\clean data\\long_merge.csv')\n",
443
  "\n",
444
+ "zone = \"47\"\n",
445
  "\n",
446
  "if zone in [\"36\", \"37\", \"38\", \"39\", \"40\", \"41\", \"42\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\", \"70\"]:\n",
447
  " rtu = \"rtu_001\"\n",
 
456
  " rtu = \"rtu_002\"\n",
457
  " wing = \"hvac_N\"\n",
458
  "#merged is the dataframe\n",
459
+ "sorted = merged[[\"date\"]+[col for col in merged.columns if zone in col or rtu in col or wing in col]+[\"hp_hws_temp\", \"aru_001_cwr_temp\" , \"aru_001_cws_fr_gpm\" ,\"aru_001_cws_temp\",\"aru_001_hwr_temp\" ,\"aru_001_hws_fr_gpm\" ,\"aru_001_hws_temp\"]]\n",
460
  "sorted"
461
  ]
462
  },
463
+ {
464
+ "cell_type": "code",
465
+ "execution_count": 100,
466
+ "metadata": {},
467
+ "outputs": [],
468
+ "source": [
469
+ "correlation_matrix = sorted.loc[:, sorted.columns != 'date'].corr()\n",
470
+ "plt.figure(figsize=(15, 10))\n",
471
+ "sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt=\".2f\", linewidths=0.5)\n",
472
+ "plt.title('Pearson Correlation Coefficients')\n",
473
+ "plt.show()"
474
+ ]
475
+ },
476
+ {
477
+ "cell_type": "code",
478
+ "execution_count": 102,
479
+ "metadata": {},
480
+ "outputs": [
481
+ {
482
+ "name": "stdout",
483
+ "output_type": "stream",
484
+ "text": [
485
+ "zone_047_fan_spd ---- 0.3838842710385038 ---- zone_047_temp\n",
486
+ "rtu_004_sa_temp ---- 0.5636316174287519 ---- zone_047_temp\n",
487
+ "rtu_004_ra_temp ---- 0.32776265464886917 ---- zone_047_temp\n",
488
+ "rtu_004_oa_temp ---- 0.3911499150089511 ---- zone_047_temp\n",
489
+ "rtu_004_ma_temp ---- 0.3800818291020465 ---- zone_047_temp\n",
490
+ "hvac_S ---- 0.3163506114497974 ---- zone_047_hw_valve\n",
491
+ "hvac_S ---- 0.42500326788919984 ---- rtu_004_fltrd_sa_flow_tn\n",
492
+ "hvac_S ---- 0.4794994590105312 ---- rtu_004_oa_temp\n",
493
+ "hvac_S ---- 0.37653522078249596 ---- rtu_004_ma_temp\n",
494
+ "hvac_S ---- 0.45054590590454646 ---- rtu_004_sf_vfd_spd_fbk_tn\n",
495
+ "hvac_S ---- 0.3910776435479394 ---- rtu_004_rf_vfd_spd_fbk_tn\n",
496
+ "aru_001_cwr_temp ---- 0.4337890009515319 ---- zone_047_temp\n",
497
+ "aru_001_cwr_temp ---- 0.5103744910713975 ---- hvac_S\n",
498
+ "aru_001_cws_fr_gpm ---- 0.5251959795850137 ---- zone_047_temp\n",
499
+ "aru_001_cws_fr_gpm ---- 0.4816297584385553 ---- hvac_S\n",
500
+ "aru_001_cws_temp ---- 0.576461860142355 ---- zone_047_temp\n",
501
+ "aru_001_cws_temp ---- 0.5060071970556257 ---- hvac_S\n"
502
+ ]
503
+ }
504
+ ],
505
+ "source": [
506
+ "highly_correlated_cols = set()\n",
507
+ "for i in range(len(correlation_matrix.columns)):\n",
508
+ " for j in range(i):\n",
509
+ " if abs(correlation_matrix.iloc[i, j]) > 0.3:\n",
510
+ " colname_i = correlation_matrix.columns[i]\n",
511
+ " colname_j = correlation_matrix.columns[j]\n",
512
+ " if (colname_i != colname_j) and (colname_i==\"zone_047_temp\" or colname_j==\"zone_047_temp\" or colname_i==\"hvac_S\" or colname_j==\"hvac_S\"):\n",
513
+ " print(colname_i,\"----\",abs(correlation_matrix.iloc[i, j]),\"----\",colname_j)\n",
514
+ " highly_correlated_cols.add(colname_i)\n",
515
+ " highly_correlated_cols.add(colname_j)\n",
516
+ " \n",
517
+ " "
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 19,
523
+ "metadata": {},
524
+ "outputs": [
525
+ {
526
+ "data": {
527
+ "text/plain": [
528
+ "date 0\n",
529
+ "zone_047_hw_valve 0\n",
530
+ "rtu_004_sat_sp_tn 0\n",
531
+ "zone_047_temp 0\n",
532
+ "zone_047_fan_spd 0\n",
533
+ "rtu_004_fltrd_sa_flow_tn 0\n",
534
+ "rtu_004_sa_temp 0\n",
535
+ "rtu_004_pa_static_stpt_tn 0\n",
536
+ "rtu_004_oa_flow_tn 0\n",
537
+ "rtu_004_oadmpr_pct 0\n",
538
+ "rtu_004_econ_stpt_tn 0\n",
539
+ "rtu_004_ra_temp 0\n",
540
+ "rtu_004_oa_temp 0\n",
541
+ "rtu_004_ma_temp 0\n",
542
+ "rtu_004_sf_vfd_spd_fbk_tn 0\n",
543
+ "rtu_004_rf_vfd_spd_fbk_tn 0\n",
544
+ "rtu_004_fltrd_gnd_lvl_plenum_press_tn 0\n",
545
+ "rtu_004_fltrd_lvl2_plenum_press_tn 0\n",
546
+ "zone_047_cooling_sp 0\n",
547
+ "Unnamed: 47_x 0\n",
548
+ "zone_047_heating_sp 0\n",
549
+ "Unnamed: 47_y 0\n",
550
+ "hvac_S 0\n",
551
+ "hp_hws_temp 0\n",
552
+ "aru_001_cwr_temp 667858\n",
553
+ "aru_001_cws_fr_gpm 667858\n",
554
+ "aru_001_cws_temp 667858\n",
555
+ "aru_001_hwr_temp 0\n",
556
+ "aru_001_hws_fr_gpm 0\n",
557
+ "aru_001_hws_temp 0\n",
558
+ "dtype: int64"
559
+ ]
560
+ },
561
+ "execution_count": 19,
562
+ "metadata": {},
563
+ "output_type": "execute_result"
564
+ }
565
+ ],
566
+ "source": [
567
+ "final_df = sorted.copy()\n",
568
+ "final_df['date'] = pd.to_datetime(final_df['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
569
+ "final_df = final_df[ (final_df.date.dt.date >date(2020, 1, 1)) & (final_df.date.dt.date< date(2020, 12, 30))]\n",
570
+ "final_df.isna().sum()"
571
+ ]
572
+ },
573
+ {
574
+ "cell_type": "code",
575
+ "execution_count": 29,
576
+ "metadata": {},
577
+ "outputs": [],
578
+ "source": [
579
+ "%matplotlib qt\n",
580
+ "for i in final_df.columns[11:14]:\n",
581
+ " plt.plot(final_df['date'],final_df[i])\n",
582
+ "plt.show()"
583
+ ]
584
+ },
585
+ {
586
+ "cell_type": "code",
587
+ "execution_count": 7,
588
+ "metadata": {},
589
+ "outputs": [
590
+ {
591
+ "name": "stderr",
592
+ "output_type": "stream",
593
+ "text": [
594
+ "c:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\keras\\src\\layers\\rnn\\rnn.py:205: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
595
+ " super().__init__(**kwargs)\n"
596
+ ]
597
+ },
598
+ {
599
+ "name": "stdout",
600
+ "output_type": "stream",
601
+ "text": [
602
+ "Epoch 1/2\n",
603
+ "\u001b[1m12174/12174\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m811s\u001b[0m 66ms/step - loss: 0.0019 - val_loss: 9.6280e-04\n",
604
+ "Epoch 2/2\n",
605
+ "\u001b[1m12174/12174\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m814s\u001b[0m 67ms/step - loss: 7.9909e-04 - val_loss: 7.6609e-04\n",
606
+ "\u001b[1m24348/24348\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m120s\u001b[0m 5ms/step\n",
607
+ "\u001b[1m10434/10434\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m58s\u001b[0m 6ms/step\n"
608
+ ]
609
+ }
610
+ ],
611
+ "source": [
612
+ "\n",
613
+ "dataset = final_df[['rtu_004_oa_temp','rtu_004_ra_temp','hp_hws_temp','rtu_004_ma_temp','rtu_004_sa_temp']].values\n",
614
+ "\n",
615
+ "# dataset = final_df[['hvac_S','rtu_004_ra_temp','rtu_004_oa_temp','rtu_004_ma_temp','rtu_004_fltrd_sa_flow_tn',\n",
616
+ "# 'rtu_004_sf_vfd_spd_fbk_tn','rtu_004_rf_vfd_spd_fbk_tn','zone_047_temp']].values\n",
617
+ "# dataset = final_df[['rtu_004_fltrd_sa_flow_tn','rtu_004_sf_vfd_spd_fbk_tn','rtu_004_rf_vfd_spd_fbk_tn',\n",
618
+ "# 'rtu_004_oa_temp','rtu_004_ma_temp','zone_047_fan_spd','zone_047_hw_valve','rtu_004_sa_temp','zone_047_temp']].values\n",
619
+ "dataset = dataset.astype('float32')\n",
620
+ "\n",
621
+ "\n",
622
+ "scaler = MinMaxScaler(feature_range=(0, 1))\n",
623
+ "dataset = scaler.fit_transform(dataset)\n",
624
+ "train_size = int(len(dataset)* 0.30)\n",
625
+ "test_size = len(dataset) - train_size\n",
626
+ "test,train = dataset[0:train_size,:],dataset[train_size:len(dataset),:]\n",
627
+ "\n",
628
+ "def create_dataset(dataset,time_step):\n",
629
+ " # x1,x2,x3,x4,x5,x6,x7, Y = [],[],[],[],[],[],[],[]\n",
630
+ " x1,x2,x3,Y = [],[],[],[]\n",
631
+ " for i in range(len(dataset)-time_step-1):\n",
632
+ " x1.append(dataset[i:(i+time_step), 0])\n",
633
+ " x2.append(dataset[i:(i+time_step), 1])\n",
634
+ " x3.append(dataset[i:(i+time_step), 2])\n",
635
+ " # x4.append(dataset[i:(i+time_step), 3])\n",
636
+ " # x5.append(dataset[i:(i+time_step), 4])\n",
637
+ " # x6.append(dataset[i:(i+time_step), 5])\n",
638
+ " # x7.append(dataset[i:(i+time_step), 6])\n",
639
+ " Y.append([dataset[i + time_step, 3],dataset[i + time_step, 4]])\n",
640
+ " # x1,x2,x3,x4,x5,x6,x7,Y = np.array(x1),np.array(x2),np.array(x3), np.array(x4),np.array(x5),np.array(x6),np.array(x7),np.array(Y)\n",
641
+ " x1,x2,x3,Y = np.array(x1),np.array(x2),np.array(x3),np.array(Y)\n",
642
+ " # Y = np.reshape(Y,(len(Y),1))\n",
643
+ " return np.stack([x1,x2,x3],axis=2),Y\n",
644
+ "\n",
645
+ "\n",
646
+ "\n",
647
+ "\n",
648
+ "time_step = 60\n",
649
+ "X_train, y_train = create_dataset(train, time_step)\n",
650
+ "X_test, y_test = create_dataset(test, time_step)\n",
651
+ "\n",
652
+ "\n",
653
+ "model = Sequential()\n",
654
+ "model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
655
+ "model.add(LSTM(units=50))\n",
656
+ "model.add(Dense(units=2))\n",
657
+ "\n",
658
+ "model.compile(optimizer='adam', loss='mean_squared_error')\n",
659
+ "\n",
660
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=5, batch_size=64, verbose=1)\n",
661
+ "\n",
662
+ "train_predict = model.predict(X_train)\n",
663
+ "test_predict = model.predict(X_test)\n"
664
+ ]
665
+ },
666
+ {
667
+ "cell_type": "code",
668
+ "execution_count": 18,
669
+ "metadata": {},
670
+ "outputs": [],
671
+ "source": [
672
+ "%matplotlib qt\n",
673
+ "\n",
674
+ "# plt.plot(y_test[:,0], label='Original Testing Data', color='blue')\n",
675
+ "# plt.plot(test_predict[:,0], label='Predicted Testing Data', color='red')\n",
676
+ "plt.plot(y_test[:,1], label='Original Testing Data', color='green')\n",
677
+ "plt.plot(test_predict[:,1], label='Predicted Testing Data', color='orange')\n",
678
+ "anomalies = np.where(abs(test_predict[:,1] - y_test[:,0]) > 0.5)[0]\n",
679
+ "plt.scatter(anomalies,test_predict[anomalies,1], color='black',marker =\"o\",s=100 )\n",
680
+ "plt.title('Testing Data - Predicted vs Actual')\n",
681
+ "plt.xlabel('Time')\n",
682
+ "plt.ylabel('Value')\n",
683
+ "plt.legend()\n",
684
+ "plt.show()"
685
+ ]
686
+ },
687
+ {
688
+ "cell_type": "markdown",
689
+ "metadata": {},
690
+ "source": [
691
+ "LSTM autoencoder"
692
+ ]
693
+ },
694
+ {
695
+ "cell_type": "markdown",
696
+ "metadata": {},
697
+ "source": [
698
+ "----------------------------"
699
+ ]
700
+ },
701
+ {
702
+ "cell_type": "code",
703
+ "execution_count": 246,
704
+ "metadata": {},
705
+ "outputs": [
706
+ {
707
+ "name": "stderr",
708
+ "output_type": "stream",
709
+ "text": [
710
+ "c:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\keras\\src\\layers\\rnn\\rnn.py:205: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
711
+ " super().__init__(**kwargs)\n"
712
+ ]
713
+ },
714
+ {
715
+ "name": "stdout",
716
+ "output_type": "stream",
717
+ "text": [
718
+ "\u001b[1m11487/24348\u001b[0m \u001b[32m━━━━━━━━━\u001b[0m\u001b[37m━━━━━━━━━━━\u001b[0m \u001b[1m2:07\u001b[0m 10ms/step"
719
+ ]
720
+ },
721
+ {
722
+ "ename": "",
723
+ "evalue": "",
724
+ "output_type": "error",
725
+ "traceback": [
726
+ "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
727
+ "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
728
+ "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
729
+ "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
730
+ ]
731
+ }
732
+ ],
733
+ "source": [
734
+ "\n",
735
+ "# dataset = final_df[['zone_047_temp','hvac_S','rtu_004_sa_temp']].values\n",
736
+ "\n",
737
+ "# dataset = final_df[['hvac_S','rtu_004_ra_temp','rtu_004_oa_temp','rtu_004_ma_temp','rtu_004_fltrd_sa_flow_tn',\n",
738
+ "# 'rtu_004_sf_vfd_spd_fbk_tn','rtu_004_rf_vfd_spd_fbk_tn','zone_047_temp']].values\n",
739
+ "dataset = final_df[['rtu_004_fltrd_sa_flow_tn','rtu_004_sf_vfd_spd_fbk_tn','rtu_004_rf_vfd_spd_fbk_tn',\n",
740
+ " 'rtu_004_oa_temp','rtu_004_ma_temp','zone_047_fan_spd','zone_047_hw_valve','rtu_004_ra_temp','rtu_004_sa_temp','zone_047_temp']].values\n",
741
+ "dataset = dataset.astype('float32')\n",
742
+ "\n",
743
+ "\n",
744
+ "scaler = MinMaxScaler(feature_range=(0, 1))\n",
745
+ "dataset = scaler.fit_transform(dataset)\n",
746
+ "test_size = int(len(dataset)* 0.30)\n",
747
+ "test, train = dataset[0:test_size,:],dataset[test_size:len(dataset),:]\n",
748
+ "\n",
749
+ "def create_dataset(dataset,time_step):\n",
750
+ " x1,x2,x3,x4,x5,x6,x7,x8,x9, Y = [],[],[],[],[],[],[],[],[],[]\n",
751
+ "\n",
752
+ " for i in range(0,len(dataset)-time_step-1):\n",
753
+ " x1.append(dataset[i:(i+time_step), 0])\n",
754
+ " x2.append(dataset[i:(i+time_step), 1])\n",
755
+ " x3.append(dataset[i:(i+time_step), 2])\n",
756
+ " x4.append(dataset[i:(i+time_step), 3])\n",
757
+ " x5.append(dataset[i:(i+time_step), 4])\n",
758
+ " x6.append(dataset[i:(i+time_step), 5])\n",
759
+ " x7.append(dataset[i:(i+time_step), 6])\n",
760
+ " x8.append(dataset[i:(i+time_step), 7])\n",
761
+ " x9.append(dataset[i:(i+time_step), 8])\n",
762
+ " Y.append(dataset[i:(i+time_step), 8])\n",
763
+ " x1,x2,x3,x4,x5,x6,x7,x8,x9,Y = np.array(x1),np.array(x2),np.array(x3), np.array(x4),np.array(x5),np.array(x6),np.array(x7),np.array(x8),np.array(x9),np.array(Y)\n",
764
+ " \n",
765
+ " # Y = np.reshape(Y,(len(Y),1))\n",
766
+ " return np.stack([x1,x2,x3,x4,x5,x6,x7,x8,x9],axis=2),Y\n",
767
+ "\n",
768
+ "\n",
769
+ "\n",
770
+ "\n",
771
+ "time_step = 60\n",
772
+ "X_train, y_train = create_dataset(train, time_step)\n",
773
+ "X_test, y_test = create_dataset(test, time_step)\n",
774
+ "\n",
775
+ "\n",
776
+ "model = Sequential()\n",
777
+ "model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
778
+ "# model.add(LSTM(units=30))\n",
779
+ "# model.add(Dense(units=time_step))\n",
780
+ "\n",
781
+ "model.compile(optimizer='adam', loss='mean_squared_error')\n",
782
+ "\n",
783
+ "# model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=2, batch_size=64, verbose=1)\n",
784
+ "\n",
785
+ "train_predict = model.predict(X_train)\n",
786
+ "# test_predict = model.predict(X_test)\n"
787
+ ]
788
+ },
789
+ {
790
+ "cell_type": "code",
791
+ "execution_count": 244,
792
+ "metadata": {},
793
+ "outputs": [
794
+ {
795
+ "data": {
796
+ "text/plain": [
797
+ "(779111, 60, 9)"
798
+ ]
799
+ },
800
+ "execution_count": 244,
801
+ "metadata": {},
802
+ "output_type": "execute_result"
803
+ }
804
+ ],
805
+ "source": [
806
+ "X_train.shape"
807
+ ]
808
+ },
809
+ {
810
+ "cell_type": "code",
811
+ "execution_count": null,
812
+ "metadata": {},
813
+ "outputs": [],
814
+ "source": [
815
+ "mo"
816
+ ]
817
+ },
818
+ {
819
+ "cell_type": "code",
820
+ "execution_count": 241,
821
+ "metadata": {},
822
+ "outputs": [],
823
+ "source": [
824
+ "%matplotlib qt\n",
825
+ "time = 10\n",
826
+ "mse = (y_test[time] - test_predict[0])**2\n",
827
+ "anomalies = np.where(mse > 0.0001)[0]\n",
828
+ "plt.plot(y_test[time], label='Original Data')\n",
829
+ "plt.plot(test_predict[time], label='predicted Data')\n",
830
+ "plt.scatter(anomalies,test_predict[time,anomalies], color='red', label='Anomalies')\n",
831
+ "plt.legend()\n",
832
+ "plt.show()"
833
+ ]
834
+ },
835
+ {
836
+ "cell_type": "code",
837
+ "execution_count": 242,
838
+ "metadata": {},
839
+ "outputs": [
840
+ {
841
+ "data": {
842
+ "text/html": [
843
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Model: \"sequential_19\"</span>\n",
844
+ "</pre>\n"
845
+ ],
846
+ "text/plain": [
847
+ "\u001b[1mModel: \"sequential_19\"\u001b[0m\n"
848
+ ]
849
+ },
850
+ "metadata": {},
851
+ "output_type": "display_data"
852
+ },
853
+ {
854
+ "data": {
855
+ "text/html": [
856
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
857
+ "┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Output Shape </span>┃<span style=\"font-weight: bold\"> Param # </span>┃\n",
858
+ "┑━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
859
+ "β”‚ lstm_39 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">LSTM</span>) β”‚ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">60</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">50</span>) β”‚ <span style=\"color: #00af00; text-decoration-color: #00af00\">12,000</span> β”‚\n",
860
+ "β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€\n",
861
+ "β”‚ lstm_40 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">LSTM</span>) β”‚ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">30</span>) β”‚ <span style=\"color: #00af00; text-decoration-color: #00af00\">9,720</span> β”‚\n",
862
+ "β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€\n",
863
+ "β”‚ dense_26 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) β”‚ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">60</span>) β”‚ <span style=\"color: #00af00; text-decoration-color: #00af00\">1,860</span> β”‚\n",
864
+ "β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\n",
865
+ "</pre>\n"
866
+ ],
867
+ "text/plain": [
868
+ "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
869
+ "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n",
870
+ "┑━━━━━━━━━━━━━━━━━━━���━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
871
+ "β”‚ lstm_39 (\u001b[38;5;33mLSTM\u001b[0m) β”‚ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m60\u001b[0m, \u001b[38;5;34m50\u001b[0m) β”‚ \u001b[38;5;34m12,000\u001b[0m β”‚\n",
872
+ "β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€\n",
873
+ "β”‚ lstm_40 (\u001b[38;5;33mLSTM\u001b[0m) β”‚ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m30\u001b[0m) β”‚ \u001b[38;5;34m9,720\u001b[0m β”‚\n",
874
+ "β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€\n",
875
+ "β”‚ dense_26 (\u001b[38;5;33mDense\u001b[0m) β”‚ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m60\u001b[0m) β”‚ \u001b[38;5;34m1,860\u001b[0m β”‚\n",
876
+ "β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\n"
877
+ ]
878
+ },
879
+ "metadata": {},
880
+ "output_type": "display_data"
881
+ },
882
+ {
883
+ "data": {
884
+ "text/html": [
885
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">70,742</span> (276.34 KB)\n",
886
+ "</pre>\n"
887
+ ],
888
+ "text/plain": [
889
+ "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m70,742\u001b[0m (276.34 KB)\n"
890
+ ]
891
+ },
892
+ "metadata": {},
893
+ "output_type": "display_data"
894
+ },
895
+ {
896
+ "data": {
897
+ "text/html": [
898
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">23,580</span> (92.11 KB)\n",
899
+ "</pre>\n"
900
+ ],
901
+ "text/plain": [
902
+ "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m23,580\u001b[0m (92.11 KB)\n"
903
+ ]
904
+ },
905
+ "metadata": {},
906
+ "output_type": "display_data"
907
+ },
908
+ {
909
+ "data": {
910
+ "text/html": [
911
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> (0.00 B)\n",
912
+ "</pre>\n"
913
+ ],
914
+ "text/plain": [
915
+ "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n"
916
+ ]
917
+ },
918
+ "metadata": {},
919
+ "output_type": "display_data"
920
+ },
921
+ {
922
+ "data": {
923
+ "text/html": [
924
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Optimizer params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">47,162</span> (184.23 KB)\n",
925
+ "</pre>\n"
926
+ ],
927
+ "text/plain": [
928
+ "\u001b[1m Optimizer params: \u001b[0m\u001b[38;5;34m47,162\u001b[0m (184.23 KB)\n"
929
+ ]
930
+ },
931
+ "metadata": {},
932
+ "output_type": "display_data"
933
+ }
934
+ ],
935
+ "source": [
936
+ "model.summary()"
937
+ ]
938
+ },
939
+ {
940
+ "cell_type": "code",
941
+ "execution_count": 238,
942
+ "metadata": {},
943
+ "outputs": [
944
+ {
945
+ "data": {
946
+ "text/plain": [
947
+ "array([-0.00162351, -0.00127119, -0.00132501, -0.00043088, -0.00357354,\n",
948
+ " -0.00349951, -0.00703096, -0.00679523, 0.00243503, 0.00075096,\n",
949
+ " 0.015773 , 0.01411158, 0.01689583, 0.01593572, 0.00665802,\n",
950
+ " 0.0068891 , -0.001706 , -0.00310844, -0.00871575, -0.00967073,\n",
951
+ " -0.00820547, -0.00687617, 0.00930512, 0.00670969, 0.00769156,\n",
952
+ " 0.01000088, -0.00052458, 0.00010484, -0.00573552, -0.00811213,\n",
953
+ " -0.01016176, -0.01063424, -0.01580012, -0.01502603, -0.01243931,\n",
954
+ " -0.01488668, 0.00733459, 0.00564003, 0.01374102, 0.01534522,\n",
955
+ " 0.00324941, 0.00375515, -0.0078848 , -0.00780392, -0.01223874,\n",
956
+ " -0.01329106, -0.00772917, -0.00823385, 0.01035273, 0.01039612,\n",
957
+ " 0.01731664, 0.01493615, 0.00356281, 0.00522107, -0.00680918,\n",
958
+ " -0.00461727, -0.00997645, -0.01072395, -0.00542653, -0.00710839],\n",
959
+ " dtype=float32)"
960
+ ]
961
+ },
962
+ "execution_count": 238,
963
+ "metadata": {},
964
+ "output_type": "execute_result"
965
+ }
966
+ ],
967
+ "source": [
968
+ "test_predict[0]-y_test[0]"
969
+ ]
970
+ },
971
  {
972
  "cell_type": "code",
973
  "execution_count": null,