jerin commited on
Commit
be37c76
1 Parent(s): 4a389dc

lstm_2_rtu_model

Browse files
Files changed (4) hide show
  1. lstm.ipynb +123 -533
  2. lstm_2rtu_smooth_03.keras +0 -0
  3. src/main.py +2 -1
  4. streamlit.py +19 -19
lstm.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -22,7 +22,7 @@
22
  },
23
  {
24
  "cell_type": "code",
25
- "execution_count": 2,
26
  "metadata": {},
27
  "outputs": [
28
  {
@@ -434,7 +434,7 @@
434
  "[2072154 rows x 30 columns]"
435
  ]
436
  },
437
- "execution_count": 2,
438
  "metadata": {},
439
  "output_type": "execute_result"
440
  }
@@ -1135,7 +1135,7 @@
1135
  },
1136
  {
1137
  "cell_type": "code",
1138
- "execution_count": 325,
1139
  "metadata": {},
1140
  "outputs": [
1141
  {
@@ -1272,7 +1272,7 @@
1272
  "[2 rows x 65 columns]"
1273
  ]
1274
  },
1275
- "execution_count": 325,
1276
  "metadata": {},
1277
  "output_type": "execute_result"
1278
  }
@@ -1294,9 +1294,17 @@
1294
  },
1295
  {
1296
  "cell_type": "code",
1297
- "execution_count": 363,
1298
  "metadata": {},
1299
- "outputs": [],
 
 
 
 
 
 
 
 
1300
  "source": [
1301
  "df_filtered['date'] = pd.to_datetime(df_filtered['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
1302
  "df_filtered = df_filtered[ (df_filtered.date.dt.date >date(2018, 5, 1)) & (df_filtered.date.dt.date< date(2020, 5, 1))] #(2018, 5, 1)\n",
@@ -1307,7 +1315,7 @@
1307
  },
1308
  {
1309
  "cell_type": "code",
1310
- "execution_count": 364,
1311
  "metadata": {},
1312
  "outputs": [],
1313
  "source": [
@@ -1340,20 +1348,22 @@
1340
  " 'rtu_004_ma_temp',\n",
1341
  " 'rtu_004_sf_vfd_spd_fbk_tn',\n",
1342
  " 'rtu_004_rf_vfd_spd_fbk_tn',\n",
1343
- " 'rtu_001_sa_temp',\n",
1344
- " 'rtu_001_oadmpr_pct',\n",
1345
- " 'rtu_001_ra_temp',\n",
1346
- " 'rtu_001_oa_temp',\n",
1347
- " 'rtu_001_ma_temp',\n",
1348
- " 'rtu_001_sf_vfd_spd_fbk_tn',\n",
1349
- " 'rtu_001_rf_vfd_spd_fbk_tn',\n",
1350
- " 'rtu_002_sa_temp',\n",
1351
- " 'rtu_002_oadmpr_pct',\n",
1352
- " 'rtu_002_ra_temp',\n",
1353
- " 'rtu_002_oa_temp',\n",
1354
- " 'rtu_002_ma_temp',\n",
1355
- " 'rtu_002_sf_vfd_spd_fbk_tn',\n",
1356
- " 'rtu_002_rf_vfd_spd_fbk_tn',\n",
 
 
1357
  " 'air_temp_set_1',\n",
1358
  " 'air_temp_set_2',\n",
1359
  " 'dew_point_temperature_set_1d',\n",
@@ -1363,7 +1373,7 @@
1363
  },
1364
  {
1365
  "cell_type": "code",
1366
- "execution_count": 365,
1367
  "metadata": {},
1368
  "outputs": [
1369
  {
@@ -1380,13 +1390,13 @@
1380
  "# df_filtered.to_csv(\"sample_data.csv\",index=False)\n",
1381
  "\n",
1382
  "#----------------------------------------------------------------------------------\n",
1383
- "# testdataset_df = df_filtered[(df_filtered.date.dt.date >date(2019, 7, 21))]\n",
1384
  "\n",
1385
- "# traindataset_df = df_filtered[(df_filtered.date.dt.date <date(2019, 7, 21))]\n",
1386
  "\n",
1387
- "testdataset_df = df_filtered[(df_filtered.date.dt.date >date(2020, 1, 1))]\n",
1388
  "\n",
1389
- "traindataset_df = df_filtered[(df_filtered.date.dt.date <date(2020, 1, 1))]\n",
1390
  "\n",
1391
  "\n",
1392
  "# testdataset_df.to_csv(\"sample_data_02.csv\",index=False)\n",
@@ -1403,7 +1413,7 @@
1403
  },
1404
  {
1405
  "cell_type": "code",
1406
- "execution_count": 366,
1407
  "metadata": {},
1408
  "outputs": [
1409
  {
@@ -1449,7 +1459,7 @@
1449
  },
1450
  {
1451
  "cell_type": "code",
1452
- "execution_count": 201,
1453
  "metadata": {},
1454
  "outputs": [
1455
  {
@@ -1464,35 +1474,23 @@
1464
  "name": "stdout",
1465
  "output_type": "stream",
1466
  "text": [
1467
- "Epoch 1/5\n",
1468
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 16ms/step - loss: 0.0568\n",
1469
- "Epoch 1: val_loss improved from inf to 0.08613, saving model to lstm_2rtu_smooth_02.keras\n",
1470
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━��━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m198s\u001b[0m 24ms/step - loss: 0.0568 - val_loss: 0.0861\n",
1471
- "Epoch 2/5\n",
1472
- "\u001b[1m8066/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 16ms/step - loss: 9.6620e-04\n",
1473
- "Epoch 2: val_loss improved from 0.08613 to 0.07149, saving model to lstm_2rtu_smooth_02.keras\n",
1474
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m189s\u001b[0m 23ms/step - loss: 9.6615e-04 - val_loss: 0.0715\n",
1475
- "Epoch 3/5\n",
1476
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 16ms/step - loss: 5.0913e-04\n",
1477
- "Epoch 3: val_loss improved from 0.07149 to 0.06955, saving model to lstm_2rtu_smooth_02.keras\n",
1478
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m187s\u001b[0m 23ms/step - loss: 5.0913e-04 - val_loss: 0.0695\n",
1479
- "Epoch 4/5\n",
1480
- "\u001b[1m8066/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 3.9422e-04\n",
1481
- "Epoch 4: val_loss improved from 0.06955 to 0.06820, saving model to lstm_2rtu_smooth_02.keras\n",
1482
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m185s\u001b[0m 23ms/step - loss: 3.9421e-04 - val_loss: 0.0682\n",
1483
- "Epoch 5/5\n",
1484
- "\u001b[1m8066/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 15ms/step - loss: 3.6433e-04\n",
1485
- "Epoch 5: val_loss improved from 0.06820 to 0.06542, saving model to lstm_2rtu_smooth_02.keras\n",
1486
- "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m188s\u001b[0m 23ms/step - loss: 3.6432e-04 - val_loss: 0.0654\n"
1487
  ]
1488
  },
1489
  {
1490
  "data": {
1491
  "text/plain": [
1492
- "<keras.src.callbacks.history.History at 0x15088066a50>"
1493
  ]
1494
  },
1495
- "execution_count": 201,
1496
  "metadata": {},
1497
  "output_type": "execute_result"
1498
  }
@@ -1500,40 +1498,40 @@
1500
  "source": [
1501
  "#2 rtu model\n",
1502
  "\n",
1503
- "# train,test = traindataset,testdataset\n",
1504
- "\n",
1505
- "# def create_dataset(dataset,time_step):\n",
1506
- "# x = [[] for _ in range(20)] \n",
1507
- "# Y = []\n",
1508
- "# for i in range(len(dataset) - time_step - 1):\n",
1509
- "# for j in range(20):\n",
1510
- "# x[j].append(dataset[i:(i + time_step), j])\n",
1511
- "# Y.append([dataset[i + time_step, 0],dataset[i + time_step, 1],dataset[i + time_step, 2],dataset[i + time_step, 3],\n",
1512
- "# dataset[i + time_step, 4],dataset[i + time_step, 5],\n",
1513
- "# dataset[i + time_step, 6],dataset[i + time_step, 7],\n",
1514
- "# dataset[i + time_step, 8],dataset[i + time_step, 9],dataset[i + time_step, 10],\n",
1515
- "# dataset[i + time_step, 11],dataset[i + time_step, 12],\n",
1516
- "# dataset[i + time_step, 13],dataset[i + time_step, 14]])\n",
1517
- "# x= [np.array(feature_list) for feature_list in x]\n",
1518
- "# Y = np.reshape(Y,(len(Y),15))\n",
1519
- "# return np.stack(x,axis=2),Y\n",
1520
- "\n",
1521
- "# time_step = 30\n",
1522
- "# X_train, y_train = create_dataset(train, time_step)\n",
1523
- "# X_test, y_test = create_dataset(test, time_step)\n",
1524
- "\n",
1525
- "\n",
1526
- "# model = Sequential()\n",
1527
- "# model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
1528
- "# model.add(LSTM(units=50, return_sequences=True))\n",
1529
- "# model.add(LSTM(units=30))\n",
1530
- "# model.add(Dense(units=15))\n",
1531
- "\n",
1532
- "# model.compile(optimizer='adam', loss='mean_squared_error')\n",
1533
- "\n",
1534
- "# checkpoint_path = \"lstm_2rtu_smooth_02.keras\"\n",
1535
- "# checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
1536
- "# model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=5, batch_size=64, verbose=1, callbacks=[checkpoint_callback])"
1537
  ]
1538
  },
1539
  {
@@ -1695,32 +1693,33 @@
1695
  },
1696
  {
1697
  "cell_type": "code",
1698
- "execution_count": 341,
1699
  "metadata": {},
1700
  "outputs": [
1701
  {
1702
  "name": "stdout",
1703
  "output_type": "stream",
1704
  "text": [
1705
- "\u001b[1m11765/11765\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m84s\u001b[0m 7ms/step\n"
 
1706
  ]
1707
  }
1708
  ],
1709
  "source": [
1710
  "test_predict1 = model.predict(X_test)\n",
1711
- "# train_predict1 = model.predict(X_train)"
1712
  ]
1713
  },
1714
  {
1715
  "cell_type": "code",
1716
- "execution_count": 362,
1717
  "metadata": {},
1718
  "outputs": [],
1719
  "source": [
1720
  "%matplotlib qt\n",
1721
- "var = 13\n",
1722
  "plt.plot(y_test[:,var], label='Original Testing Data', color='blue')\n",
1723
- "plt.plot(test_predict2[:,var], label='Predicted Testing Data', color='red',alpha=0.8)\n",
1724
  "# anomalies = np.where(abs(test_predict1[:,var] - y_test[:,var]) > 0.38)\n",
1725
  "# plt.scatter(anomalies,test_predict1[anomalies,var], color='black',marker =\"o\",s=100 )\n",
1726
  "\n",
@@ -1787,425 +1786,16 @@
1787
  },
1788
  {
1789
  "cell_type": "code",
1790
- "execution_count": 195,
1791
  "metadata": {},
1792
  "outputs": [
1793
  {
1794
- "data": {
1795
- "text/html": [
1796
- "<style>#sk-container-id-3 {\n",
1797
- " /* Definition of color scheme common for light and dark mode */\n",
1798
- " --sklearn-color-text: black;\n",
1799
- " --sklearn-color-line: gray;\n",
1800
- " /* Definition of color scheme for unfitted estimators */\n",
1801
- " --sklearn-color-unfitted-level-0: #fff5e6;\n",
1802
- " --sklearn-color-unfitted-level-1: #f6e4d2;\n",
1803
- " --sklearn-color-unfitted-level-2: #ffe0b3;\n",
1804
- " --sklearn-color-unfitted-level-3: chocolate;\n",
1805
- " /* Definition of color scheme for fitted estimators */\n",
1806
- " --sklearn-color-fitted-level-0: #f0f8ff;\n",
1807
- " --sklearn-color-fitted-level-1: #d4ebff;\n",
1808
- " --sklearn-color-fitted-level-2: #b3dbfd;\n",
1809
- " --sklearn-color-fitted-level-3: cornflowerblue;\n",
1810
- "\n",
1811
- " /* Specific color for light theme */\n",
1812
- " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
1813
- " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
1814
- " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
1815
- " --sklearn-color-icon: #696969;\n",
1816
- "\n",
1817
- " @media (prefers-color-scheme: dark) {\n",
1818
- " /* Redefinition of color scheme for dark theme */\n",
1819
- " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
1820
- " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
1821
- " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
1822
- " --sklearn-color-icon: #878787;\n",
1823
- " }\n",
1824
- "}\n",
1825
- "\n",
1826
- "#sk-container-id-3 {\n",
1827
- " color: var(--sklearn-color-text);\n",
1828
- "}\n",
1829
- "\n",
1830
- "#sk-container-id-3 pre {\n",
1831
- " padding: 0;\n",
1832
- "}\n",
1833
- "\n",
1834
- "#sk-container-id-3 input.sk-hidden--visually {\n",
1835
- " border: 0;\n",
1836
- " clip: rect(1px 1px 1px 1px);\n",
1837
- " clip: rect(1px, 1px, 1px, 1px);\n",
1838
- " height: 1px;\n",
1839
- " margin: -1px;\n",
1840
- " overflow: hidden;\n",
1841
- " padding: 0;\n",
1842
- " position: absolute;\n",
1843
- " width: 1px;\n",
1844
- "}\n",
1845
- "\n",
1846
- "#sk-container-id-3 div.sk-dashed-wrapped {\n",
1847
- " border: 1px dashed var(--sklearn-color-line);\n",
1848
- " margin: 0 0.4em 0.5em 0.4em;\n",
1849
- " box-sizing: border-box;\n",
1850
- " padding-bottom: 0.4em;\n",
1851
- " background-color: var(--sklearn-color-background);\n",
1852
- "}\n",
1853
- "\n",
1854
- "#sk-container-id-3 div.sk-container {\n",
1855
- " /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
1856
- " but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
1857
- " so we also need the `!important` here to be able to override the\n",
1858
- " default hidden behavior on the sphinx rendered scikit-learn.org.\n",
1859
- " See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
1860
- " display: inline-block !important;\n",
1861
- " position: relative;\n",
1862
- "}\n",
1863
- "\n",
1864
- "#sk-container-id-3 div.sk-text-repr-fallback {\n",
1865
- " display: none;\n",
1866
- "}\n",
1867
- "\n",
1868
- "div.sk-parallel-item,\n",
1869
- "div.sk-serial,\n",
1870
- "div.sk-item {\n",
1871
- " /* draw centered vertical line to link estimators */\n",
1872
- " background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
1873
- " background-size: 2px 100%;\n",
1874
- " background-repeat: no-repeat;\n",
1875
- " background-position: center center;\n",
1876
- "}\n",
1877
- "\n",
1878
- "/* Parallel-specific style estimator block */\n",
1879
- "\n",
1880
- "#sk-container-id-3 div.sk-parallel-item::after {\n",
1881
- " content: \"\";\n",
1882
- " width: 100%;\n",
1883
- " border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
1884
- " flex-grow: 1;\n",
1885
- "}\n",
1886
- "\n",
1887
- "#sk-container-id-3 div.sk-parallel {\n",
1888
- " display: flex;\n",
1889
- " align-items: stretch;\n",
1890
- " justify-content: center;\n",
1891
- " background-color: var(--sklearn-color-background);\n",
1892
- " position: relative;\n",
1893
- "}\n",
1894
- "\n",
1895
- "#sk-container-id-3 div.sk-parallel-item {\n",
1896
- " display: flex;\n",
1897
- " flex-direction: column;\n",
1898
- "}\n",
1899
- "\n",
1900
- "#sk-container-id-3 div.sk-parallel-item:first-child::after {\n",
1901
- " align-self: flex-end;\n",
1902
- " width: 50%;\n",
1903
- "}\n",
1904
- "\n",
1905
- "#sk-container-id-3 div.sk-parallel-item:last-child::after {\n",
1906
- " align-self: flex-start;\n",
1907
- " width: 50%;\n",
1908
- "}\n",
1909
- "\n",
1910
- "#sk-container-id-3 div.sk-parallel-item:only-child::after {\n",
1911
- " width: 0;\n",
1912
- "}\n",
1913
- "\n",
1914
- "/* Serial-specific style estimator block */\n",
1915
- "\n",
1916
- "#sk-container-id-3 div.sk-serial {\n",
1917
- " display: flex;\n",
1918
- " flex-direction: column;\n",
1919
- " align-items: center;\n",
1920
- " background-color: var(--sklearn-color-background);\n",
1921
- " padding-right: 1em;\n",
1922
- " padding-left: 1em;\n",
1923
- "}\n",
1924
- "\n",
1925
- "\n",
1926
- "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
1927
- "clickable and can be expanded/collapsed.\n",
1928
- "- Pipeline and ColumnTransformer use this feature and define the default style\n",
1929
- "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
1930
- "*/\n",
1931
- "\n",
1932
- "/* Pipeline and ColumnTransformer style (default) */\n",
1933
- "\n",
1934
- "#sk-container-id-3 div.sk-toggleable {\n",
1935
- " /* Default theme specific background. It is overwritten whether we have a\n",
1936
- " specific estimator or a Pipeline/ColumnTransformer */\n",
1937
- " background-color: var(--sklearn-color-background);\n",
1938
- "}\n",
1939
- "\n",
1940
- "/* Toggleable label */\n",
1941
- "#sk-container-id-3 label.sk-toggleable__label {\n",
1942
- " cursor: pointer;\n",
1943
- " display: block;\n",
1944
- " width: 100%;\n",
1945
- " margin-bottom: 0;\n",
1946
- " padding: 0.5em;\n",
1947
- " box-sizing: border-box;\n",
1948
- " text-align: center;\n",
1949
- "}\n",
1950
- "\n",
1951
- "#sk-container-id-3 label.sk-toggleable__label-arrow:before {\n",
1952
- " /* Arrow on the left of the label */\n",
1953
- " content: \"▸\";\n",
1954
- " float: left;\n",
1955
- " margin-right: 0.25em;\n",
1956
- " color: var(--sklearn-color-icon);\n",
1957
- "}\n",
1958
- "\n",
1959
- "#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {\n",
1960
- " color: var(--sklearn-color-text);\n",
1961
- "}\n",
1962
- "\n",
1963
- "/* Toggleable content - dropdown */\n",
1964
- "\n",
1965
- "#sk-container-id-3 div.sk-toggleable__content {\n",
1966
- " max-height: 0;\n",
1967
- " max-width: 0;\n",
1968
- " overflow: hidden;\n",
1969
- " text-align: left;\n",
1970
- " /* unfitted */\n",
1971
- " background-color: var(--sklearn-color-unfitted-level-0);\n",
1972
- "}\n",
1973
- "\n",
1974
- "#sk-container-id-3 div.sk-toggleable__content.fitted {\n",
1975
- " /* fitted */\n",
1976
- " background-color: var(--sklearn-color-fitted-level-0);\n",
1977
- "}\n",
1978
- "\n",
1979
- "#sk-container-id-3 div.sk-toggleable__content pre {\n",
1980
- " margin: 0.2em;\n",
1981
- " border-radius: 0.25em;\n",
1982
- " color: var(--sklearn-color-text);\n",
1983
- " /* unfitted */\n",
1984
- " background-color: var(--sklearn-color-unfitted-level-0);\n",
1985
- "}\n",
1986
- "\n",
1987
- "#sk-container-id-3 div.sk-toggleable__content.fitted pre {\n",
1988
- " /* unfitted */\n",
1989
- " background-color: var(--sklearn-color-fitted-level-0);\n",
1990
- "}\n",
1991
- "\n",
1992
- "#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
1993
- " /* Expand drop-down */\n",
1994
- " max-height: 200px;\n",
1995
- " max-width: 100%;\n",
1996
- " overflow: auto;\n",
1997
- "}\n",
1998
- "\n",
1999
- "#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
2000
- " content: \"▾\";\n",
2001
- "}\n",
2002
- "\n",
2003
- "/* Pipeline/ColumnTransformer-specific style */\n",
2004
- "\n",
2005
- "#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
2006
- " color: var(--sklearn-color-text);\n",
2007
- " background-color: var(--sklearn-color-unfitted-level-2);\n",
2008
- "}\n",
2009
- "\n",
2010
- "#sk-container-id-3 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
2011
- " background-color: var(--sklearn-color-fitted-level-2);\n",
2012
- "}\n",
2013
- "\n",
2014
- "/* Estimator-specific style */\n",
2015
- "\n",
2016
- "/* Colorize estimator box */\n",
2017
- "#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
2018
- " /* unfitted */\n",
2019
- " background-color: var(--sklearn-color-unfitted-level-2);\n",
2020
- "}\n",
2021
- "\n",
2022
- "#sk-container-id-3 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
2023
- " /* fitted */\n",
2024
- " background-color: var(--sklearn-color-fitted-level-2);\n",
2025
- "}\n",
2026
- "\n",
2027
- "#sk-container-id-3 div.sk-label label.sk-toggleable__label,\n",
2028
- "#sk-container-id-3 div.sk-label label {\n",
2029
- " /* The background is the default theme color */\n",
2030
- " color: var(--sklearn-color-text-on-default-background);\n",
2031
- "}\n",
2032
- "\n",
2033
- "/* On hover, darken the color of the background */\n",
2034
- "#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {\n",
2035
- " color: var(--sklearn-color-text);\n",
2036
- " background-color: var(--sklearn-color-unfitted-level-2);\n",
2037
- "}\n",
2038
- "\n",
2039
- "/* Label box, darken color on hover, fitted */\n",
2040
- "#sk-container-id-3 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
2041
- " color: var(--sklearn-color-text);\n",
2042
- " background-color: var(--sklearn-color-fitted-level-2);\n",
2043
- "}\n",
2044
- "\n",
2045
- "/* Estimator label */\n",
2046
- "\n",
2047
- "#sk-container-id-3 div.sk-label label {\n",
2048
- " font-family: monospace;\n",
2049
- " font-weight: bold;\n",
2050
- " display: inline-block;\n",
2051
- " line-height: 1.2em;\n",
2052
- "}\n",
2053
- "\n",
2054
- "#sk-container-id-3 div.sk-label-container {\n",
2055
- " text-align: center;\n",
2056
- "}\n",
2057
- "\n",
2058
- "/* Estimator-specific */\n",
2059
- "#sk-container-id-3 div.sk-estimator {\n",
2060
- " font-family: monospace;\n",
2061
- " border: 1px dotted var(--sklearn-color-border-box);\n",
2062
- " border-radius: 0.25em;\n",
2063
- " box-sizing: border-box;\n",
2064
- " margin-bottom: 0.5em;\n",
2065
- " /* unfitted */\n",
2066
- " background-color: var(--sklearn-color-unfitted-level-0);\n",
2067
- "}\n",
2068
- "\n",
2069
- "#sk-container-id-3 div.sk-estimator.fitted {\n",
2070
- " /* fitted */\n",
2071
- " background-color: var(--sklearn-color-fitted-level-0);\n",
2072
- "}\n",
2073
- "\n",
2074
- "/* on hover */\n",
2075
- "#sk-container-id-3 div.sk-estimator:hover {\n",
2076
- " /* unfitted */\n",
2077
- " background-color: var(--sklearn-color-unfitted-level-2);\n",
2078
- "}\n",
2079
- "\n",
2080
- "#sk-container-id-3 div.sk-estimator.fitted:hover {\n",
2081
- " /* fitted */\n",
2082
- " background-color: var(--sklearn-color-fitted-level-2);\n",
2083
- "}\n",
2084
- "\n",
2085
- "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
2086
- "\n",
2087
- "/* Common style for \"i\" and \"?\" */\n",
2088
- "\n",
2089
- ".sk-estimator-doc-link,\n",
2090
- "a:link.sk-estimator-doc-link,\n",
2091
- "a:visited.sk-estimator-doc-link {\n",
2092
- " float: right;\n",
2093
- " font-size: smaller;\n",
2094
- " line-height: 1em;\n",
2095
- " font-family: monospace;\n",
2096
- " background-color: var(--sklearn-color-background);\n",
2097
- " border-radius: 1em;\n",
2098
- " height: 1em;\n",
2099
- " width: 1em;\n",
2100
- " text-decoration: none !important;\n",
2101
- " margin-left: 1ex;\n",
2102
- " /* unfitted */\n",
2103
- " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
2104
- " color: var(--sklearn-color-unfitted-level-1);\n",
2105
- "}\n",
2106
- "\n",
2107
- ".sk-estimator-doc-link.fitted,\n",
2108
- "a:link.sk-estimator-doc-link.fitted,\n",
2109
- "a:visited.sk-estimator-doc-link.fitted {\n",
2110
- " /* fitted */\n",
2111
- " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
2112
- " color: var(--sklearn-color-fitted-level-1);\n",
2113
- "}\n",
2114
- "\n",
2115
- "/* On hover */\n",
2116
- "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
2117
- ".sk-estimator-doc-link:hover,\n",
2118
- "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
2119
- ".sk-estimator-doc-link:hover {\n",
2120
- " /* unfitted */\n",
2121
- " background-color: var(--sklearn-color-unfitted-level-3);\n",
2122
- " color: var(--sklearn-color-background);\n",
2123
- " text-decoration: none;\n",
2124
- "}\n",
2125
- "\n",
2126
- "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
2127
- ".sk-estimator-doc-link.fitted:hover,\n",
2128
- "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
2129
- ".sk-estimator-doc-link.fitted:hover {\n",
2130
- " /* fitted */\n",
2131
- " background-color: var(--sklearn-color-fitted-level-3);\n",
2132
- " color: var(--sklearn-color-background);\n",
2133
- " text-decoration: none;\n",
2134
- "}\n",
2135
- "\n",
2136
- "/* Span, style for the box shown on hovering the info icon */\n",
2137
- ".sk-estimator-doc-link span {\n",
2138
- " display: none;\n",
2139
- " z-index: 9999;\n",
2140
- " position: relative;\n",
2141
- " font-weight: normal;\n",
2142
- " right: .2ex;\n",
2143
- " padding: .5ex;\n",
2144
- " margin: .5ex;\n",
2145
- " width: min-content;\n",
2146
- " min-width: 20ex;\n",
2147
- " max-width: 50ex;\n",
2148
- " color: var(--sklearn-color-text);\n",
2149
- " box-shadow: 2pt 2pt 4pt #999;\n",
2150
- " /* unfitted */\n",
2151
- " background: var(--sklearn-color-unfitted-level-0);\n",
2152
- " border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
2153
- "}\n",
2154
- "\n",
2155
- ".sk-estimator-doc-link.fitted span {\n",
2156
- " /* fitted */\n",
2157
- " background: var(--sklearn-color-fitted-level-0);\n",
2158
- " border: var(--sklearn-color-fitted-level-3);\n",
2159
- "}\n",
2160
- "\n",
2161
- ".sk-estimator-doc-link:hover span {\n",
2162
- " display: block;\n",
2163
- "}\n",
2164
- "\n",
2165
- "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
2166
- "\n",
2167
- "#sk-container-id-3 a.estimator_doc_link {\n",
2168
- " float: right;\n",
2169
- " font-size: 1rem;\n",
2170
- " line-height: 1em;\n",
2171
- " font-family: monospace;\n",
2172
- " background-color: var(--sklearn-color-background);\n",
2173
- " border-radius: 1rem;\n",
2174
- " height: 1rem;\n",
2175
- " width: 1rem;\n",
2176
- " text-decoration: none;\n",
2177
- " /* unfitted */\n",
2178
- " color: var(--sklearn-color-unfitted-level-1);\n",
2179
- " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
2180
- "}\n",
2181
- "\n",
2182
- "#sk-container-id-3 a.estimator_doc_link.fitted {\n",
2183
- " /* fitted */\n",
2184
- " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
2185
- " color: var(--sklearn-color-fitted-level-1);\n",
2186
- "}\n",
2187
- "\n",
2188
- "/* On hover */\n",
2189
- "#sk-container-id-3 a.estimator_doc_link:hover {\n",
2190
- " /* unfitted */\n",
2191
- " background-color: var(--sklearn-color-unfitted-level-3);\n",
2192
- " color: var(--sklearn-color-background);\n",
2193
- " text-decoration: none;\n",
2194
- "}\n",
2195
- "\n",
2196
- "#sk-container-id-3 a.estimator_doc_link.fitted:hover {\n",
2197
- " /* fitted */\n",
2198
- " background-color: var(--sklearn-color-fitted-level-3);\n",
2199
- "}\n",
2200
- "</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(n_clusters=1, random_state=10)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;&nbsp;KMeans<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.cluster.KMeans.html\">?<span>Documentation for KMeans</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>KMeans(n_clusters=1, random_state=10)</pre></div> </div></div></div></div>"
2201
- ],
2202
- "text/plain": [
2203
- "KMeans(n_clusters=1, random_state=10)"
2204
- ]
2205
- },
2206
- "execution_count": 195,
2207
- "metadata": {},
2208
- "output_type": "execute_result"
2209
  }
2210
  ],
2211
  "source": [
@@ -2217,8 +1807,8 @@
2217
  "np.random.seed(0)\n",
2218
  "X1 = train_predict1[:,1:8] - y_train[:,1:8]\n",
2219
  "X2 = train_predict1[:,8:15] - y_train[:,8:15]\n",
2220
- "X3 = train_predict1[:,15:22] - y_train[:,15:22]\n",
2221
- "X4 = train_predict1[:,22:29] - y_train[:,22:29]\n",
2222
  "\n",
2223
  "k = 1\n",
2224
  "\n",
@@ -2226,30 +1816,30 @@
2226
  "kmeans1.fit(X1)\n",
2227
  "kmeans2 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
2228
  "kmeans2.fit(X2)\n",
2229
- "kmeans3 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
2230
- "kmeans3.fit(X3)\n",
2231
- "kmeans4 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
2232
- "kmeans4.fit(X4)\n",
2233
  "\n",
2234
  "\n",
2235
  "\n",
2236
- "# pca = PCA(n_components=2)\n",
2237
- "# X = pca.fit_transform(X2)\n",
2238
  "\n",
2239
  "\n",
2240
  "\n",
2241
  "\n",
2242
  "# # Getting the cluster centers and labels\n",
2243
- "# centroids = pca.transform(kmeans.cluster_centers_)\n",
2244
- "# labels = kmeans.labels_\n",
2245
- "# print(kmeans.cluster_centers_)\n",
2246
  "# Plotting the data points and cluster centers\n",
2247
- "# plt.scatter(X[:, 0], X[:, 1], c=labels, cmap='viridis', alpha=0.5)\n",
2248
- "# plt.scatter(centroids[:, 0], centroids[:, 1], marker='x', c='red', s=200, linewidths=2)\n",
2249
- "# plt.title('KMeans Clustering')\n",
2250
- "# plt.xlabel('Feature 1')\n",
2251
- "# plt.ylabel('Feature 2')\n",
2252
- "# plt.show()\n"
2253
  ]
2254
  },
2255
  {
@@ -2302,16 +1892,16 @@
2302
  },
2303
  {
2304
  "cell_type": "code",
2305
- "execution_count": 323,
2306
  "metadata": {},
2307
  "outputs": [
2308
  {
2309
  "data": {
2310
  "text/plain": [
2311
- "[<matplotlib.lines.Line2D at 0x228993bb690>]"
2312
  ]
2313
  },
2314
- "execution_count": 323,
2315
  "metadata": {},
2316
  "output_type": "execute_result"
2317
  }
@@ -2321,15 +1911,15 @@
2321
  "\n",
2322
  "distance1 = np.linalg.norm((test_predict1[:,1:8]-y_test[:,1:8])-kmeans1.cluster_centers_[0], ord=2, axis = 1)\n",
2323
  "distance2 = np.linalg.norm((test_predict1[:,8:15]-y_test[:,8:15])-kmeans2.cluster_centers_[0], ord=2, axis = 1)\n",
2324
- "distance3 = np.linalg.norm((test_predict1[:,15:22]-y_test[:,15:22])-kmeans3.cluster_centers_[0], ord=2, axis = 1)\n",
2325
- "distance4 = np.linalg.norm((test_predict1[:,22:29]-y_test[:,22:29])-kmeans4.cluster_centers_[0], ord=2, axis = 1)\n",
2326
  "# distance_a = np.linalg.norm(test_predict1[:,8:]-a, ord=2, axis = 1)\n",
2327
  "# plt.plot(y_test[:,23],alpha=0.6)\n",
2328
- "plt.plot(y_test[:,3],alpha=0.6)\n",
2329
  "# plt.plot(y_test[:,6],alpha=0.6)\n",
2330
- "# plt.plot(y_test[:,7],alpha=0.6)\n",
2331
- "plt.plot(test_predict1[:,3],alpha=0.6)\n",
2332
- "plt.plot(abs(distance1)>2)\n",
2333
  "# plt.plot(abs(distance2)>3.5)\n",
2334
  "# plt.plot(abs(distance3)>5)\n",
2335
  "# plt.plot(abs(distance4)>5)\n",
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 4,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
22
  },
23
  {
24
  "cell_type": "code",
25
+ "execution_count": 5,
26
  "metadata": {},
27
  "outputs": [
28
  {
 
434
  "[2072154 rows x 30 columns]"
435
  ]
436
  },
437
+ "execution_count": 5,
438
  "metadata": {},
439
  "output_type": "execute_result"
440
  }
 
1135
  },
1136
  {
1137
  "cell_type": "code",
1138
+ "execution_count": 6,
1139
  "metadata": {},
1140
  "outputs": [
1141
  {
 
1272
  "[2 rows x 65 columns]"
1273
  ]
1274
  },
1275
+ "execution_count": 6,
1276
  "metadata": {},
1277
  "output_type": "execute_result"
1278
  }
 
1294
  },
1295
  {
1296
  "cell_type": "code",
1297
+ "execution_count": 7,
1298
  "metadata": {},
1299
+ "outputs": [
1300
+ {
1301
+ "name": "stdout",
1302
+ "output_type": "stream",
1303
+ "text": [
1304
+ "There are NA values in the DataFrame columns. [0, 0, 0, 0, 0, 0, 27872, 36554, 15482, 39222, 30748, 37389, 18791, 36175, 31546, 36586, 16271, 36346, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23177, 23177, 0, 0, 0, 0, 0]\n"
1305
+ ]
1306
+ }
1307
+ ],
1308
  "source": [
1309
  "df_filtered['date'] = pd.to_datetime(df_filtered['date'], format = \"%Y-%m-%d %H:%M:%S\")\n",
1310
  "df_filtered = df_filtered[ (df_filtered.date.dt.date >date(2018, 5, 1)) & (df_filtered.date.dt.date< date(2020, 5, 1))] #(2018, 5, 1)\n",
 
1315
  },
1316
  {
1317
  "cell_type": "code",
1318
+ "execution_count": 8,
1319
  "metadata": {},
1320
  "outputs": [],
1321
  "source": [
 
1348
  " 'rtu_004_ma_temp',\n",
1349
  " 'rtu_004_sf_vfd_spd_fbk_tn',\n",
1350
  " 'rtu_004_rf_vfd_spd_fbk_tn',\n",
1351
+ "# 'rtu_001_sa_temp',\n",
1352
+ "# 'rtu_001_oadmpr_pct',\n",
1353
+ "# 'rtu_001_ra_temp',\n",
1354
+ "# 'rtu_001_oa_temp',\n",
1355
+ "# 'rtu_001_ma_temp',\n",
1356
+ "# 'rtu_001_sf_vfd_spd_fbk_tn',\n",
1357
+ "# 'rtu_001_rf_vfd_spd_fbk_tn',\n",
1358
+ "# 'rtu_002_sa_temp',\n",
1359
+ "# 'rtu_002_oadmpr_pct',\n",
1360
+ "# 'rtu_002_ra_temp',\n",
1361
+ "# 'rtu_002_oa_temp',\n",
1362
+ "# 'rtu_002_ma_temp',\n",
1363
+ "# 'rtu_002_sf_vfd_spd_fbk_tn',\n",
1364
+ "# 'rtu_002_rf_vfd_spd_fbk_tn',\n",
1365
+ " 'rtu_003_sat_sp_tn',\n",
1366
+ " 'rtu_004_sat_sp_tn',\n",
1367
  " 'air_temp_set_1',\n",
1368
  " 'air_temp_set_2',\n",
1369
  " 'dew_point_temperature_set_1d',\n",
 
1373
  },
1374
  {
1375
  "cell_type": "code",
1376
+ "execution_count": 23,
1377
  "metadata": {},
1378
  "outputs": [
1379
  {
 
1390
  "# df_filtered.to_csv(\"sample_data.csv\",index=False)\n",
1391
  "\n",
1392
  "#----------------------------------------------------------------------------------\n",
1393
+ "testdataset_df = df_filtered[(df_filtered.date.dt.date >date(2019, 7, 21))]\n",
1394
  "\n",
1395
+ "traindataset_df = df_filtered[(df_filtered.date.dt.date <date(2019, 7, 21))]\n",
1396
  "\n",
1397
+ "# testdataset_df = df_filtered[(df_filtered.date.dt.date >date(2020, 1, 1))]\n",
1398
  "\n",
1399
+ "# traindataset_df = df_filtered[(df_filtered.date.dt.date <date(2020, 1, 1))]\n",
1400
  "\n",
1401
  "\n",
1402
  "# testdataset_df.to_csv(\"sample_data_02.csv\",index=False)\n",
 
1413
  },
1414
  {
1415
  "cell_type": "code",
1416
+ "execution_count": 24,
1417
  "metadata": {},
1418
  "outputs": [
1419
  {
 
1459
  },
1460
  {
1461
  "cell_type": "code",
1462
+ "execution_count": 25,
1463
  "metadata": {},
1464
  "outputs": [
1465
  {
 
1474
  "name": "stdout",
1475
  "output_type": "stream",
1476
  "text": [
1477
+ "Epoch 1/2\n",
1478
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 0.0577\n",
1479
+ "Epoch 1: val_loss improved from inf to 0.08234, saving model to lstm_2rtu_smooth_03.keras\n",
1480
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m234s\u001b[0m 29ms/step - loss: 0.0577 - val_loss: 0.0823\n",
1481
+ "Epoch 2/2\n",
1482
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.6307e-04\n",
1483
+ "Epoch 2: val_loss improved from 0.08234 to 0.07465, saving model to lstm_2rtu_smooth_03.keras\n",
1484
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m232s\u001b[0m 29ms/step - loss: 8.6305e-04 - val_loss: 0.0747\n"
 
 
 
 
 
 
 
 
 
 
 
 
1485
  ]
1486
  },
1487
  {
1488
  "data": {
1489
  "text/plain": [
1490
+ "<keras.src.callbacks.history.History at 0x207d62cebd0>"
1491
  ]
1492
  },
1493
+ "execution_count": 25,
1494
  "metadata": {},
1495
  "output_type": "execute_result"
1496
  }
 
1498
  "source": [
1499
  "#2 rtu model\n",
1500
  "\n",
1501
+ "train,test = traindataset,testdataset\n",
1502
+ "\n",
1503
+ "def create_dataset(dataset,time_step):\n",
1504
+ " x = [[] for _ in range(22)] \n",
1505
+ " Y = []\n",
1506
+ " for i in range(len(dataset) - time_step - 1):\n",
1507
+ " for j in range(22):\n",
1508
+ " x[j].append(dataset[i:(i + time_step), j])\n",
1509
+ " Y.append([dataset[i + time_step, 0],dataset[i + time_step, 1],dataset[i + time_step, 2],dataset[i + time_step, 3],\n",
1510
+ " dataset[i + time_step, 4],dataset[i + time_step, 5],\n",
1511
+ " dataset[i + time_step, 6],dataset[i + time_step, 7],\n",
1512
+ " dataset[i + time_step, 8],dataset[i + time_step, 9],dataset[i + time_step, 10],\n",
1513
+ " dataset[i + time_step, 11],dataset[i + time_step, 12],\n",
1514
+ " dataset[i + time_step, 13],dataset[i + time_step, 14]])\n",
1515
+ " x= [np.array(feature_list) for feature_list in x]\n",
1516
+ " Y = np.reshape(Y,(len(Y),15))\n",
1517
+ " return np.stack(x,axis=2),Y\n",
1518
+ "\n",
1519
+ "time_step = 30\n",
1520
+ "X_train, y_train = create_dataset(train, time_step)\n",
1521
+ "X_test, y_test = create_dataset(test, time_step)\n",
1522
+ "\n",
1523
+ "\n",
1524
+ "model = Sequential()\n",
1525
+ "model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))\n",
1526
+ "model.add(LSTM(units=50, return_sequences=True))\n",
1527
+ "model.add(LSTM(units=30))\n",
1528
+ "model.add(Dense(units=15))\n",
1529
+ "\n",
1530
+ "model.compile(optimizer='adam', loss='mean_squared_error')\n",
1531
+ "\n",
1532
+ "checkpoint_path = \"lstm_2rtu_smooth_03.keras\"\n",
1533
+ "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
1534
+ "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=2, batch_size=64, verbose=1, callbacks=[checkpoint_callback])"
1535
  ]
1536
  },
1537
  {
 
1693
  },
1694
  {
1695
  "cell_type": "code",
1696
+ "execution_count": 26,
1697
  "metadata": {},
1698
  "outputs": [
1699
  {
1700
  "name": "stdout",
1701
  "output_type": "stream",
1702
  "text": [
1703
+ "\u001b[1m19190/19190\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m95s\u001b[0m 5ms/step\n",
1704
+ "\u001b[1m16134/16134\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m83s\u001b[0m 5ms/step\n"
1705
  ]
1706
  }
1707
  ],
1708
  "source": [
1709
  "test_predict1 = model.predict(X_test)\n",
1710
+ "train_predict1 = model.predict(X_train)"
1711
  ]
1712
  },
1713
  {
1714
  "cell_type": "code",
1715
+ "execution_count": 35,
1716
  "metadata": {},
1717
  "outputs": [],
1718
  "source": [
1719
  "%matplotlib qt\n",
1720
+ "var = 7\n",
1721
  "plt.plot(y_test[:,var], label='Original Testing Data', color='blue')\n",
1722
+ "plt.plot(test_predict1[:,var], label='Predicted Testing Data', color='red',alpha=0.8)\n",
1723
  "# anomalies = np.where(abs(test_predict1[:,var] - y_test[:,var]) > 0.38)\n",
1724
  "# plt.scatter(anomalies,test_predict1[anomalies,var], color='black',marker =\"o\",s=100 )\n",
1725
  "\n",
 
1786
  },
1787
  {
1788
  "cell_type": "code",
1789
+ "execution_count": 43,
1790
  "metadata": {},
1791
  "outputs": [
1792
  {
1793
+ "name": "stdout",
1794
+ "output_type": "stream",
1795
+ "text": [
1796
+ "[[ 0.00183319 0.01064136 0.01099219 0.01235903 0.01590783 0.0086837\n",
1797
+ " -0.00136298]]\n"
1798
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1799
  }
1800
  ],
1801
  "source": [
 
1807
  "np.random.seed(0)\n",
1808
  "X1 = train_predict1[:,1:8] - y_train[:,1:8]\n",
1809
  "X2 = train_predict1[:,8:15] - y_train[:,8:15]\n",
1810
+ "# X3 = train_predict1[:,15:22] - y_train[:,15:22]\n",
1811
+ "# X4 = train_predict1[:,22:29] - y_train[:,22:29]\n",
1812
  "\n",
1813
  "k = 1\n",
1814
  "\n",
 
1816
  "kmeans1.fit(X1)\n",
1817
  "kmeans2 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
1818
  "kmeans2.fit(X2)\n",
1819
+ "# kmeans3 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
1820
+ "# kmeans3.fit(X3)\n",
1821
+ "# kmeans4 = KMeans(n_clusters=k, random_state=10) #2 for without smoothing\n",
1822
+ "# kmeans4.fit(X4)\n",
1823
  "\n",
1824
  "\n",
1825
  "\n",
1826
+ "pca = PCA(n_components=2)\n",
1827
+ "X = pca.fit_transform(X1)\n",
1828
  "\n",
1829
  "\n",
1830
  "\n",
1831
  "\n",
1832
  "# # Getting the cluster centers and labels\n",
1833
+ "centroids = pca.transform(kmeans1.cluster_centers_)\n",
1834
+ "labels = kmeans1.labels_\n",
1835
+ "print(kmeans1.cluster_centers_)\n",
1836
  "# Plotting the data points and cluster centers\n",
1837
+ "plt.scatter(X[:, 0], X[:, 1], c=labels, cmap='viridis', alpha=0.5)\n",
1838
+ "plt.scatter(centroids[:, 0], centroids[:, 1], marker='x', c='red', s=200, linewidths=2)\n",
1839
+ "plt.title('KMeans Clustering')\n",
1840
+ "plt.xlabel('Feature 1')\n",
1841
+ "plt.ylabel('Feature 2')\n",
1842
+ "plt.show()\n"
1843
  ]
1844
  },
1845
  {
 
1892
  },
1893
  {
1894
  "cell_type": "code",
1895
+ "execution_count": 41,
1896
  "metadata": {},
1897
  "outputs": [
1898
  {
1899
  "data": {
1900
  "text/plain": [
1901
+ "[<matplotlib.lines.Line2D at 0x207c1f8ce90>]"
1902
  ]
1903
  },
1904
+ "execution_count": 41,
1905
  "metadata": {},
1906
  "output_type": "execute_result"
1907
  }
 
1911
  "\n",
1912
  "distance1 = np.linalg.norm((test_predict1[:,1:8]-y_test[:,1:8])-kmeans1.cluster_centers_[0], ord=2, axis = 1)\n",
1913
  "distance2 = np.linalg.norm((test_predict1[:,8:15]-y_test[:,8:15])-kmeans2.cluster_centers_[0], ord=2, axis = 1)\n",
1914
+ "# distance3 = np.linalg.norm((test_predict1[:,15:22]-y_test[:,15:22])-kmeans3.cluster_centers_[0], ord=2, axis = 1)\n",
1915
+ "# distance4 = np.linalg.norm((test_predict1[:,22:29]-y_test[:,22:29])-kmeans4.cluster_centers_[0], ord=2, axis = 1)\n",
1916
  "# distance_a = np.linalg.norm(test_predict1[:,8:]-a, ord=2, axis = 1)\n",
1917
  "# plt.plot(y_test[:,23],alpha=0.6)\n",
1918
+ "# plt.plot(y_test[:,3],alpha=0.6)\n",
1919
  "# plt.plot(y_test[:,6],alpha=0.6)\n",
1920
+ "plt.plot(y_test[:,7],alpha=0.6)\n",
1921
+ "# plt.plot(test_predict1[:,3],alpha=0.6)\n",
1922
+ "plt.plot(abs(distance1)>2.5)\n",
1923
  "# plt.plot(abs(distance2)>3.5)\n",
1924
  "# plt.plot(abs(distance3)>5)\n",
1925
  "# plt.plot(abs(distance4)>5)\n",
lstm_2rtu_smooth_03.keras ADDED
Binary file (575 kB). View file
 
src/main.py CHANGED
@@ -23,7 +23,8 @@ def main():
23
  # print(json.loads(message.payload.decode()))
24
  df_new, df_trans = rtu_data_pipeline.fit(message)
25
  if not df_new is None and not df_trans is None:
26
- out = rtu_anomalizer.pipeline(df_new, df_trans, rtu_data_pipeline.scaler)
 
27
 
28
  broker_address = "localhost"
29
  broker_port = 1883
 
23
  # print(json.loads(message.payload.decode()))
24
  df_new, df_trans = rtu_data_pipeline.fit(message)
25
  if not df_new is None and not df_trans is None:
26
+ out1,out2,out3,out4 = rtu_anomalizer.pipeline(df_new, df_trans, rtu_data_pipeline.scaler)
27
+ print(out3)
28
 
29
  broker_address = "localhost"
30
  broker_port = 1883
streamlit.py CHANGED
@@ -12,14 +12,14 @@ import plotly.graph_objects as go
12
  warnings.filterwarnings('ignore')
13
 
14
 
15
- model = load_model("lstm_4rtu_smooth_02.keras")
16
- scaler = joblib.load('scaler_1.pkl')
17
  # kmeans = joblib.load('kmeans_model.pkl')
18
- kmeans1 = joblib.load('kmeans_model1.pkl')
19
- kmeans2 = joblib.load('kmeans_model2.pkl')
20
- kmeans3 = joblib.load('kmeans_model3.pkl')
21
- kmeans4 = joblib.load('kmeans_model4.pkl')
22
- pca = joblib.load('pca_model.pkl')
23
 
24
  st.set_page_config(
25
  page_title = 'Real-Time Data Buliding 59',
@@ -63,10 +63,10 @@ df = pd.DataFrame(columns=['hp_hws_temp',
63
  'rtu_002_ma_temp',
64
  'rtu_002_sf_vfd_spd_fbk_tn',
65
  'rtu_002_rf_vfd_spd_fbk_tn',
66
- 'rtu_004_sat_sp_tn',
67
- 'rtu_003_sat_sp_tn',
68
- 'rtu_001_sat_sp_tn',
69
- 'rtu_002_sat_sp_tn',
70
  'air_temp_set_1',
71
  'air_temp_set_2',
72
  'dew_point_temperature_set_1d',
@@ -112,10 +112,10 @@ def on_message(client, userdata, message):
112
  rtu_002_ma_temp = payload['rtu_002_ma_temp']
113
  rtu_002_sf_vfd_spd_fbk_tn = payload['rtu_002_sf_vfd_spd_fbk_tn']
114
  rtu_002_rf_vfd_spd_fbk_tn = payload['rtu_002_rf_vfd_spd_fbk_tn']
115
- rtu_004_sat_sp_tn = payload['rtu_004_sat_sp_tn']
116
- rtu_003_sat_sp_tn = payload['rtu_003_sat_sp_tn']
117
- rtu_001_sat_sp_tn = payload['rtu_001_sat_sp_tn']
118
- rtu_002_sat_sp_tn = payload['rtu_002_sat_sp_tn']
119
  air_temp_set_1 = payload['air_temp_set_1']
120
  air_temp_set_2 = payload['air_temp_set_2']
121
  dew_point_temperature_set_1d = payload['dew_point_temperature_set_1d']
@@ -152,10 +152,10 @@ def on_message(client, userdata, message):
152
  'rtu_002_ma_temp':rtu_002_ma_temp,
153
  'rtu_002_sf_vfd_spd_fbk_tn':rtu_002_sf_vfd_spd_fbk_tn,
154
  'rtu_002_rf_vfd_spd_fbk_tn':rtu_002_rf_vfd_spd_fbk_tn,
155
- 'rtu_004_sat_sp_tn':rtu_004_sat_sp_tn,
156
- 'rtu_003_sat_sp_tn' :rtu_003_sat_sp_tn,
157
- 'rtu_001_sat_sp_tn':rtu_001_sat_sp_tn,
158
- 'rtu_002_sat_sp_tn':rtu_002_sat_sp_tn,
159
  'air_temp_set_1':air_temp_set_1,
160
  'air_temp_set_2':air_temp_set_2,
161
  'dew_point_temperature_set_1d':dew_point_temperature_set_1d,
 
12
  warnings.filterwarnings('ignore')
13
 
14
 
15
+ model = load_model(r"src\rtu\models\lstm_4rtu_smooth_02.keras")
16
+ scaler = joblib.load(r'src\rtu\models\scaler_1.pkl')
17
  # kmeans = joblib.load('kmeans_model.pkl')
18
+ kmeans1 = joblib.load(r'src\rtu\models\kmeans_model1.pkl')
19
+ kmeans2 = joblib.load(r'src\rtu\models\kmeans_model2.pkl')
20
+ kmeans3 = joblib.load(r'src\rtu\models\kmeans_model3.pkl')
21
+ kmeans4 = joblib.load(r'src\rtu\models\kmeans_model4.pkl')
22
+ # pca = joblib.load('pca_model.pkl')
23
 
24
  st.set_page_config(
25
  page_title = 'Real-Time Data Buliding 59',
 
63
  'rtu_002_ma_temp',
64
  'rtu_002_sf_vfd_spd_fbk_tn',
65
  'rtu_002_rf_vfd_spd_fbk_tn',
66
+ # 'rtu_004_sat_sp_tn',
67
+ # 'rtu_003_sat_sp_tn',
68
+ # 'rtu_001_sat_sp_tn',
69
+ # 'rtu_002_sat_sp_tn',
70
  'air_temp_set_1',
71
  'air_temp_set_2',
72
  'dew_point_temperature_set_1d',
 
112
  rtu_002_ma_temp = payload['rtu_002_ma_temp']
113
  rtu_002_sf_vfd_spd_fbk_tn = payload['rtu_002_sf_vfd_spd_fbk_tn']
114
  rtu_002_rf_vfd_spd_fbk_tn = payload['rtu_002_rf_vfd_spd_fbk_tn']
115
+ # rtu_004_sat_sp_tn = payload['rtu_004_sat_sp_tn']
116
+ # rtu_003_sat_sp_tn = payload['rtu_003_sat_sp_tn']
117
+ # rtu_001_sat_sp_tn = payload['rtu_001_sat_sp_tn']
118
+ # rtu_002_sat_sp_tn = payload['rtu_002_sat_sp_tn']
119
  air_temp_set_1 = payload['air_temp_set_1']
120
  air_temp_set_2 = payload['air_temp_set_2']
121
  dew_point_temperature_set_1d = payload['dew_point_temperature_set_1d']
 
152
  'rtu_002_ma_temp':rtu_002_ma_temp,
153
  'rtu_002_sf_vfd_spd_fbk_tn':rtu_002_sf_vfd_spd_fbk_tn,
154
  'rtu_002_rf_vfd_spd_fbk_tn':rtu_002_rf_vfd_spd_fbk_tn,
155
+ # 'rtu_004_sat_sp_tn':rtu_004_sat_sp_tn,
156
+ # 'rtu_003_sat_sp_tn' :rtu_003_sat_sp_tn,
157
+ # 'rtu_001_sat_sp_tn':rtu_001_sat_sp_tn,
158
+ # 'rtu_002_sat_sp_tn':rtu_002_sat_sp_tn,
159
  'air_temp_set_1':air_temp_set_1,
160
  'air_temp_set_2':air_temp_set_2,
161
  'dew_point_temperature_set_1d':dew_point_temperature_set_1d,