jerin commited on
Commit
21a4a75
β€’
1 Parent(s): be37c76

update LSTM 2 rtu model

Browse files
Files changed (3) hide show
  1. lstm.ipynb +108 -97
  2. lstm_2rtu_smooth_04.keras +0 -0
  3. mqttpublisher.ipynb +0 -0
lstm.ipynb CHANGED
@@ -1135,7 +1135,7 @@
1135
  },
1136
  {
1137
  "cell_type": "code",
1138
- "execution_count": 6,
1139
  "metadata": {},
1140
  "outputs": [
1141
  {
@@ -1272,7 +1272,7 @@
1272
  "[2 rows x 65 columns]"
1273
  ]
1274
  },
1275
- "execution_count": 6,
1276
  "metadata": {},
1277
  "output_type": "execute_result"
1278
  }
@@ -1294,7 +1294,7 @@
1294
  },
1295
  {
1296
  "cell_type": "code",
1297
- "execution_count": 7,
1298
  "metadata": {},
1299
  "outputs": [
1300
  {
@@ -1315,7 +1315,27 @@
1315
  },
1316
  {
1317
  "cell_type": "code",
1318
- "execution_count": 8,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1319
  "metadata": {},
1320
  "outputs": [],
1321
  "source": [
@@ -1334,36 +1354,38 @@
1334
  "# 'solar_radiation_set_1']]\n",
1335
  "\n",
1336
  "df_filtered = df_filtered.loc[:,['date','hp_hws_temp',\n",
1337
- " 'rtu_003_sa_temp',\n",
1338
- " 'rtu_003_oadmpr_pct',\n",
1339
- " 'rtu_003_ra_temp',\n",
1340
- " 'rtu_003_oa_temp',\n",
1341
- " 'rtu_003_ma_temp',\n",
1342
- " 'rtu_003_sf_vfd_spd_fbk_tn',\n",
1343
- " 'rtu_003_rf_vfd_spd_fbk_tn',\n",
1344
- " 'rtu_004_sa_temp',\n",
1345
- " 'rtu_004_oadmpr_pct',\n",
1346
- " 'rtu_004_ra_temp',\n",
1347
- " 'rtu_004_oa_temp',\n",
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,7 +1395,7 @@
1373
  },
1374
  {
1375
  "cell_type": "code",
1376
- "execution_count": 23,
1377
  "metadata": {},
1378
  "outputs": [
1379
  {
@@ -1413,7 +1435,7 @@
1413
  },
1414
  {
1415
  "cell_type": "code",
1416
- "execution_count": 24,
1417
  "metadata": {},
1418
  "outputs": [
1419
  {
@@ -1459,7 +1481,7 @@
1459
  },
1460
  {
1461
  "cell_type": "code",
1462
- "execution_count": 25,
1463
  "metadata": {},
1464
  "outputs": [
1465
  {
@@ -1475,22 +1497,22 @@
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
  }
@@ -1529,7 +1551,7 @@
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
  ]
@@ -1675,12 +1697,12 @@
1675
  },
1676
  {
1677
  "cell_type": "code",
1678
- "execution_count": 284,
1679
  "metadata": {},
1680
  "outputs": [],
1681
  "source": [
1682
  "from tensorflow.keras.models import load_model\n",
1683
- "checkpoint_path = \"lstm_4rtu_smooth_02.keras\"\n",
1684
  "model = load_model(checkpoint_path)"
1685
  ]
1686
  },
@@ -1693,15 +1715,15 @@
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
  ],
@@ -1712,14 +1734,15 @@
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,15 +1809,15 @@
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
  ],
@@ -1892,20 +1915,9 @@
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
- }
1908
- ],
1909
  "source": [
1910
  "%matplotlib qt\n",
1911
  "\n",
@@ -1915,17 +1927,22 @@
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",
1926
  "# plt.plot(distance_a>8,c='g')\n",
1927
- "\n",
1928
- " "
 
 
 
1929
  ]
1930
  },
1931
  {
@@ -1981,31 +1998,25 @@
1981
  },
1982
  {
1983
  "cell_type": "code",
1984
- "execution_count": 77,
1985
  "metadata": {},
1986
- "outputs": [
1987
- {
1988
- "data": {
1989
- "text/plain": [
1990
- "array([[ 5.8607887e-02, -2.4713947e-01, 2.4978706e-01, -7.8289807e-01,\n",
1991
- " -2.0218764e-01, -2.8860569e-01, 2.7817219e-01, 2.4209845e-01],\n",
1992
- " [-2.6845999e-02, 1.2596852e-01, 9.6294099e-01, 2.0099232e-01,\n",
1993
- " 3.3391420e-02, 7.7613303e-04, -7.1204931e-02, -9.7836025e-02]],\n",
1994
- " dtype=float32)"
1995
- ]
1996
- },
1997
- "execution_count": 77,
1998
- "metadata": {},
1999
- "output_type": "execute_result"
2000
- }
2001
- ],
2002
  "source": [
2003
- "pca.components_"
 
 
 
 
 
 
 
 
 
2004
  ]
2005
  },
2006
  {
2007
  "cell_type": "code",
2008
- "execution_count": 84,
2009
  "metadata": {},
2010
  "outputs": [],
2011
  "source": [
@@ -2026,7 +2037,7 @@
2026
  },
2027
  {
2028
  "cell_type": "code",
2029
- "execution_count": 38,
2030
  "metadata": {},
2031
  "outputs": [
2032
  {
@@ -2036,7 +2047,7 @@
2036
  "traceback": [
2037
  "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
2038
  "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
2039
- "Cell \u001b[1;32mIn[38], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m X \u001b[38;5;241m=\u001b[39m \u001b[43mprocessed_data\u001b[49m\n\u001b[0;32m 4\u001b[0m k \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m 6\u001b[0m kmeans \u001b[38;5;241m=\u001b[39m KMeans(n_clusters\u001b[38;5;241m=\u001b[39mk,random_state\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m)\n",
2040
  "\u001b[1;31mNameError\u001b[0m: name 'processed_data' is not defined"
2041
  ]
2042
  }
 
1135
  },
1136
  {
1137
  "cell_type": "code",
1138
+ "execution_count": 110,
1139
  "metadata": {},
1140
  "outputs": [
1141
  {
 
1272
  "[2 rows x 65 columns]"
1273
  ]
1274
  },
1275
+ "execution_count": 110,
1276
  "metadata": {},
1277
  "output_type": "execute_result"
1278
  }
 
1294
  },
1295
  {
1296
  "cell_type": "code",
1297
+ "execution_count": 111,
1298
  "metadata": {},
1299
  "outputs": [
1300
  {
 
1315
  },
1316
  {
1317
  "cell_type": "code",
1318
+ "execution_count": 179,
1319
+ "metadata": {},
1320
+ "outputs": [
1321
+ {
1322
+ "data": {
1323
+ "text/plain": [
1324
+ "[<matplotlib.lines.Line2D at 0x207d4f52890>]"
1325
+ ]
1326
+ },
1327
+ "execution_count": 179,
1328
+ "metadata": {},
1329
+ "output_type": "execute_result"
1330
+ }
1331
+ ],
1332
+ "source": [
1333
+ "plt.plot(df_filtered['rtu_002_rf_vfd_spd_fbk_tn'])"
1334
+ ]
1335
+ },
1336
+ {
1337
+ "cell_type": "code",
1338
+ "execution_count": 112,
1339
  "metadata": {},
1340
  "outputs": [],
1341
  "source": [
 
1354
  "# 'solar_radiation_set_1']]\n",
1355
  "\n",
1356
  "df_filtered = df_filtered.loc[:,['date','hp_hws_temp',\n",
1357
+ "# 'rtu_003_sa_temp',\n",
1358
+ "# 'rtu_003_oadmpr_pct',\n",
1359
+ "# 'rtu_003_ra_temp',\n",
1360
+ "# 'rtu_003_oa_temp',\n",
1361
+ "# 'rtu_003_ma_temp',\n",
1362
+ "# 'rtu_003_sf_vfd_spd_fbk_tn',\n",
1363
+ "# 'rtu_003_rf_vfd_spd_fbk_tn',\n",
1364
+ "# 'rtu_004_sa_temp',\n",
1365
+ "# 'rtu_004_oadmpr_pct',\n",
1366
+ "# 'rtu_004_ra_temp',\n",
1367
+ "# 'rtu_004_oa_temp',\n",
1368
+ "# 'rtu_004_ma_temp',\n",
1369
+ "# 'rtu_004_sf_vfd_spd_fbk_tn',\n",
1370
+ "# 'rtu_004_rf_vfd_spd_fbk_tn',\n",
1371
+ " 'rtu_001_sa_temp',\n",
1372
+ " 'rtu_001_oadmpr_pct',\n",
1373
+ " 'rtu_001_ra_temp',\n",
1374
+ " 'rtu_001_oa_temp',\n",
1375
+ " 'rtu_001_ma_temp',\n",
1376
+ " 'rtu_001_sf_vfd_spd_fbk_tn',\n",
1377
+ " 'rtu_001_rf_vfd_spd_fbk_tn',\n",
1378
+ " 'rtu_002_sa_temp',\n",
1379
+ " 'rtu_002_oadmpr_pct',\n",
1380
+ " 'rtu_002_ra_temp',\n",
1381
+ " 'rtu_002_oa_temp',\n",
1382
+ " 'rtu_002_ma_temp',\n",
1383
+ " 'rtu_002_sf_vfd_spd_fbk_tn',\n",
1384
+ " 'rtu_002_rf_vfd_spd_fbk_tn',\n",
1385
+ "# 'rtu_003_sat_sp_tn',\n",
1386
+ "# 'rtu_004_sat_sp_tn',\n",
1387
+ " 'rtu_001_sat_sp_tn',\n",
1388
+ " 'rtu_002_sat_sp_tn',\n",
1389
  " 'air_temp_set_1',\n",
1390
  " 'air_temp_set_2',\n",
1391
  " 'dew_point_temperature_set_1d',\n",
 
1395
  },
1396
  {
1397
  "cell_type": "code",
1398
+ "execution_count": 113,
1399
  "metadata": {},
1400
  "outputs": [
1401
  {
 
1435
  },
1436
  {
1437
  "cell_type": "code",
1438
+ "execution_count": 114,
1439
  "metadata": {},
1440
  "outputs": [
1441
  {
 
1481
  },
1482
  {
1483
  "cell_type": "code",
1484
+ "execution_count": 115,
1485
  "metadata": {},
1486
  "outputs": [
1487
  {
 
1497
  "output_type": "stream",
1498
  "text": [
1499
  "Epoch 1/2\n",
1500
+ "\u001b[1m8066/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 0.0548\n",
1501
+ "Epoch 1: val_loss improved from inf to 0.34488, saving model to lstm_2rtu_smooth_04.keras\n",
1502
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m165s\u001b[0m 20ms/step - loss: 0.0548 - val_loss: 0.3449\n",
1503
  "Epoch 2/2\n",
1504
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 0.0014\n",
1505
+ "Epoch 2: val_loss improved from 0.34488 to 0.27523, saving model to lstm_2rtu_smooth_04.keras\n",
1506
+ "\u001b[1m8067/8067\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m160s\u001b[0m 20ms/step - loss: 0.0014 - val_loss: 0.2752\n"
1507
  ]
1508
  },
1509
  {
1510
  "data": {
1511
  "text/plain": [
1512
+ "<keras.src.callbacks.history.History at 0x207bef58850>"
1513
  ]
1514
  },
1515
+ "execution_count": 115,
1516
  "metadata": {},
1517
  "output_type": "execute_result"
1518
  }
 
1551
  "\n",
1552
  "model.compile(optimizer='adam', loss='mean_squared_error')\n",
1553
  "\n",
1554
+ "checkpoint_path = \"lstm_2rtu_smooth_04.keras\" #\"lstm_2rtu_smooth_03.keras\"--> 3,4rtu\n",
1555
  "checkpoint_callback = ModelCheckpoint(filepath=checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n",
1556
  "model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=2, batch_size=64, verbose=1, callbacks=[checkpoint_callback])"
1557
  ]
 
1697
  },
1698
  {
1699
  "cell_type": "code",
1700
+ "execution_count": 89,
1701
  "metadata": {},
1702
  "outputs": [],
1703
  "source": [
1704
  "from tensorflow.keras.models import load_model\n",
1705
+ "checkpoint_path = \"lstm_2rtu_smooth_03.keras\"\n",
1706
  "model = load_model(checkpoint_path)"
1707
  ]
1708
  },
 
1715
  },
1716
  {
1717
  "cell_type": "code",
1718
+ "execution_count": 116,
1719
  "metadata": {},
1720
  "outputs": [
1721
  {
1722
  "name": "stdout",
1723
  "output_type": "stream",
1724
  "text": [
1725
+ "\u001b[1m19190/19190\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m78s\u001b[0m 4ms/step\n",
1726
+ "\u001b[1m16134/16134\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m63s\u001b[0m 4ms/step\n"
1727
  ]
1728
  }
1729
  ],
 
1734
  },
1735
  {
1736
  "cell_type": "code",
1737
+ "execution_count": 148,
1738
  "metadata": {},
1739
  "outputs": [],
1740
  "source": [
1741
  "%matplotlib qt\n",
1742
+ "var = 5\n",
1743
+ "plt.plot(testdataset_df['date'][31:], y_test[:,var], label='Original Testing Data')\n",
1744
+ "plt.plot(testdataset_df['date'][31:] ,test_predict1[:,var], label='Predicted Testing Data')\n",
1745
+ "\n",
1746
  "# anomalies = np.where(abs(test_predict1[:,var] - y_test[:,var]) > 0.38)\n",
1747
  "# plt.scatter(anomalies,test_predict1[anomalies,var], color='black',marker =\"o\",s=100 )\n",
1748
  "\n",
 
1809
  },
1810
  {
1811
  "cell_type": "code",
1812
+ "execution_count": 150,
1813
  "metadata": {},
1814
  "outputs": [
1815
  {
1816
  "name": "stdout",
1817
  "output_type": "stream",
1818
  "text": [
1819
+ "[[ 0.00056891 -0.00128509 0.00987136 -0.00519864 0.01173089 0.00975552\n",
1820
+ " 0.01170705]]\n"
1821
  ]
1822
  }
1823
  ],
 
1915
  },
1916
  {
1917
  "cell_type": "code",
1918
+ "execution_count": 185,
1919
  "metadata": {},
1920
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
1921
  "source": [
1922
  "%matplotlib qt\n",
1923
  "\n",
 
1927
  "# distance4 = np.linalg.norm((test_predict1[:,22:29]-y_test[:,22:29])-kmeans4.cluster_centers_[0], ord=2, axis = 1)\n",
1928
  "# distance_a = np.linalg.norm(test_predict1[:,8:]-a, ord=2, axis = 1)\n",
1929
  "# plt.plot(y_test[:,23],alpha=0.6)\n",
1930
+ "# plt.plot(y_test[:,7],alpha=0.6)\n",
1931
  "# plt.plot(y_test[:,6],alpha=0.6)\n",
1932
+ "# plt.plot(testdataset_df['date'][31:] ,y_test[:,14],alpha=0.6,label='Return air fan speed')\n",
1933
+ "# plt.plot(testdataset_df['date'][31:] ,y_test[:,9],alpha=0.6,label='Damper position')\n",
1934
  "# plt.plot(test_predict1[:,3],alpha=0.6)\n",
1935
+ "plt.plot(testdataset_df['date'][31:] ,abs(distance2)>3.5,linewidth=2.5,label='Faults')\n",
1936
+ "plt.plot(testdataset_df['date'][31:] ,pd.Series((distance2)>3.5).rolling(window=60,min_periods=1).mean()==1,linewidth=2.5,label='Faults')\n",
1937
  "# plt.plot(abs(distance2)>3.5)\n",
1938
  "# plt.plot(abs(distance3)>5)\n",
1939
  "# plt.plot(abs(distance4)>5)\n",
1940
  "# plt.plot(distance_a>8,c='g')\n",
1941
+ "plt.title('RTU-2 Faults')\n",
1942
+ "plt.xlabel('Time')\n",
1943
+ "plt.ylabel('Value')\n",
1944
+ "plt.legend()\n",
1945
+ "plt.show()\n"
1946
  ]
1947
  },
1948
  {
 
1998
  },
1999
  {
2000
  "cell_type": "code",
2001
+ "execution_count": 166,
2002
  "metadata": {},
2003
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2004
  "source": [
2005
+ "distance2 = np.linalg.norm((test_predict1[:,8:15]-y_test[:,8:15])-kmeans2.cluster_centers_[0], ord=2, axis = 1)\n",
2006
+ "X = pca.transform((test_predict1[:,8:15]-y_test[:,8:15])-kmeans2.cluster_centers_[0])\n",
2007
+ "centroids = pca.transform(kmeans2.cluster_centers_)\n",
2008
+ "\n",
2009
+ "plt.scatter(X[:, 0], X[:, 1], c = abs(distance2)>10 ,cmap='viridis', alpha=0.5)\n",
2010
+ "plt.scatter(centroids[:, 0], centroids[:, 1], marker='x', c='red', s=200, linewidths=2)\n",
2011
+ "plt.title('KMeans Clustering')\n",
2012
+ "plt.xlabel('Feature 1')\n",
2013
+ "plt.ylabel('Feature 2')\n",
2014
+ "plt.show()"
2015
  ]
2016
  },
2017
  {
2018
  "cell_type": "code",
2019
+ "execution_count": 155,
2020
  "metadata": {},
2021
  "outputs": [],
2022
  "source": [
 
2037
  },
2038
  {
2039
  "cell_type": "code",
2040
+ "execution_count": 154,
2041
  "metadata": {},
2042
  "outputs": [
2043
  {
 
2047
  "traceback": [
2048
  "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
2049
  "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
2050
+ "Cell \u001b[1;32mIn[154], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m X \u001b[38;5;241m=\u001b[39m \u001b[43mprocessed_data\u001b[49m\n\u001b[0;32m 4\u001b[0m k \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m2\u001b[39m\n\u001b[0;32m 6\u001b[0m kmeans \u001b[38;5;241m=\u001b[39m KMeans(n_clusters\u001b[38;5;241m=\u001b[39mk,random_state\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m)\n",
2051
  "\u001b[1;31mNameError\u001b[0m: name 'processed_data' is not defined"
2052
  ]
2053
  }
lstm_2rtu_smooth_04.keras ADDED
Binary file (575 kB). View file
 
mqttpublisher.ipynb CHANGED
The diff for this file is too large to render. See raw diff