jerin commited on
Commit
cd9d584
1 Parent(s): 3b66598

new pipeline lstm

Browse files
.gitignore CHANGED
@@ -4,4 +4,5 @@ venv
4
  __pycache__/
5
  *.tf
6
  data
7
- *.keras
 
 
4
  __pycache__/
5
  *.tf
6
  data
7
+ *.keras
8
+ *.csv
MA_temp_model.h5 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ed0c2c96cde21763e2a60597ab8abf0a50bd75ab954525845702014d219027c4
3
- size 533080
 
 
 
 
buildingdata.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:62e6cb23b7dfca34ca511b0ff99c68009f860968cd0c5688ac97ffa50a6aea8b
3
- size 24061812
 
 
 
 
energy_model.h5 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad1ad8b65c5030e0dc971b3c488335f2f1d93b0b8acc2bfb6af10145237cda87
3
- size 780616
 
 
 
 
energy_model_01.h5 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:58e7e4823df5c20cd2fb4df23d2399d8b0fcf710147f3e52c9c1f3fcbeaa7cc1
3
- size 535480
 
 
 
 
kmeans_model.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:5bddef9e8a8d413136daf6f99dd236fb6c97700d2fa85567de17aacb4a32bce1
3
- size 1927225
 
 
 
 
kmeans_model1.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:aaa404e937bf8fe9d52b38aa1e11f87d544530a2d4789b46d20b5a1665e15846
3
- size 2064297
 
 
 
 
kmeans_model2.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9cf710504c910255e59d0609617fecf74ee8ad6710f4ba4109d9de5aae0cd879
3
- size 2064297
 
 
 
 
kmeans_model3.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:1fb375913725bf309d514f55b71799daead266db7caad09f02ab9cfdd56bdc0a
3
- size 2064297
 
 
 
 
kmeans_model4.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:cfbe4b1a5c1aa4b00e8e932c77dd8ed5ce99fbe5efd4960079d14e380206f9f2
3
- size 2064297
 
 
 
 
pca_model.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:225896826ab8bfb9ea32f0f3057c1292ca5bc238d2ea87858c25fa8da5960b46
3
- size 1179
 
 
 
 
pipeline.ipynb CHANGED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import numpy as np\n",
10
+ "\n",
11
+ "def initialize_lists(size=30):\n",
12
+ " initial_values = [0] * size\n",
13
+ " return initial_values.copy(), initial_values.copy(), initial_values.copy()\n",
14
+ "\n",
15
+ "def get_window(df, len_df):\n",
16
+ " if len_df > 30:\n",
17
+ " return df[len_df-31:len_df].astype('float32')\n",
18
+ " else:\n",
19
+ " return None\n",
20
+ "\n",
21
+ "def transform_window(df_window, scaler):\n",
22
+ " return scaler.transform(df_window)\n",
23
+ "\n",
24
+ "def prepare_input(df_trans):\n",
25
+ " return df_trans[:30,:].reshape((1,30,30))\n",
26
+ "\n",
27
+ "def predict(model, df_new):\n",
28
+ " return model.predict(df_new)\n",
29
+ "\n",
30
+ "def calculate_residuals(df_trans, pred):\n",
31
+ " actual = df_trans[30,:25]\n",
32
+ " resid = actual - pred\n",
33
+ " return actual, resid\n",
34
+ "\n",
35
+ "def resize_prediction(pred, df_trans):\n",
36
+ " pred.resize((pred.shape[0], pred.shape[1] + len(df_trans[30,25:])))\n",
37
+ " pred[:, -len(df_trans[30,25:]):] = df_trans[30,25:]\n",
38
+ " return pred\n",
39
+ "\n",
40
+ "def inverse_transform(scaler, pred, df_trans):\n",
41
+ " pred = scaler.inverse_transform(np.array(pred))\n",
42
+ " actual = scaler.inverse_transform(np.array([df_trans[30,:]]))\n",
43
+ " return actual, pred\n",
44
+ "\n",
45
+ "def update_lists(actual_list, pred_list, resid_list, actual, pred, resid):\n",
46
+ " actual_list.pop(0)\n",
47
+ " pred_list.pop(0)\n",
48
+ " resid_list.pop(0)\n",
49
+ " actual_list.append(actual[0,1])\n",
50
+ " pred_list.append(pred[0,1])\n",
51
+ " resid_list.append(resid[0,1])\n",
52
+ " return actual_list, pred_list, resid_list\n",
53
+ "\n",
54
+ "def calculate_distances(resid, kmeans1, kmeans2, kmeans3, kmeans4):\n",
55
+ " dist = []\n",
56
+ " dist.append(np.linalg.norm(resid[:,1:8]-kmeans1.cluster_centers_[0], ord=2, axis=1))\n",
57
+ " dist.append(np.linalg.norm(resid[:,8:15]-kmeans2.cluster_centers_[0], ord=2, axis=1))\n",
58
+ " dist.append(np.linalg.norm(resid[:,15:22]-kmeans3.cluster_centers_[0], ord=2, axis=1))\n",
59
+ " dist.append(np.linalg.norm(resid[:,22:29]-kmeans4.cluster_centers_[0], ord=2, axis=1))\n",
60
+ " return np.array(dist)\n",
61
+ "\n",
62
+ "def pipeline(df, scaler, model, kmeans1, kmeans2, kmeans3, kmeans4):\n",
63
+ " actual_list, pred_list, resid_list = initialize_lists()\n",
64
+ " len_df = np.len(df)\n",
65
+ " df_window = get_window(df, len_df)\n",
66
+ " if df_window is not None:\n",
67
+ " df_trans = transform_window(df_window, scaler)\n",
68
+ " df_new = prepare_input(df_trans)\n",
69
+ " pred = predict(model, df_new)\n",
70
+ " actual, resid = calculate_residuals(df_trans, pred)\n",
71
+ " pred = resize_prediction(pred, df_trans)\n",
72
+ " actual, pred = inverse_transform(scaler, pred, df_trans)\n",
73
+ " actual_list, pred_list, resid_list = update_lists(actual_list, pred_list, resid_list, actual, pred, resid)\n",
74
+ " dist = calculate_distances(resid, kmeans1, kmeans2, kmeans3, kmeans4)\n",
75
+ " return actual_list, pred_list, resid_list, dist\n",
76
+ " else:\n",
77
+ " return actual_list, pred_list, resid_list, None\n"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": 1,
83
+ "metadata": {},
84
+ "outputs": [
85
+ {
86
+ "data": {
87
+ "text/plain": [
88
+ "['a', 'b', 'c', 'd']"
89
+ ]
90
+ },
91
+ "execution_count": 1,
92
+ "metadata": {},
93
+ "output_type": "execute_result"
94
+ }
95
+ ],
96
+ "source": [
97
+ "inp = ['a', 'b']\n",
98
+ "out = ['c','d']\n",
99
+ "\n",
100
+ "inp+out"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": null,
106
+ "metadata": {},
107
+ "outputs": [],
108
+ "source": []
109
+ }
110
+ ],
111
+ "metadata": {
112
+ "kernelspec": {
113
+ "display_name": "smartbuilding",
114
+ "language": "python",
115
+ "name": "python3"
116
+ },
117
+ "language_info": {
118
+ "codemirror_mode": {
119
+ "name": "ipython",
120
+ "version": 3
121
+ },
122
+ "file_extension": ".py",
123
+ "mimetype": "text/x-python",
124
+ "name": "python",
125
+ "nbconvert_exporter": "python",
126
+ "pygments_lexer": "ipython3",
127
+ "version": "3.11.8"
128
+ }
129
+ },
130
+ "nbformat": 4,
131
+ "nbformat_minor": 2
132
+ }
sample_data.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:aa13789e2460e1b575a63d32ca46615d5df237c62de5da2f4da22c1e8edc945c
3
- size 144290729
 
 
 
 
sample_data_01.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:8a00542784412e885f2ef707e3dd86b58023e678b35221fefbce5af9ec6cb10d
3
- size 59769388
 
 
 
 
sample_data_02.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:3fe51d16cfeffdc7df991e0f27da089da5e9f1260e2ab9c316cd6786999d8d29
3
- size 119517162
 
 
 
 
sample_data_smooth_01.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:efbfdef5e85cb88d20e7e50ac2351f60d20f07a31b2a40cf4c925596097c5cc4
3
- size 299846687
 
 
 
 
scaler.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:63d98018c0b4da0c42820e9017c91944d1486e85471cd44a9a6ab121e7d2c64a
3
- size 1101
 
 
 
 
scaler_1.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:778df19577ac7a34c16dfda1b32f26800c62ff687130e22e58715b8d495dcb37
3
- size 1437