jerin commited on
Commit
81c7365
β€’
1 Parent(s): 830ab0c

add new lstm workbook

Browse files
Files changed (1) hide show
  1. lstm.ipynb +1310 -0
lstm.ipynb ADDED
@@ -0,0 +1,1310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
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
+ "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
+ "from keras.callbacks import ModelCheckpoint\n"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 2,
26
+ "metadata": {},
27
+ "outputs": [
28
+ {
29
+ "data": {
30
+ "text/html": [
31
+ "<div>\n",
32
+ "<style scoped>\n",
33
+ " .dataframe tbody tr th:only-of-type {\n",
34
+ " vertical-align: middle;\n",
35
+ " }\n",
36
+ "\n",
37
+ " .dataframe tbody tr th {\n",
38
+ " vertical-align: top;\n",
39
+ " }\n",
40
+ "\n",
41
+ " .dataframe thead th {\n",
42
+ " text-align: right;\n",
43
+ " }\n",
44
+ "</style>\n",
45
+ "<table border=\"1\" class=\"dataframe\">\n",
46
+ " <thead>\n",
47
+ " <tr style=\"text-align: right;\">\n",
48
+ " <th></th>\n",
49
+ " <th>date</th>\n",
50
+ " <th>zone_047_hw_valve</th>\n",
51
+ " <th>rtu_004_sat_sp_tn</th>\n",
52
+ " <th>zone_047_temp</th>\n",
53
+ " <th>zone_047_fan_spd</th>\n",
54
+ " <th>rtu_004_fltrd_sa_flow_tn</th>\n",
55
+ " <th>rtu_004_sa_temp</th>\n",
56
+ " <th>rtu_004_pa_static_stpt_tn</th>\n",
57
+ " <th>rtu_004_oa_flow_tn</th>\n",
58
+ " <th>rtu_004_oadmpr_pct</th>\n",
59
+ " <th>...</th>\n",
60
+ " <th>zone_047_heating_sp</th>\n",
61
+ " <th>Unnamed: 47_y</th>\n",
62
+ " <th>hvac_S</th>\n",
63
+ " <th>hp_hws_temp</th>\n",
64
+ " <th>aru_001_cwr_temp</th>\n",
65
+ " <th>aru_001_cws_fr_gpm</th>\n",
66
+ " <th>aru_001_cws_temp</th>\n",
67
+ " <th>aru_001_hwr_temp</th>\n",
68
+ " <th>aru_001_hws_fr_gpm</th>\n",
69
+ " <th>aru_001_hws_temp</th>\n",
70
+ " </tr>\n",
71
+ " </thead>\n",
72
+ " <tbody>\n",
73
+ " <tr>\n",
74
+ " <th>0</th>\n",
75
+ " <td>2018-01-01 00:00:00</td>\n",
76
+ " <td>100.0</td>\n",
77
+ " <td>69.0</td>\n",
78
+ " <td>67.5</td>\n",
79
+ " <td>20.0</td>\n",
80
+ " <td>9265.604</td>\n",
81
+ " <td>66.1</td>\n",
82
+ " <td>0.06</td>\n",
83
+ " <td>0.000000</td>\n",
84
+ " <td>28.0</td>\n",
85
+ " <td>...</td>\n",
86
+ " <td>NaN</td>\n",
87
+ " <td>NaN</td>\n",
88
+ " <td>NaN</td>\n",
89
+ " <td>75.3</td>\n",
90
+ " <td>NaN</td>\n",
91
+ " <td>NaN</td>\n",
92
+ " <td>NaN</td>\n",
93
+ " <td>NaN</td>\n",
94
+ " <td>NaN</td>\n",
95
+ " <td>NaN</td>\n",
96
+ " </tr>\n",
97
+ " <tr>\n",
98
+ " <th>1</th>\n",
99
+ " <td>2018-01-01 00:01:00</td>\n",
100
+ " <td>100.0</td>\n",
101
+ " <td>69.0</td>\n",
102
+ " <td>67.5</td>\n",
103
+ " <td>20.0</td>\n",
104
+ " <td>9265.604</td>\n",
105
+ " <td>66.0</td>\n",
106
+ " <td>0.06</td>\n",
107
+ " <td>6572.099162</td>\n",
108
+ " <td>28.0</td>\n",
109
+ " <td>...</td>\n",
110
+ " <td>NaN</td>\n",
111
+ " <td>NaN</td>\n",
112
+ " <td>NaN</td>\n",
113
+ " <td>75.3</td>\n",
114
+ " <td>NaN</td>\n",
115
+ " <td>NaN</td>\n",
116
+ " <td>NaN</td>\n",
117
+ " <td>NaN</td>\n",
118
+ " <td>NaN</td>\n",
119
+ " <td>NaN</td>\n",
120
+ " </tr>\n",
121
+ " <tr>\n",
122
+ " <th>2</th>\n",
123
+ " <td>2018-01-01 00:02:00</td>\n",
124
+ " <td>100.0</td>\n",
125
+ " <td>69.0</td>\n",
126
+ " <td>67.5</td>\n",
127
+ " <td>20.0</td>\n",
128
+ " <td>9708.240</td>\n",
129
+ " <td>66.1</td>\n",
130
+ " <td>0.06</td>\n",
131
+ " <td>7628.832542</td>\n",
132
+ " <td>28.0</td>\n",
133
+ " <td>...</td>\n",
134
+ " <td>NaN</td>\n",
135
+ " <td>NaN</td>\n",
136
+ " <td>NaN</td>\n",
137
+ " <td>75.3</td>\n",
138
+ " <td>NaN</td>\n",
139
+ " <td>NaN</td>\n",
140
+ " <td>NaN</td>\n",
141
+ " <td>NaN</td>\n",
142
+ " <td>NaN</td>\n",
143
+ " <td>NaN</td>\n",
144
+ " </tr>\n",
145
+ " <tr>\n",
146
+ " <th>3</th>\n",
147
+ " <td>2018-01-01 00:03:00</td>\n",
148
+ " <td>100.0</td>\n",
149
+ " <td>69.0</td>\n",
150
+ " <td>67.5</td>\n",
151
+ " <td>20.0</td>\n",
152
+ " <td>9611.638</td>\n",
153
+ " <td>66.1</td>\n",
154
+ " <td>0.06</td>\n",
155
+ " <td>7710.294617</td>\n",
156
+ " <td>28.0</td>\n",
157
+ " <td>...</td>\n",
158
+ " <td>NaN</td>\n",
159
+ " <td>NaN</td>\n",
160
+ " <td>NaN</td>\n",
161
+ " <td>75.3</td>\n",
162
+ " <td>NaN</td>\n",
163
+ " <td>NaN</td>\n",
164
+ " <td>NaN</td>\n",
165
+ " <td>NaN</td>\n",
166
+ " <td>NaN</td>\n",
167
+ " <td>NaN</td>\n",
168
+ " </tr>\n",
169
+ " <tr>\n",
170
+ " <th>4</th>\n",
171
+ " <td>2018-01-01 00:04:00</td>\n",
172
+ " <td>100.0</td>\n",
173
+ " <td>69.0</td>\n",
174
+ " <td>67.5</td>\n",
175
+ " <td>20.0</td>\n",
176
+ " <td>9215.110</td>\n",
177
+ " <td>66.0</td>\n",
178
+ " <td>0.06</td>\n",
179
+ " <td>7139.184090</td>\n",
180
+ " <td>28.0</td>\n",
181
+ " <td>...</td>\n",
182
+ " <td>NaN</td>\n",
183
+ " <td>NaN</td>\n",
184
+ " <td>NaN</td>\n",
185
+ " <td>75.3</td>\n",
186
+ " <td>NaN</td>\n",
187
+ " <td>NaN</td>\n",
188
+ " <td>NaN</td>\n",
189
+ " <td>NaN</td>\n",
190
+ " <td>NaN</td>\n",
191
+ " <td>NaN</td>\n",
192
+ " </tr>\n",
193
+ " <tr>\n",
194
+ " <th>...</th>\n",
195
+ " <td>...</td>\n",
196
+ " <td>...</td>\n",
197
+ " <td>...</td>\n",
198
+ " <td>...</td>\n",
199
+ " <td>...</td>\n",
200
+ " <td>...</td>\n",
201
+ " <td>...</td>\n",
202
+ " <td>...</td>\n",
203
+ " <td>...</td>\n",
204
+ " <td>...</td>\n",
205
+ " <td>...</td>\n",
206
+ " <td>...</td>\n",
207
+ " <td>...</td>\n",
208
+ " <td>...</td>\n",
209
+ " <td>...</td>\n",
210
+ " <td>...</td>\n",
211
+ " <td>...</td>\n",
212
+ " <td>...</td>\n",
213
+ " <td>...</td>\n",
214
+ " <td>...</td>\n",
215
+ " <td>...</td>\n",
216
+ " </tr>\n",
217
+ " <tr>\n",
218
+ " <th>2072149</th>\n",
219
+ " <td>2020-12-31 23:58:00</td>\n",
220
+ " <td>100.0</td>\n",
221
+ " <td>68.0</td>\n",
222
+ " <td>63.2</td>\n",
223
+ " <td>20.0</td>\n",
224
+ " <td>18884.834</td>\n",
225
+ " <td>64.4</td>\n",
226
+ " <td>0.06</td>\n",
227
+ " <td>2938.320000</td>\n",
228
+ " <td>23.4</td>\n",
229
+ " <td>...</td>\n",
230
+ " <td>71.0</td>\n",
231
+ " <td>69.0</td>\n",
232
+ " <td>23.145000</td>\n",
233
+ " <td>123.8</td>\n",
234
+ " <td>56.25</td>\n",
235
+ " <td>54.71</td>\n",
236
+ " <td>56.4</td>\n",
237
+ " <td>123.42</td>\n",
238
+ " <td>61.6</td>\n",
239
+ " <td>122.36</td>\n",
240
+ " </tr>\n",
241
+ " <tr>\n",
242
+ " <th>2072150</th>\n",
243
+ " <td>2020-12-31 23:58:00</td>\n",
244
+ " <td>100.0</td>\n",
245
+ " <td>68.0</td>\n",
246
+ " <td>63.2</td>\n",
247
+ " <td>20.0</td>\n",
248
+ " <td>18884.834</td>\n",
249
+ " <td>64.4</td>\n",
250
+ " <td>0.06</td>\n",
251
+ " <td>2938.320000</td>\n",
252
+ " <td>23.4</td>\n",
253
+ " <td>...</td>\n",
254
+ " <td>71.0</td>\n",
255
+ " <td>69.0</td>\n",
256
+ " <td>23.145000</td>\n",
257
+ " <td>123.8</td>\n",
258
+ " <td>56.25</td>\n",
259
+ " <td>54.71</td>\n",
260
+ " <td>56.4</td>\n",
261
+ " <td>123.42</td>\n",
262
+ " <td>61.6</td>\n",
263
+ " <td>122.36</td>\n",
264
+ " </tr>\n",
265
+ " <tr>\n",
266
+ " <th>2072151</th>\n",
267
+ " <td>2020-12-31 23:59:00</td>\n",
268
+ " <td>100.0</td>\n",
269
+ " <td>68.0</td>\n",
270
+ " <td>63.2</td>\n",
271
+ " <td>20.0</td>\n",
272
+ " <td>19345.508</td>\n",
273
+ " <td>64.3</td>\n",
274
+ " <td>0.06</td>\n",
275
+ " <td>3154.390000</td>\n",
276
+ " <td>23.4</td>\n",
277
+ " <td>...</td>\n",
278
+ " <td>71.0</td>\n",
279
+ " <td>69.0</td>\n",
280
+ " <td>23.145000</td>\n",
281
+ " <td>123.8</td>\n",
282
+ " <td>56.25</td>\n",
283
+ " <td>54.71</td>\n",
284
+ " <td>56.4</td>\n",
285
+ " <td>123.42</td>\n",
286
+ " <td>61.6</td>\n",
287
+ " <td>122.36</td>\n",
288
+ " </tr>\n",
289
+ " <tr>\n",
290
+ " <th>2072152</th>\n",
291
+ " <td>2020-12-31 23:59:00</td>\n",
292
+ " <td>100.0</td>\n",
293
+ " <td>68.0</td>\n",
294
+ " <td>63.2</td>\n",
295
+ " <td>20.0</td>\n",
296
+ " <td>19345.508</td>\n",
297
+ " <td>64.3</td>\n",
298
+ " <td>0.06</td>\n",
299
+ " <td>3154.390000</td>\n",
300
+ " <td>23.4</td>\n",
301
+ " <td>...</td>\n",
302
+ " <td>71.0</td>\n",
303
+ " <td>69.0</td>\n",
304
+ " <td>23.145000</td>\n",
305
+ " <td>123.8</td>\n",
306
+ " <td>56.25</td>\n",
307
+ " <td>54.71</td>\n",
308
+ " <td>56.4</td>\n",
309
+ " <td>123.42</td>\n",
310
+ " <td>61.6</td>\n",
311
+ " <td>122.36</td>\n",
312
+ " </tr>\n",
313
+ " <tr>\n",
314
+ " <th>2072153</th>\n",
315
+ " <td>2021-01-01 00:00:00</td>\n",
316
+ " <td>100.0</td>\n",
317
+ " <td>68.0</td>\n",
318
+ " <td>63.2</td>\n",
319
+ " <td>20.0</td>\n",
320
+ " <td>18650.232</td>\n",
321
+ " <td>64.1</td>\n",
322
+ " <td>0.06</td>\n",
323
+ " <td>3076.270000</td>\n",
324
+ " <td>22.9</td>\n",
325
+ " <td>...</td>\n",
326
+ " <td>71.0</td>\n",
327
+ " <td>69.0</td>\n",
328
+ " <td>23.788947</td>\n",
329
+ " <td>123.8</td>\n",
330
+ " <td>56.25</td>\n",
331
+ " <td>54.71</td>\n",
332
+ " <td>56.4</td>\n",
333
+ " <td>123.42</td>\n",
334
+ " <td>61.6</td>\n",
335
+ " <td>122.36</td>\n",
336
+ " </tr>\n",
337
+ " </tbody>\n",
338
+ "</table>\n",
339
+ "<p>2072154 rows Γ— 30 columns</p>\n",
340
+ "</div>"
341
+ ],
342
+ "text/plain": [
343
+ " date zone_047_hw_valve rtu_004_sat_sp_tn \\\n",
344
+ "0 2018-01-01 00:00:00 100.0 69.0 \n",
345
+ "1 2018-01-01 00:01:00 100.0 69.0 \n",
346
+ "2 2018-01-01 00:02:00 100.0 69.0 \n",
347
+ "3 2018-01-01 00:03:00 100.0 69.0 \n",
348
+ "4 2018-01-01 00:04:00 100.0 69.0 \n",
349
+ "... ... ... ... \n",
350
+ "2072149 2020-12-31 23:58:00 100.0 68.0 \n",
351
+ "2072150 2020-12-31 23:58:00 100.0 68.0 \n",
352
+ "2072151 2020-12-31 23:59:00 100.0 68.0 \n",
353
+ "2072152 2020-12-31 23:59:00 100.0 68.0 \n",
354
+ "2072153 2021-01-01 00:00:00 100.0 68.0 \n",
355
+ "\n",
356
+ " zone_047_temp zone_047_fan_spd rtu_004_fltrd_sa_flow_tn \\\n",
357
+ "0 67.5 20.0 9265.604 \n",
358
+ "1 67.5 20.0 9265.604 \n",
359
+ "2 67.5 20.0 9708.240 \n",
360
+ "3 67.5 20.0 9611.638 \n",
361
+ "4 67.5 20.0 9215.110 \n",
362
+ "... ... ... ... \n",
363
+ "2072149 63.2 20.0 18884.834 \n",
364
+ "2072150 63.2 20.0 18884.834 \n",
365
+ "2072151 63.2 20.0 19345.508 \n",
366
+ "2072152 63.2 20.0 19345.508 \n",
367
+ "2072153 63.2 20.0 18650.232 \n",
368
+ "\n",
369
+ " rtu_004_sa_temp rtu_004_pa_static_stpt_tn rtu_004_oa_flow_tn \\\n",
370
+ "0 66.1 0.06 0.000000 \n",
371
+ "1 66.0 0.06 6572.099162 \n",
372
+ "2 66.1 0.06 7628.832542 \n",
373
+ "3 66.1 0.06 7710.294617 \n",
374
+ "4 66.0 0.06 7139.184090 \n",
375
+ "... ... ... ... \n",
376
+ "2072149 64.4 0.06 2938.320000 \n",
377
+ "2072150 64.4 0.06 2938.320000 \n",
378
+ "2072151 64.3 0.06 3154.390000 \n",
379
+ "2072152 64.3 0.06 3154.390000 \n",
380
+ "2072153 64.1 0.06 3076.270000 \n",
381
+ "\n",
382
+ " rtu_004_oadmpr_pct ... zone_047_heating_sp Unnamed: 47_y \\\n",
383
+ "0 28.0 ... NaN NaN \n",
384
+ "1 28.0 ... NaN NaN \n",
385
+ "2 28.0 ... NaN NaN \n",
386
+ "3 28.0 ... NaN NaN \n",
387
+ "4 28.0 ... NaN NaN \n",
388
+ "... ... ... ... ... \n",
389
+ "2072149 23.4 ... 71.0 69.0 \n",
390
+ "2072150 23.4 ... 71.0 69.0 \n",
391
+ "2072151 23.4 ... 71.0 69.0 \n",
392
+ "2072152 23.4 ... 71.0 69.0 \n",
393
+ "2072153 22.9 ... 71.0 69.0 \n",
394
+ "\n",
395
+ " hvac_S hp_hws_temp aru_001_cwr_temp aru_001_cws_fr_gpm \\\n",
396
+ "0 NaN 75.3 NaN NaN \n",
397
+ "1 NaN 75.3 NaN NaN \n",
398
+ "2 NaN 75.3 NaN NaN \n",
399
+ "3 NaN 75.3 NaN NaN \n",
400
+ "4 NaN 75.3 NaN NaN \n",
401
+ "... ... ... ... ... \n",
402
+ "2072149 23.145000 123.8 56.25 54.71 \n",
403
+ "2072150 23.145000 123.8 56.25 54.71 \n",
404
+ "2072151 23.145000 123.8 56.25 54.71 \n",
405
+ "2072152 23.145000 123.8 56.25 54.71 \n",
406
+ "2072153 23.788947 123.8 56.25 54.71 \n",
407
+ "\n",
408
+ " aru_001_cws_temp aru_001_hwr_temp aru_001_hws_fr_gpm \\\n",
409
+ "0 NaN NaN NaN \n",
410
+ "1 NaN NaN NaN \n",
411
+ "2 NaN NaN NaN \n",
412
+ "3 NaN NaN NaN \n",
413
+ "4 NaN NaN NaN \n",
414
+ "... ... ... ... \n",
415
+ "2072149 56.4 123.42 61.6 \n",
416
+ "2072150 56.4 123.42 61.6 \n",
417
+ "2072151 56.4 123.42 61.6 \n",
418
+ "2072152 56.4 123.42 61.6 \n",
419
+ "2072153 56.4 123.42 61.6 \n",
420
+ "\n",
421
+ " aru_001_hws_temp \n",
422
+ "0 NaN \n",
423
+ "1 NaN \n",
424
+ "2 NaN \n",
425
+ "3 NaN \n",
426
+ "4 NaN \n",
427
+ "... ... \n",
428
+ "2072149 122.36 \n",
429
+ "2072150 122.36 \n",
430
+ "2072151 122.36 \n",
431
+ "2072152 122.36 \n",
432
+ "2072153 122.36 \n",
433
+ "\n",
434
+ "[2072154 rows x 30 columns]"
435
+ ]
436
+ },
437
+ "execution_count": 2,
438
+ "metadata": {},
439
+ "output_type": "execute_result"
440
+ }
441
+ ],
442
+ "source": [
443
+ "merged = pd.read_csv(r'C:\\Users\\jerin\\Downloads\\lbnlbldg59\\lbnlbldg59\\lbnlbldg59.processed\\LBNLBLDG59\\clean_Bldg59_2018to2020\\clean data\\long_merge.csv')\n",
444
+ "\n",
445
+ "zone = \"47\"\n",
446
+ "\n",
447
+ "if zone in [\"36\", \"37\", \"38\", \"39\", \"40\", \"41\", \"42\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\", \"70\"]:\n",
448
+ " rtu = \"rtu_001\"\n",
449
+ " wing = \"hvac_N\"\n",
450
+ "elif zone in [\"18\", \"25\", \"26\", \"45\", \"48\", \"55\", \"56\", \"61\"]:\n",
451
+ " rtu = \"rtu_003\"\n",
452
+ " wing = \"hvac_S\"\n",
453
+ "elif zone in [\"16\", \"17\", \"21\", \"22\", \"23\", \"24\", \"46\", \"47\", \"51\", \"52\", \"53\", \"54\"]:\n",
454
+ " rtu = \"rtu_004\"\n",
455
+ " wing = \"hvac_S\"\n",
456
+ "else:\n",
457
+ " rtu = \"rtu_002\"\n",
458
+ " wing = \"hvac_N\"\n",
459
+ "#merged is the dataframe\n",
460
+ "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",
461
+ "sorted"
462
+ ]
463
+ },
464
+ {
465
+ "cell_type": "code",
466
+ "execution_count": 3,
467
+ "metadata": {},
468
+ "outputs": [
469
+ {
470
+ "data": {
471
+ "text/plain": [
472
+ "date 0\n",
473
+ "zone_047_hw_valve 0\n",
474
+ "rtu_004_sat_sp_tn 0\n",
475
+ "zone_047_temp 0\n",
476
+ "zone_047_fan_spd 0\n",
477
+ "rtu_004_fltrd_sa_flow_tn 0\n",
478
+ "rtu_004_sa_temp 0\n",
479
+ "rtu_004_pa_static_stpt_tn 0\n",
480
+ "rtu_004_oa_flow_tn 0\n",
481
+ "rtu_004_oadmpr_pct 0\n",
482
+ "rtu_004_econ_stpt_tn 0\n",
483
+ "rtu_004_ra_temp 0\n",
484
+ "rtu_004_oa_temp 0\n",
485
+ "rtu_004_ma_temp 0\n",
486
+ "rtu_004_sf_vfd_spd_fbk_tn 0\n",
487
+ "rtu_004_rf_vfd_spd_fbk_tn 0\n",
488
+ "rtu_004_fltrd_gnd_lvl_plenum_press_tn 0\n",
489
+ "rtu_004_fltrd_lvl2_plenum_press_tn 0\n",
490
+ "zone_047_cooling_sp 0\n",
491
+ "Unnamed: 47_x 394570\n",
492
+ "zone_047_heating_sp 0\n",
493
+ "Unnamed: 47_y 394570\n",
494
+ "hvac_S 13035\n",
495
+ "hp_hws_temp 0\n",
496
+ "aru_001_cwr_temp 524350\n",
497
+ "aru_001_cws_fr_gpm 524350\n",
498
+ "aru_001_cws_temp 524350\n",
499
+ "aru_001_hwr_temp 299165\n",
500
+ "aru_001_hws_fr_gpm 299165\n",
501
+ "aru_001_hws_temp 299165\n",
502
+ "dtype: int64"
503
+ ]
504
+ },
505
+ "execution_count": 3,
506
+ "metadata": {},
507
+ "output_type": "execute_result"
508
+ }
509
+ ],
510
+ "source": [
511
+ "final_df = sorted.copy()\n",
512
+ "final_df['date'] = pd.to_datetime(final_df['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
513
+ "final_df = final_df[ (final_df.date.dt.date >date(2019, 4, 1)) & (final_df.date.dt.date< date(2020, 2, 15))]\n",
514
+ "final_df.isna().sum()"
515
+ ]
516
+ },
517
+ {
518
+ "cell_type": "code",
519
+ "execution_count": 4,
520
+ "metadata": {},
521
+ "outputs": [],
522
+ "source": [
523
+ "testdataset_df = final_df[(final_df.date.dt.date <date(2019, 11, 8))]\n",
524
+ "\n",
525
+ "traindataset_df = final_df[ (final_df.date.dt.date >date(2019, 11, 8))]\n",
526
+ "\n",
527
+ "testdataset = testdataset_df[['rtu_004_oa_temp','rtu_004_ra_temp','hp_hws_temp','rtu_004_oa_flow_tn','rtu_004_oadmpr_pct',\n",
528
+ " 'rtu_004_sat_sp_tn','rtu_004_rf_vfd_spd_fbk_tn','rtu_004_ma_temp','rtu_004_sa_temp','rtu_004_fltrd_sa_flow_tn',\n",
529
+ " 'rtu_004_sf_vfd_spd_fbk_tn']].values\n",
530
+ "\n",
531
+ "\n",
532
+ "traindataset = traindataset_df[['rtu_004_oa_temp','rtu_004_ra_temp','hp_hws_temp','rtu_004_oa_flow_tn','rtu_004_oadmpr_pct',\n",
533
+ " 'rtu_004_sat_sp_tn','rtu_004_rf_vfd_spd_fbk_tn','rtu_004_ma_temp','rtu_004_sa_temp','rtu_004_fltrd_sa_flow_tn',\n",
534
+ " 'rtu_004_sf_vfd_spd_fbk_tn']].values"
535
+ ]
536
+ },
537
+ {
538
+ "cell_type": "code",
539
+ "execution_count": 5,
540
+ "metadata": {},
541
+ "outputs": [],
542
+ "source": [
543
+ "traindataset = traindataset.astype('float32')\n",
544
+ "testdataset = testdataset.astype('float32')\n",
545
+ "\n",
546
+ "\n",
547
+ "scaler = MinMaxScaler(feature_range=(0, 1))\n",
548
+ "traindataset = scaler.fit_transform(traindataset)\n",
549
+ "testdataset = scaler.transform(testdataset)"
550
+ ]
551
+ },
552
+ {
553
+ "cell_type": "code",
554
+ "execution_count": 47,
555
+ "metadata": {},
556
+ "outputs": [
557
+ {
558
+ "name": "stderr",
559
+ "output_type": "stream",
560
+ "text": [
561
+ "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",
562
+ " super().__init__(**kwargs)\n"
563
+ ]
564
+ },
565
+ {
566
+ "name": "stdout",
567
+ "output_type": "stream",
568
+ "text": [
569
+ "Epoch 1/10\n",
570
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 0.0071\n",
571
+ "Epoch 1: val_loss improved from inf to 0.01145, saving model to lstm2.keras\n",
572
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m77s\u001b[0m 23ms/step - loss: 0.0071 - val_loss: 0.0115\n",
573
+ "Epoch 2/10\n",
574
+ "\u001b[1m3217/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 0.0013\n",
575
+ "Epoch 2: val_loss improved from 0.01145 to 0.01144, saving model to lstm2.keras\n",
576
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m73s\u001b[0m 23ms/step - loss: 0.0013 - val_loss: 0.0114\n",
577
+ "Epoch 3/10\n",
578
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 0.0010\n",
579
+ "Epoch 3: val_loss improved from 0.01144 to 0.00729, saving model to lstm2.keras\n",
580
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m71s\u001b[0m 22ms/step - loss: 0.0010 - val_loss: 0.0073\n",
581
+ "Epoch 4/10\n",
582
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 5.5876e-04\n",
583
+ "Epoch 4: val_loss improved from 0.00729 to 0.00409, saving model to lstm2.keras\n",
584
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━���━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m73s\u001b[0m 23ms/step - loss: 5.5871e-04 - val_loss: 0.0041\n",
585
+ "Epoch 5/10\n",
586
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 3.9261e-04\n",
587
+ "Epoch 5: val_loss improved from 0.00409 to 0.00386, saving model to lstm2.keras\n",
588
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m72s\u001b[0m 22ms/step - loss: 3.9260e-04 - val_loss: 0.0039\n",
589
+ "Epoch 6/10\n",
590
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 3.3977e-04\n",
591
+ "Epoch 6: val_loss did not improve from 0.00386\n",
592
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m70s\u001b[0m 22ms/step - loss: 3.3976e-04 - val_loss: 0.0049\n",
593
+ "Epoch 7/10\n",
594
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 3.0365e-04\n",
595
+ "Epoch 7: val_loss did not improve from 0.00386\n",
596
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m69s\u001b[0m 22ms/step - loss: 3.0364e-04 - val_loss: 0.0052\n",
597
+ "Epoch 8/10\n",
598
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 2.7422e-04\n",
599
+ "Epoch 8: val_loss did not improve from 0.00386\n",
600
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m70s\u001b[0m 22ms/step - loss: 2.7422e-04 - val_loss: 0.0052\n",
601
+ "Epoch 9/10\n",
602
+ "\u001b[1m3217/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 2.5380e-04\n",
603
+ "Epoch 9: val_loss did not improve from 0.00386\n",
604
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m73s\u001b[0m 23ms/step - loss: 2.5379e-04 - val_loss: 0.0058\n",
605
+ "Epoch 10/10\n",
606
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 2.3404e-04\n",
607
+ "Epoch 10: val_loss did not improve from 0.00386\n",
608
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m72s\u001b[0m 22ms/step - loss: 2.3403e-04 - val_loss: 0.0099\n"
609
+ ]
610
+ },
611
+ {
612
+ "data": {
613
+ "text/plain": [
614
+ "<keras.src.callbacks.history.History at 0x2a05f762150>"
615
+ ]
616
+ },
617
+ "execution_count": 47,
618
+ "metadata": {},
619
+ "output_type": "execute_result"
620
+ }
621
+ ],
622
+ "source": [
623
+ "train,test = traindataset,testdataset\n",
624
+ "\n",
625
+ "def create_dataset(dataset,time_step):\n",
626
+ " x1,x2,x3,x4,x5,x6,x7,x8,x9,Y = [],[],[],[],[],[],[],[],[],[]\n",
627
+ " for i in range(len(dataset)-time_step-1):\n",
628
+ " x1.append(dataset[i:(i+time_step), 0])\n",
629
+ " x2.append(dataset[i:(i+time_step), 1])\n",
630
+ " x3.append(dataset[i:(i+time_step), 2])\n",
631
+ " x4.append(dataset[i:(i+time_step), 3])\n",
632
+ " x5.append(dataset[i:(i+time_step), 4])\n",
633
+ " x6.append(dataset[i:(i+time_step), 5])\n",
634
+ " x7.append(dataset[i:(i+time_step), 6])\n",
635
+ " x8.append(dataset[i:(i+time_step), 7])\n",
636
+ " # x9.append(dataset[i:(i+time_step), 8])\n",
637
+ " Y.append([dataset[i + time_step, 7]])\n",
638
+ " x1,x2,x3,x4,x5,x6,x7,x8 = 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)\n",
639
+ " Y = np.reshape(Y,(len(Y),1))\n",
640
+ " return np.stack([x1,x2,x3,x4,x5,x6,x7,x8],axis=2),Y\n",
641
+ "\n",
642
+ "\n",
643
+ "\n",
644
+ "\n",
645
+ "time_step = 30\n",
646
+ "X_train, y_train = create_dataset(train, time_step)\n",
647
+ "X_test, y_test = create_dataset(test, time_step)\n",
648
+ "\n",
649
+ "\n",
650
+ "model = Sequential()\n",
651
+ "model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
652
+ "model.add(LSTM(units=50, return_sequences=True))\n",
653
+ "model.add(LSTM(units=30))\n",
654
+ "model.add(Dense(units=1))\n",
655
+ "\n",
656
+ "model.compile(optimizer='adam', loss='mean_squared_error')\n",
657
+ "\n",
658
+ "checkpoint_path = \"lstm2.keras\"\n",
659
+ "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
660
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=10, batch_size=64, verbose=1, callbacks=[checkpoint_callback])\n"
661
+ ]
662
+ },
663
+ {
664
+ "cell_type": "code",
665
+ "execution_count": 45,
666
+ "metadata": {},
667
+ "outputs": [
668
+ {
669
+ "name": "stdout",
670
+ "output_type": "stream",
671
+ "text": [
672
+ "Epoch 1/5\n",
673
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 1.8977e-04\n",
674
+ "Epoch 1: val_loss improved from inf to 0.01131, saving model to lstm2.keras\n",
675
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m94s\u001b[0m 29ms/step - loss: 1.8977e-04 - val_loss: 0.0113\n",
676
+ "Epoch 2/5\n",
677
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 18ms/step - loss: 1.7357e-04\n",
678
+ "Epoch 2: val_loss did not improve from 0.01131\n",
679
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m91s\u001b[0m 28ms/step - loss: 1.7358e-04 - val_loss: 0.0123\n",
680
+ "Epoch 3/5\n",
681
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 18ms/step - loss: 1.6701e-04\n",
682
+ "Epoch 3: val_loss did not improve from 0.01131\n",
683
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m92s\u001b[0m 28ms/step - loss: 1.6701e-04 - val_loss: 0.0127\n",
684
+ "Epoch 4/5\n",
685
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 18ms/step - loss: 1.7043e-04\n",
686
+ "Epoch 4: val_loss did not improve from 0.01131\n",
687
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m91s\u001b[0m 28ms/step - loss: 1.7043e-04 - val_loss: 0.0131\n",
688
+ "Epoch 5/5\n",
689
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 1.6319e-04\n",
690
+ "Epoch 5: val_loss did not improve from 0.01131\n",
691
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m104s\u001b[0m 32ms/step - loss: 1.6319e-04 - val_loss: 0.0134\n"
692
+ ]
693
+ },
694
+ {
695
+ "data": {
696
+ "text/plain": [
697
+ "<keras.src.callbacks.history.History at 0x2a05f486ed0>"
698
+ ]
699
+ },
700
+ "execution_count": 45,
701
+ "metadata": {},
702
+ "output_type": "execute_result"
703
+ }
704
+ ],
705
+ "source": [
706
+ "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
707
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=5, batch_size=64, verbose=1, callbacks=[checkpoint_callback])"
708
+ ]
709
+ },
710
+ {
711
+ "cell_type": "code",
712
+ "execution_count": 48,
713
+ "metadata": {},
714
+ "outputs": [
715
+ {
716
+ "name": "stdout",
717
+ "output_type": "stream",
718
+ "text": [
719
+ "\u001b[1m9900/9900\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m34s\u001b[0m 3ms/step\n"
720
+ ]
721
+ }
722
+ ],
723
+ "source": [
724
+ "# train_predict = model.predict(X_train)\n",
725
+ "test_predict = model.predict(X_test)"
726
+ ]
727
+ },
728
+ {
729
+ "cell_type": "code",
730
+ "execution_count": 49,
731
+ "metadata": {},
732
+ "outputs": [],
733
+ "source": [
734
+ "%matplotlib qt\n",
735
+ "#'rtu_004_ma_temp','rtu_004_sa_temp'\n",
736
+ "var = 0\n",
737
+ "plt.plot(testdataset_df['date'][31:],y_test, label='Original Testing Data', color='blue')\n",
738
+ "plt.plot(testdataset_df['date'][31:],test_predict, label='Predicted Testing Data', color='red',alpha=0.8)\n",
739
+ "# anomalies = np.where(abs(test_predict[:,var] - y_test[:,var]) > 0.38)[0]\n",
740
+ "# plt.scatter(anomalies,test_predict[anomalies,var], color='black',marker =\"o\",s=100 )\n",
741
+ "\n",
742
+ "\n",
743
+ "plt.title('Testing Data - Predicted vs Actual')\n",
744
+ "plt.xlabel('Time')\n",
745
+ "plt.ylabel('Value')\n",
746
+ "plt.legend()\n",
747
+ "plt.show()"
748
+ ]
749
+ },
750
+ {
751
+ "cell_type": "code",
752
+ "execution_count": 50,
753
+ "metadata": {},
754
+ "outputs": [
755
+ {
756
+ "name": "stderr",
757
+ "output_type": "stream",
758
+ "text": [
759
+ "WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. \n"
760
+ ]
761
+ }
762
+ ],
763
+ "source": [
764
+ "from tensorflow.keras.models import load_model\n",
765
+ "# model.save(\"MA_temp_model.h5\") \n",
766
+ "# loaded_model = load_model(\"MA_temp_model.h5\")"
767
+ ]
768
+ },
769
+ {
770
+ "cell_type": "code",
771
+ "execution_count": null,
772
+ "metadata": {},
773
+ "outputs": [],
774
+ "source": []
775
+ },
776
+ {
777
+ "cell_type": "markdown",
778
+ "metadata": {},
779
+ "source": [
780
+ "ENERGY DATA"
781
+ ]
782
+ },
783
+ {
784
+ "cell_type": "code",
785
+ "execution_count": 3,
786
+ "metadata": {},
787
+ "outputs": [
788
+ {
789
+ "data": {
790
+ "text/html": [
791
+ "<div>\n",
792
+ "<style scoped>\n",
793
+ " .dataframe tbody tr th:only-of-type {\n",
794
+ " vertical-align: middle;\n",
795
+ " }\n",
796
+ "\n",
797
+ " .dataframe tbody tr th {\n",
798
+ " vertical-align: top;\n",
799
+ " }\n",
800
+ "\n",
801
+ " .dataframe thead th {\n",
802
+ " text-align: right;\n",
803
+ " }\n",
804
+ "</style>\n",
805
+ "<table border=\"1\" class=\"dataframe\">\n",
806
+ " <thead>\n",
807
+ " <tr style=\"text-align: right;\">\n",
808
+ " <th></th>\n",
809
+ " <th>date</th>\n",
810
+ " <th>rtu_001_sat_sp_tn</th>\n",
811
+ " <th>rtu_002_sat_sp_tn</th>\n",
812
+ " <th>rtu_003_sat_sp_tn</th>\n",
813
+ " <th>rtu_004_sat_sp_tn</th>\n",
814
+ " <th>rtu_001_fltrd_sa_flow_tn</th>\n",
815
+ " <th>rtu_002_fltrd_sa_flow_tn</th>\n",
816
+ " <th>rtu_003_fltrd_sa_flow_tn</th>\n",
817
+ " <th>rtu_004_fltrd_sa_flow_tn</th>\n",
818
+ " <th>rtu_001_sa_temp</th>\n",
819
+ " <th>...</th>\n",
820
+ " <th>rtu_001_fltrd_gnd_lvl_plenum_press_tn</th>\n",
821
+ " <th>rtu_002_fltrd_gnd_lvl_plenum_press_tn</th>\n",
822
+ " <th>rtu_003_fltrd_gnd_lvl_plenum_press_tn</th>\n",
823
+ " <th>rtu_004_fltrd_gnd_lvl_plenum_press_tn</th>\n",
824
+ " <th>rtu_001_fltrd_lvl2_plenum_press_tn</th>\n",
825
+ " <th>rtu_002_fltrd_lvl2_plenum_press_tn</th>\n",
826
+ " <th>rtu_003_fltrd_lvl2_plenum_press_tn</th>\n",
827
+ " <th>rtu_004_fltrd_lvl2_plenum_press_tn</th>\n",
828
+ " <th>hvac_N</th>\n",
829
+ " <th>hvac_S</th>\n",
830
+ " </tr>\n",
831
+ " </thead>\n",
832
+ " <tbody>\n",
833
+ " <tr>\n",
834
+ " <th>0</th>\n",
835
+ " <td>2018-01-01 00:00:00</td>\n",
836
+ " <td>68.0</td>\n",
837
+ " <td>70.0</td>\n",
838
+ " <td>65.0</td>\n",
839
+ " <td>69.0</td>\n",
840
+ " <td>14131.449</td>\n",
841
+ " <td>13998.757</td>\n",
842
+ " <td>13558.539</td>\n",
843
+ " <td>9265.604</td>\n",
844
+ " <td>67.6</td>\n",
845
+ " <td>...</td>\n",
846
+ " <td>0.030</td>\n",
847
+ " <td>0.04</td>\n",
848
+ " <td>0.04</td>\n",
849
+ " <td>0.047</td>\n",
850
+ " <td>0.050</td>\n",
851
+ " <td>0.05</td>\n",
852
+ " <td>0.05</td>\n",
853
+ " <td>0.050</td>\n",
854
+ " <td>NaN</td>\n",
855
+ " <td>NaN</td>\n",
856
+ " </tr>\n",
857
+ " <tr>\n",
858
+ " <th>1</th>\n",
859
+ " <td>2018-01-01 00:01:00</td>\n",
860
+ " <td>68.0</td>\n",
861
+ " <td>70.0</td>\n",
862
+ " <td>65.0</td>\n",
863
+ " <td>69.0</td>\n",
864
+ " <td>14164.429</td>\n",
865
+ " <td>14065.259</td>\n",
866
+ " <td>13592.909</td>\n",
867
+ " <td>9265.604</td>\n",
868
+ " <td>67.6</td>\n",
869
+ " <td>...</td>\n",
870
+ " <td>0.031</td>\n",
871
+ " <td>0.04</td>\n",
872
+ " <td>0.04</td>\n",
873
+ " <td>0.043</td>\n",
874
+ " <td>0.048</td>\n",
875
+ " <td>0.05</td>\n",
876
+ " <td>0.04</td>\n",
877
+ " <td>0.046</td>\n",
878
+ " <td>NaN</td>\n",
879
+ " <td>NaN</td>\n",
880
+ " </tr>\n",
881
+ " </tbody>\n",
882
+ "</table>\n",
883
+ "<p>2 rows Γ— 59 columns</p>\n",
884
+ "</div>"
885
+ ],
886
+ "text/plain": [
887
+ " date rtu_001_sat_sp_tn rtu_002_sat_sp_tn \\\n",
888
+ "0 2018-01-01 00:00:00 68.0 70.0 \n",
889
+ "1 2018-01-01 00:01:00 68.0 70.0 \n",
890
+ "\n",
891
+ " rtu_003_sat_sp_tn rtu_004_sat_sp_tn rtu_001_fltrd_sa_flow_tn \\\n",
892
+ "0 65.0 69.0 14131.449 \n",
893
+ "1 65.0 69.0 14164.429 \n",
894
+ "\n",
895
+ " rtu_002_fltrd_sa_flow_tn rtu_003_fltrd_sa_flow_tn \\\n",
896
+ "0 13998.757 13558.539 \n",
897
+ "1 14065.259 13592.909 \n",
898
+ "\n",
899
+ " rtu_004_fltrd_sa_flow_tn rtu_001_sa_temp ... \\\n",
900
+ "0 9265.604 67.6 ... \n",
901
+ "1 9265.604 67.6 ... \n",
902
+ "\n",
903
+ " rtu_001_fltrd_gnd_lvl_plenum_press_tn \\\n",
904
+ "0 0.030 \n",
905
+ "1 0.031 \n",
906
+ "\n",
907
+ " rtu_002_fltrd_gnd_lvl_plenum_press_tn \\\n",
908
+ "0 0.04 \n",
909
+ "1 0.04 \n",
910
+ "\n",
911
+ " rtu_003_fltrd_gnd_lvl_plenum_press_tn \\\n",
912
+ "0 0.04 \n",
913
+ "1 0.04 \n",
914
+ "\n",
915
+ " rtu_004_fltrd_gnd_lvl_plenum_press_tn rtu_001_fltrd_lvl2_plenum_press_tn \\\n",
916
+ "0 0.047 0.050 \n",
917
+ "1 0.043 0.048 \n",
918
+ "\n",
919
+ " rtu_002_fltrd_lvl2_plenum_press_tn rtu_003_fltrd_lvl2_plenum_press_tn \\\n",
920
+ "0 0.05 0.05 \n",
921
+ "1 0.05 0.04 \n",
922
+ "\n",
923
+ " rtu_004_fltrd_lvl2_plenum_press_tn hvac_N hvac_S \n",
924
+ "0 0.050 NaN NaN \n",
925
+ "1 0.046 NaN NaN \n",
926
+ "\n",
927
+ "[2 rows x 59 columns]"
928
+ ]
929
+ },
930
+ "execution_count": 3,
931
+ "metadata": {},
932
+ "output_type": "execute_result"
933
+ }
934
+ ],
935
+ "source": [
936
+ "zone = [\"18\", \"25\", \"26\", \"45\", \"48\", \"55\", \"56\", \"61\",\"16\", \"17\", \"21\", \"23\", \"24\", \"46\", \"47\", \"51\", \"52\", \"53\", \"54\"]\n",
937
+ "rtu = [\"rtu_001\",\"rtu_002\",\"rtu_003\",\"rtu_004\"]\n",
938
+ "wing = [\"hvac_N\",\"hvac_S\"]\n",
939
+ "# any(sub in col for sub in zone) or\n",
940
+ "energy_data = merged[[\"date\"]+[col for col in merged.columns if any(sub in col for sub in wing) or any(sub in col for sub in rtu)]]\n",
941
+ "df_filtered = energy_data[[col for col in energy_data.columns if 'Unnamed' not in col]]\n",
942
+ "df_filtered = df_filtered[[col for col in df_filtered.columns if 'co2' not in col]]\n",
943
+ "df_filtered = df_filtered[[col for col in df_filtered.columns if 'templogger' not in col]]\n",
944
+ "# df_filtered = df_filtered.dropna()\n",
945
+ "df_filtered.head(2)"
946
+ ]
947
+ },
948
+ {
949
+ "cell_type": "code",
950
+ "execution_count": 4,
951
+ "metadata": {},
952
+ "outputs": [
953
+ {
954
+ "name": "stdout",
955
+ "output_type": "stream",
956
+ "text": [
957
+ "There are NA values in the DataFrame columns.\n"
958
+ ]
959
+ }
960
+ ],
961
+ "source": [
962
+ "df_filtered['date'] = pd.to_datetime(df_filtered['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
963
+ "df_filtered = df_filtered[ (df_filtered.date.dt.date >date(2019, 4, 1)) & (df_filtered.date.dt.date< date(2020, 2, 15))]\n",
964
+ "# df_filtered.isna().sum()\n",
965
+ "if df_filtered.isna().any().any():\n",
966
+ " print(\"There are NA values in the DataFrame columns.\")"
967
+ ]
968
+ },
969
+ {
970
+ "cell_type": "code",
971
+ "execution_count": 5,
972
+ "metadata": {},
973
+ "outputs": [
974
+ {
975
+ "data": {
976
+ "text/plain": [
977
+ "[]"
978
+ ]
979
+ },
980
+ "execution_count": 5,
981
+ "metadata": {},
982
+ "output_type": "execute_result"
983
+ }
984
+ ],
985
+ "source": [
986
+ "testdataset_df = df_filtered[(df_filtered.date.dt.date <date(2019, 8, 21))]\n",
987
+ "\n",
988
+ "traindataset_df = df_filtered[ (df_filtered.date.dt.date >date(2019, 11, 8))]\n",
989
+ "\n",
990
+ "testdataset = testdataset_df.drop(columns=[\"date\"]).values\n",
991
+ "\n",
992
+ "traindataset = traindataset_df.drop(columns=[\"date\"]).values\n",
993
+ "\n",
994
+ "columns_with_na = traindataset_df.columns[traindataset_df.isna().any()].tolist()\n",
995
+ "columns_with_na"
996
+ ]
997
+ },
998
+ {
999
+ "cell_type": "code",
1000
+ "execution_count": 6,
1001
+ "metadata": {},
1002
+ "outputs": [],
1003
+ "source": [
1004
+ "traindataset = traindataset.astype('float32')\n",
1005
+ "testdataset = testdataset.astype('float32')\n",
1006
+ "\n",
1007
+ "scaler = MinMaxScaler(feature_range=(0, 1))\n",
1008
+ "traindataset = scaler.fit_transform(traindataset)\n",
1009
+ "testdataset = scaler.transform(testdataset)"
1010
+ ]
1011
+ },
1012
+ {
1013
+ "cell_type": "code",
1014
+ "execution_count": 7,
1015
+ "metadata": {},
1016
+ "outputs": [
1017
+ {
1018
+ "name": "stderr",
1019
+ "output_type": "stream",
1020
+ "text": [
1021
+ "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",
1022
+ " super().__init__(**kwargs)\n"
1023
+ ]
1024
+ },
1025
+ {
1026
+ "name": "stdout",
1027
+ "output_type": "stream",
1028
+ "text": [
1029
+ "Epoch 1/15\n",
1030
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 0.0038\n",
1031
+ "Epoch 1: val_loss improved from inf to 0.00894, saving model to lstm3.keras\n",
1032
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m144s\u001b[0m 44ms/step - loss: 0.0038 - val_loss: 0.0089\n",
1033
+ "Epoch 2/15\n",
1034
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 32ms/step - loss: 5.4854e-04\n",
1035
+ "Epoch 2: val_loss improved from 0.00894 to 0.00529, saving model to lstm3.keras\n",
1036
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m137s\u001b[0m 43ms/step - loss: 5.4854e-04 - val_loss: 0.0053\n",
1037
+ "Epoch 3/15\n",
1038
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 5.0405e-04\n",
1039
+ "Epoch 3: val_loss did not improve from 0.00529\n",
1040
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 5.0405e-04 - val_loss: 0.0063\n",
1041
+ "Epoch 4/15\n",
1042
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.9573e-04\n",
1043
+ "Epoch 4: val_loss did not improve from 0.00529\n",
1044
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m131s\u001b[0m 41ms/step - loss: 4.9572e-04 - val_loss: 0.0061\n",
1045
+ "Epoch 5/15\n",
1046
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 31ms/step - loss: 4.9666e-04\n",
1047
+ "Epoch 5: val_loss did not improve from 0.00529\n",
1048
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m135s\u001b[0m 42ms/step - loss: 4.9665e-04 - val_loss: 0.0058\n",
1049
+ "Epoch 6/15\n",
1050
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.7853e-04\n",
1051
+ "Epoch 6: val_loss improved from 0.00529 to 0.00512, saving model to lstm3.keras\n",
1052
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 4.7852e-04 - val_loss: 0.0051\n",
1053
+ "Epoch 7/15\n",
1054
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 29ms/step - loss: 4.3858e-04\n",
1055
+ "Epoch 7: val_loss improved from 0.00512 to 0.00386, saving model to lstm3.keras\n",
1056
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 4.3859e-04 - val_loss: 0.0039\n",
1057
+ "Epoch 8/15\n",
1058
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.4643e-04\n",
1059
+ "Epoch 8: val_loss improved from 0.00386 to 0.00321, saving model to lstm3.keras\n",
1060
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 4.4643e-04 - val_loss: 0.0032\n",
1061
+ "Epoch 9/15\n",
1062
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.3562e-04\n",
1063
+ "Epoch 9: val_loss improved from 0.00321 to 0.00267, saving model to lstm3.keras\n",
1064
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m130s\u001b[0m 40ms/step - loss: 4.3562e-04 - val_loss: 0.0027\n",
1065
+ "Epoch 10/15\n",
1066
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.3336e-04\n",
1067
+ "Epoch 10: val_loss did not improve from 0.00267\n",
1068
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m130s\u001b[0m 40ms/step - loss: 4.3336e-04 - val_loss: 0.0029\n",
1069
+ "Epoch 11/15\n",
1070
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.2932e-04\n",
1071
+ "Epoch 11: val_loss did not improve from 0.00267\n",
1072
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m130s\u001b[0m 40ms/step - loss: 4.2932e-04 - val_loss: 0.0032\n",
1073
+ "Epoch 12/15\n",
1074
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━���━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.1954e-04\n",
1075
+ "Epoch 12: val_loss improved from 0.00267 to 0.00248, saving model to lstm3.keras\n",
1076
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m128s\u001b[0m 40ms/step - loss: 4.1954e-04 - val_loss: 0.0025\n",
1077
+ "Epoch 13/15\n",
1078
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 29ms/step - loss: 4.2671e-04\n",
1079
+ "Epoch 13: val_loss improved from 0.00248 to 0.00245, saving model to lstm3.keras\n",
1080
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m130s\u001b[0m 40ms/step - loss: 4.2671e-04 - val_loss: 0.0024\n",
1081
+ "Epoch 14/15\n",
1082
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.1718e-04\n",
1083
+ "Epoch 14: val_loss did not improve from 0.00245\n",
1084
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 4.1717e-04 - val_loss: 0.0031\n",
1085
+ "Epoch 15/15\n",
1086
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 30ms/step - loss: 4.0550e-04\n",
1087
+ "Epoch 15: val_loss did not improve from 0.00245\n",
1088
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m129s\u001b[0m 40ms/step - loss: 4.0550e-04 - val_loss: 0.0025\n"
1089
+ ]
1090
+ },
1091
+ {
1092
+ "data": {
1093
+ "text/plain": [
1094
+ "<keras.src.callbacks.history.History at 0x1fc4b1aecd0>"
1095
+ ]
1096
+ },
1097
+ "execution_count": 7,
1098
+ "metadata": {},
1099
+ "output_type": "execute_result"
1100
+ }
1101
+ ],
1102
+ "source": [
1103
+ "train,test = traindataset,testdataset\n",
1104
+ "\n",
1105
+ "def create_dataset(dataset,time_step):\n",
1106
+ " x = [[] for _ in range(58)] \n",
1107
+ " Y = []\n",
1108
+ " for i in range(len(dataset) - time_step - 1):\n",
1109
+ " for j in range(58):\n",
1110
+ " x[j].append(dataset[i:(i + time_step), j])\n",
1111
+ " Y.append([dataset[i + time_step, 56],dataset[i + time_step, 57]])\n",
1112
+ " x= [np.array(feature_list) for feature_list in x]\n",
1113
+ " Y = np.reshape(Y,(len(Y),2))\n",
1114
+ " return np.stack(x,axis=2),Y\n",
1115
+ "\n",
1116
+ "time_step = 60\n",
1117
+ "X_train, y_train = create_dataset(train, time_step)\n",
1118
+ "X_test, y_test = create_dataset(test, time_step)\n",
1119
+ "\n",
1120
+ "\n",
1121
+ "model = Sequential()\n",
1122
+ "model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
1123
+ "model.add(LSTM(units=50, return_sequences=True))\n",
1124
+ "model.add(LSTM(units=50))\n",
1125
+ "model.add(Dense(units=2))\n",
1126
+ "\n",
1127
+ "model.compile(optimizer='adam', loss='mean_squared_error')\n",
1128
+ "\n",
1129
+ "checkpoint_path = \"lstm3.keras\"\n",
1130
+ "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
1131
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=15, batch_size=64, verbose=1, callbacks=[checkpoint_callback])\n"
1132
+ ]
1133
+ },
1134
+ {
1135
+ "cell_type": "code",
1136
+ "execution_count": 39,
1137
+ "metadata": {},
1138
+ "outputs": [
1139
+ {
1140
+ "name": "stdout",
1141
+ "output_type": "stream",
1142
+ "text": [
1143
+ "Epoch 1/10\n",
1144
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0050\n",
1145
+ "Epoch 1: val_loss improved from inf to 0.03991, saving model to lstm3.keras\n",
1146
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0050 - val_loss: 0.0399\n",
1147
+ "Epoch 2/10\n",
1148
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0050\n",
1149
+ "Epoch 2: val_loss did not improve from 0.03991\n",
1150
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m67s\u001b[0m 21ms/step - loss: 0.0050 - val_loss: 0.0480\n",
1151
+ "Epoch 3/10\n",
1152
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0048\n",
1153
+ "Epoch 3: val_loss did not improve from 0.03991\n",
1154
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━��━\u001b[0m\u001b[37m\u001b[0m \u001b[1m67s\u001b[0m 21ms/step - loss: 0.0048 - val_loss: 0.0474\n",
1155
+ "Epoch 4/10\n",
1156
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0047\n",
1157
+ "Epoch 4: val_loss did not improve from 0.03991\n",
1158
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0047 - val_loss: 0.0492\n",
1159
+ "Epoch 5/10\n",
1160
+ "\u001b[1m3217/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0048\n",
1161
+ "Epoch 5: val_loss improved from 0.03991 to 0.03753, saving model to lstm3.keras\n",
1162
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0048 - val_loss: 0.0375\n",
1163
+ "Epoch 6/10\n",
1164
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0046\n",
1165
+ "Epoch 6: val_loss did not improve from 0.03753\n",
1166
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0046 - val_loss: 0.0466\n",
1167
+ "Epoch 7/10\n",
1168
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0043\n",
1169
+ "Epoch 7: val_loss did not improve from 0.03753\n",
1170
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m67s\u001b[0m 21ms/step - loss: 0.0043 - val_loss: 0.0499\n",
1171
+ "Epoch 8/10\n",
1172
+ "\u001b[1m3219/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0043\n",
1173
+ "Epoch 8: val_loss did not improve from 0.03753\n",
1174
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0043 - val_loss: 0.0483\n",
1175
+ "Epoch 9/10\n",
1176
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0042\n",
1177
+ "Epoch 9: val_loss did not improve from 0.03753\n",
1178
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m69s\u001b[0m 22ms/step - loss: 0.0042 - val_loss: 0.0559\n",
1179
+ "Epoch 10/10\n",
1180
+ "\u001b[1m3218/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 0.0044\n",
1181
+ "Epoch 10: val_loss did not improve from 0.03753\n",
1182
+ "\u001b[1m3220/3220\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m68s\u001b[0m 21ms/step - loss: 0.0044 - val_loss: 0.0470\n"
1183
+ ]
1184
+ },
1185
+ {
1186
+ "data": {
1187
+ "text/plain": [
1188
+ "<keras.src.callbacks.history.History at 0x153b37086d0>"
1189
+ ]
1190
+ },
1191
+ "execution_count": 39,
1192
+ "metadata": {},
1193
+ "output_type": "execute_result"
1194
+ }
1195
+ ],
1196
+ "source": [
1197
+ "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
1198
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=10, batch_size=64, verbose=1, callbacks=[checkpoint_callback])"
1199
+ ]
1200
+ },
1201
+ {
1202
+ "cell_type": "code",
1203
+ "execution_count": 8,
1204
+ "metadata": {},
1205
+ "outputs": [
1206
+ {
1207
+ "name": "stdout",
1208
+ "output_type": "stream",
1209
+ "text": [
1210
+ "\u001b[1m6344/6344\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m47s\u001b[0m 7ms/step\n"
1211
+ ]
1212
+ }
1213
+ ],
1214
+ "source": [
1215
+ "test_predict1 = model.predict(X_test)\n",
1216
+ "# train_predict1 = model.predict(X_train)"
1217
+ ]
1218
+ },
1219
+ {
1220
+ "cell_type": "code",
1221
+ "execution_count": 10,
1222
+ "metadata": {},
1223
+ "outputs": [],
1224
+ "source": [
1225
+ "%matplotlib qt\n",
1226
+ "var = 0\n",
1227
+ "plt.plot(testdataset_df['date'][61:],y_test[:,0], label='Original Testing Data', color='blue')\n",
1228
+ "plt.plot(testdataset_df['date'][61:],test_predict1[:,0], label='Predicted Testing Data', color='red',alpha=0.8)\n",
1229
+ "# anomalies = np.where(abs(test_predict[:,var] - y_test[:,var]) > 0.38)[0]\n",
1230
+ "# plt.scatter(anomalies,test_predict[anomalies,var], color='black',marker =\"o\",s=100 )\n",
1231
+ "\n",
1232
+ "\n",
1233
+ "plt.title('Testing Data - Predicted vs Actual')\n",
1234
+ "plt.xlabel('Time')\n",
1235
+ "plt.ylabel('Value')\n",
1236
+ "plt.legend()\n",
1237
+ "plt.show()"
1238
+ ]
1239
+ },
1240
+ {
1241
+ "cell_type": "code",
1242
+ "execution_count": 11,
1243
+ "metadata": {},
1244
+ "outputs": [
1245
+ {
1246
+ "name": "stderr",
1247
+ "output_type": "stream",
1248
+ "text": [
1249
+ "WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. \n"
1250
+ ]
1251
+ }
1252
+ ],
1253
+ "source": [
1254
+ "from tensorflow.keras.models import load_model\n",
1255
+ "model.save(\"energy_model.h5\") "
1256
+ ]
1257
+ },
1258
+ {
1259
+ "cell_type": "code",
1260
+ "execution_count": 8,
1261
+ "metadata": {},
1262
+ "outputs": [
1263
+ {
1264
+ "data": {
1265
+ "text/plain": [
1266
+ "[<matplotlib.lines.Line2D at 0x152fd38cd10>]"
1267
+ ]
1268
+ },
1269
+ "execution_count": 8,
1270
+ "metadata": {},
1271
+ "output_type": "execute_result"
1272
+ }
1273
+ ],
1274
+ "source": [
1275
+ "%matplotlib qt\n",
1276
+ "plt.plot(df_filtered['date'],df_filtered['hvac_S'])\n",
1277
+ "plt.plot(df_filtered['date'],df_filtered['rtu_003_sf_vfd_spd_fbk_tn'])\n",
1278
+ "plt.plot(df_filtered['date'],df_filtered['zone_025_temp'])"
1279
+ ]
1280
+ },
1281
+ {
1282
+ "cell_type": "code",
1283
+ "execution_count": null,
1284
+ "metadata": {},
1285
+ "outputs": [],
1286
+ "source": []
1287
+ }
1288
+ ],
1289
+ "metadata": {
1290
+ "kernelspec": {
1291
+ "display_name": "smartbuilding",
1292
+ "language": "python",
1293
+ "name": "python3"
1294
+ },
1295
+ "language_info": {
1296
+ "codemirror_mode": {
1297
+ "name": "ipython",
1298
+ "version": 3
1299
+ },
1300
+ "file_extension": ".py",
1301
+ "mimetype": "text/x-python",
1302
+ "name": "python",
1303
+ "nbconvert_exporter": "python",
1304
+ "pygments_lexer": "ipython3",
1305
+ "version": "3.11.8"
1306
+ }
1307
+ },
1308
+ "nbformat": 4,
1309
+ "nbformat_minor": 2
1310
+ }