akshayballal commited on
Commit
4bb0525
2 Parent(s): 1245467 6fbf053

Merge branch 'lstm_pipeline' of hf.co:spaces/smartbuildings/smart-buildings into lstm_pipeline

Browse files
src/main.py CHANGED
@@ -17,6 +17,10 @@ def main():
17
  "src/rtu/models/kmeans_rtu_1.pkl",
18
  "src/rtu/models/kmeans_rtu_2.pkl",
19
  ],
 
 
 
 
20
  num_inputs=rtu_data_pipeline.num_inputs,
21
  num_outputs=rtu_data_pipeline.num_outputs,
22
  )
@@ -27,6 +31,10 @@ def main():
27
  "src/rtu/models/kmeans_rtu_3.pkl",
28
  "src/rtu/models/kmeans_rtu_4.pkl",
29
  ],
 
 
 
 
30
  num_inputs=rtu_data_pipeline.num_inputs,
31
  num_outputs=rtu_data_pipeline.num_outputs,
32
  )
 
17
  "src/rtu/models/kmeans_rtu_1.pkl",
18
  "src/rtu/models/kmeans_rtu_2.pkl",
19
  ],
20
+ pca_model_paths=[
21
+ "src/rtu/models/pca_rtu_1.pkl",
22
+ "src/rtu/models/pca_rtu_2.pkl",
23
+ ],
24
  num_inputs=rtu_data_pipeline.num_inputs,
25
  num_outputs=rtu_data_pipeline.num_outputs,
26
  )
 
31
  "src/rtu/models/kmeans_rtu_3.pkl",
32
  "src/rtu/models/kmeans_rtu_4.pkl",
33
  ],
34
+ pca_model_paths=[
35
+ "src/rtu/models/pca_rtu_3.pkl",
36
+ "src/rtu/models/pca_rtu_4.pkl",
37
+ ],
38
  num_inputs=rtu_data_pipeline.num_inputs,
39
  num_outputs=rtu_data_pipeline.num_outputs,
40
  )
src/rtu/RTUAnomalizer1.py CHANGED
@@ -10,11 +10,13 @@ class RTUAnomalizer1:
10
 
11
  model = None
12
  kmeans_models = []
 
13
 
14
  def __init__(
15
  self,
16
  prediction_model_path=None,
17
  clustering_model_paths=None,
 
18
  num_inputs=None,
19
  num_outputs=None,
20
  ):
@@ -29,8 +31,9 @@ class RTUAnomalizer1:
29
  """
30
  self.num_inputs = num_inputs
31
  self.num_outputs = num_outputs
32
- if prediction_model_path is not None and clustering_model_paths is not None:
33
- self.load_models(prediction_model_path, clustering_model_paths)
 
34
  self.actual_list, self.pred_list, self.resid_list = self.initialize_lists()
35
 
36
  def initialize_lists(self, size=30):
@@ -46,7 +49,7 @@ class RTUAnomalizer1:
46
  initial_values = [[0]*self.num_outputs] * size
47
  return initial_values.copy(), initial_values.copy(), initial_values.copy()
48
 
49
- def load_models(self, prediction_model_path, clustering_model_paths):
50
  """
51
  Load the prediction and clustering models.
52
 
@@ -58,6 +61,9 @@ class RTUAnomalizer1:
58
 
59
  for path in clustering_model_paths:
60
  self.kmeans_models.append(joblib.load(path))
 
 
 
61
 
62
  def predict(self, df_new):
63
  """
@@ -158,7 +164,7 @@ class RTUAnomalizer1:
158
  for i, model in enumerate(self.kmeans_models):
159
  dist.append(
160
  np.linalg.norm(
161
- resid[:, (i * 7) + 1 : (i * 7) + 8] - model.cluster_centers_[0],
162
  ord=2,
163
  axis=1,
164
  )
 
10
 
11
  model = None
12
  kmeans_models = []
13
+ pca_models = []
14
 
15
  def __init__(
16
  self,
17
  prediction_model_path=None,
18
  clustering_model_paths=None,
19
+ pca_model_paths=None,
20
  num_inputs=None,
21
  num_outputs=None,
22
  ):
 
31
  """
32
  self.num_inputs = num_inputs
33
  self.num_outputs = num_outputs
34
+ if prediction_model_path is not None and clustering_model_paths is not None and pca_model_paths is not None:
35
+ self.load_models(prediction_model_path, clustering_model_paths, pca_model_paths)
36
+
37
  self.actual_list, self.pred_list, self.resid_list = self.initialize_lists()
38
 
39
  def initialize_lists(self, size=30):
 
49
  initial_values = [[0]*self.num_outputs] * size
50
  return initial_values.copy(), initial_values.copy(), initial_values.copy()
51
 
52
+ def load_models(self, prediction_model_path, clustering_model_paths, pca_model_paths):
53
  """
54
  Load the prediction and clustering models.
55
 
 
61
 
62
  for path in clustering_model_paths:
63
  self.kmeans_models.append(joblib.load(path))
64
+
65
+ for path in pca_model_paths:
66
+ self.pca_models.append(joblib.load(path))
67
 
68
  def predict(self, df_new):
69
  """
 
164
  for i, model in enumerate(self.kmeans_models):
165
  dist.append(
166
  np.linalg.norm(
167
+ self.pca_models[i].transform(resid[:, (i * 7) + 1 : (i * 7) + 8]) - model.cluster_centers_[0],
168
  ord=2,
169
  axis=1,
170
  )
src/rtu/RTUAnomalizer2.py CHANGED
@@ -10,11 +10,13 @@ class RTUAnomalizer2:
10
 
11
  model = None
12
  kmeans_models = []
 
13
 
14
  def __init__(
15
  self,
16
  prediction_model_path=None,
17
  clustering_model_paths=None,
 
18
  num_inputs=None,
19
  num_outputs=None,
20
  ):
@@ -29,8 +31,9 @@ class RTUAnomalizer2:
29
  """
30
  self.num_inputs = num_inputs
31
  self.num_outputs = num_outputs
32
- if prediction_model_path is not None and clustering_model_paths is not None:
33
- self.load_models(prediction_model_path, clustering_model_paths)
 
34
  self.actual_list, self.pred_list, self.resid_list = self.initialize_lists()
35
 
36
  def initialize_lists(self, size=30):
@@ -46,7 +49,7 @@ class RTUAnomalizer2:
46
  initial_values = [[0]*self.num_outputs] * size
47
  return initial_values.copy(), initial_values.copy(), initial_values.copy()
48
 
49
- def load_models(self, prediction_model_path, clustering_model_paths):
50
  """
51
  Load the prediction and clustering models.
52
 
@@ -58,6 +61,9 @@ class RTUAnomalizer2:
58
 
59
  for path in clustering_model_paths:
60
  self.kmeans_models.append(joblib.load(path))
 
 
 
61
 
62
  def predict(self, df_new):
63
  """
@@ -158,7 +164,7 @@ class RTUAnomalizer2:
158
  for i, model in enumerate(self.kmeans_models):
159
  dist.append(
160
  np.linalg.norm(
161
- resid[:, (i * 7) + 1 : (i * 7) + 8] - model.cluster_centers_[0],
162
  ord=2,
163
  axis=1,
164
  )
 
10
 
11
  model = None
12
  kmeans_models = []
13
+ pca_models = []
14
 
15
  def __init__(
16
  self,
17
  prediction_model_path=None,
18
  clustering_model_paths=None,
19
+ pca_model_paths=None,
20
  num_inputs=None,
21
  num_outputs=None,
22
  ):
 
31
  """
32
  self.num_inputs = num_inputs
33
  self.num_outputs = num_outputs
34
+ if prediction_model_path is not None and clustering_model_paths is not None and pca_model_paths is not None:
35
+ self.load_models(prediction_model_path, clustering_model_paths, pca_model_paths)
36
+
37
  self.actual_list, self.pred_list, self.resid_list = self.initialize_lists()
38
 
39
  def initialize_lists(self, size=30):
 
49
  initial_values = [[0]*self.num_outputs] * size
50
  return initial_values.copy(), initial_values.copy(), initial_values.copy()
51
 
52
+ def load_models(self, prediction_model_path, clustering_model_paths, pca_model_paths):
53
  """
54
  Load the prediction and clustering models.
55
 
 
61
 
62
  for path in clustering_model_paths:
63
  self.kmeans_models.append(joblib.load(path))
64
+
65
+ for path in pca_model_paths:
66
+ self.pca_models.append(joblib.load(path))
67
 
68
  def predict(self, df_new):
69
  """
 
164
  for i, model in enumerate(self.kmeans_models):
165
  dist.append(
166
  np.linalg.norm(
167
+ self.pca_models[i].transform(resid[:, (i * 7) + 1 : (i * 7) + 8]) - model.cluster_centers_[0],
168
  ord=2,
169
  axis=1,
170
  )
src/rtu/models/kmeans_rtu_1.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:42621b20e5f4048526e82615e92de0031ba42c540fbaba637efe0b4506f13ff4
3
- size 2065925
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb67ee66d9eff490b1ab8668a29c2ac428f1f2ac0e4adab479a50dfb4109d914
3
+ size 2065909
src/rtu/models/kmeans_rtu_2.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e1c07513633ff899c5b1fa46bdf750420ee95593282f79bc4564db06c2dfb601
3
- size 2065925
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ff364f579e10cc8ec951cfae8ef4f0c658e5e5a39a94ffdaf0984aad526726b
3
+ size 2065909
src/rtu/models/kmeans_rtu_3.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:31d6d81362dde61976f0617e51239a67c6962c1ea84f6c301970bafdb8406146
3
- size 2065881
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:985814b63e8649991cbf7c68f659ea3d34ba1d452e8f8b53ab04e2257547d83f
3
+ size 2065865
src/rtu/models/kmeans_rtu_4.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:72a5a1799b4546825815d9833598bcce7fb3241f9c15a3c03c3d0c28e5010b33
3
- size 2065881
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5390875e07cc929502f0eec1fe7e1751479ecfa928a8196176996141dbf86dc5
3
+ size 2065865
src/rtu/models/lstm.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
src/rtu/models/pca_rtu_1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ec1b50bc380f48a59de90ae3a8a45923816e24848dceeb353299c0407e2e34c
3
+ size 1083
src/rtu/models/pca_rtu_2.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f0e68e14251682befa07845b614e545a97074ac5390b8bc6cfa85540211175e
3
+ size 1083
src/rtu/models/pca_rtu_3.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4599b4e582432c9de20e501d5d28c582d9df8dd71a3006f975469fb819e9a0e
3
+ size 1083
src/rtu/models/pca_rtu_4.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:efeca9febf06e512ab41e93ded97b978569cf5f531094cd777e82289ecf9856f
3
+ size 1083