Spaces:
Sleeping
Sleeping
jerin commited on
Commit ·
e0c688d
1
Parent(s): 985bb5d
add pca
Browse files- src/main.py +8 -0
- src/rtu/RTUAnomalizer1.py +10 -4
- src/rtu/RTUAnomalizer2.py +10 -4
- src/rtu/models/kmeans_rtu_1.pkl +2 -2
- src/rtu/models/kmeans_rtu_2.pkl +2 -2
- src/rtu/models/kmeans_rtu_3.pkl +2 -2
- src/rtu/models/kmeans_rtu_4.pkl +2 -2
- src/rtu/models/lstm.ipynb +0 -0
- src/rtu/models/pca_rtu_1.pkl +3 -0
- src/rtu/models/pca_rtu_2.pkl +3 -0
- src/rtu/models/pca_rtu_3.pkl +3 -0
- src/rtu/models/pca_rtu_4.pkl +3 -0
src/main.py
CHANGED
|
@@ -16,6 +16,10 @@ def main():
|
|
| 16 |
"src/rtu/models/kmeans_rtu_1.pkl",
|
| 17 |
"src/rtu/models/kmeans_rtu_2.pkl",
|
| 18 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
num_inputs=rtu_data_pipeline.num_inputs,
|
| 20 |
num_outputs=rtu_data_pipeline.num_outputs,
|
| 21 |
)
|
|
@@ -26,6 +30,10 @@ def main():
|
|
| 26 |
"src/rtu/models/kmeans_rtu_3.pkl",
|
| 27 |
"src/rtu/models/kmeans_rtu_4.pkl",
|
| 28 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
num_inputs=rtu_data_pipeline.num_inputs,
|
| 30 |
num_outputs=rtu_data_pipeline.num_outputs,
|
| 31 |
)
|
|
|
|
| 16 |
"src/rtu/models/kmeans_rtu_1.pkl",
|
| 17 |
"src/rtu/models/kmeans_rtu_2.pkl",
|
| 18 |
],
|
| 19 |
+
pca_model_paths=[
|
| 20 |
+
"src/rtu/models/pca_rtu_1.pkl",
|
| 21 |
+
"src/rtu/models/pca_rtu_2.pkl",
|
| 22 |
+
],
|
| 23 |
num_inputs=rtu_data_pipeline.num_inputs,
|
| 24 |
num_outputs=rtu_data_pipeline.num_outputs,
|
| 25 |
)
|
|
|
|
| 30 |
"src/rtu/models/kmeans_rtu_3.pkl",
|
| 31 |
"src/rtu/models/kmeans_rtu_4.pkl",
|
| 32 |
],
|
| 33 |
+
pca_model_paths=[
|
| 34 |
+
"src/rtu/models/pca_rtu_3.pkl",
|
| 35 |
+
"src/rtu/models/pca_rtu_4.pkl",
|
| 36 |
+
],
|
| 37 |
num_inputs=rtu_data_pipeline.num_inputs,
|
| 38 |
num_outputs=rtu_data_pipeline.num_outputs,
|
| 39 |
)
|
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:
|
| 3 |
-
size
|
|
|
|
| 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:
|
| 3 |
-
size
|
|
|
|
| 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:
|
| 3 |
-
size
|
|
|
|
| 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:
|
| 3 |
-
size
|
|
|
|
| 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
|