-
Notifications
You must be signed in to change notification settings - Fork 1
/
other.py
134 lines (108 loc) · 3.76 KB
/
other.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from collections import deque
import statistics
import sys
import seaborn as sns
import pandas as pd
from sklearn.svm import SVC
from sklearn import decomposition
def space_gg(x, a_list, b_list):
title = 'Memory cost for building the model'
fig, ax = plt.subplots()
plt.xlabel('Record time length (second)')
plt.ylabel('Space needed (MegaBytes)')
ax.plot(x, a_list, label='storage_memory')
ax.plot(x, b_list, label='running_memory')
ax.legend()
ax.set_title(title)
plt.savefig(title + 'line_chart.png')
# plt.show()
def time_gg(x, time_list):
title = 'Time cost for building the model'
fig, ax = plt.subplots()
plt.xlabel('Record time length (second)')
plt.ylabel('Time needed (second)')
ax.plot(x, time_list, label='time')
ax.legend()
ax.set_title(title)
plt.savefig(title + 'line_chart.png')
# plt.show()
def main():
fp = open('exp.txt', 'r')
x = []
y = []
z1 = []
z2 = []
for line in fp:
items = line.strip().split(' ')
if len(items) < 4:
continue
print(items)
x.append(int(items[0]))
y.append(float(items[1]))
z1.append(float(items[2]))
z2.append(float(items[3]))
time_gg(x, y)
space_gg(x, z1, z2)
def main2():
inn = pd.read_csv('result - Copy4.csv')
print(inn)
f, ax = plt.subplots(1, 1)
ax.plot(inn.K, inn['60s'], color="blue", label="1min")
ax.plot(inn.K, inn['120s'], color="red", label="2min")
ax.plot(inn.K, inn['180s'], color="green", label="3min")
ax.plot(inn.K, inn['240s'], color="orange", label="4min")
ax.legend()
plt.xlabel('K')
plt.ylabel('detected time stamp (20/s)')
ax.set_title('The time when anomaly is detected')
plt.show()
def main3():
dfl = []
for t in range(1, 4+1):
dfl.append(pd.read_csv('motor_BODY' + str(t) + '_res.csv'))
df = dfl[0].append(dfl[1]).append(dfl[2]).append(dfl[3]).reset_index()
df = df.drop(['index'], axis=1)
df.to_csv('sss.csv', index=False)
g = sns.factorplot(x="K", y="false_positive_ratio", hue="recorded_time", col="delta_t", col_wrap=3, data=df)
g.fig.subplots_adjust(top=0.9)
g.fig.suptitle('K v.s. false_positive_ratio for choice of delta_t (BODY)', fontsize=16)
plt.savefig('BODY_delta_t.png')
# plt.show()
print(df)
def main4():
dfl = []
for t in range(1, 4+1):
dfl.append(pd.read_csv('TOP' + str(t) + '.csv'))
df = dfl[0].append(dfl[1]).append(dfl[2]).append(dfl[3]).reset_index()
df = df.drop(['index'], axis=1)
g = sns.FacetGrid(df, hue="recorded_time", size=5)
g = g.map(sns.distplot, "gap_value")
plt.ylabel('percentage (%)')
plt.title('gaps distribution depends on recorded time (TOP)')
plt.legend()
plt.savefig('tm.png')
plt.show()
def main5():
# dfl = []
# for t in range(1, 4 + 1):
# dfl.append(pd.read_csv('motor_HOOK' + str(t) + '_res.csv'))
# df = dfl[0].append(dfl[1]).append(dfl[2]).append(dfl[3]).reset_index()
# df = df.drop(['index'], axis=1)
# df.to_csv('sss.csv', index=False)
for pos in ['HOOK', 'TOP', 'BODY']:
for t in [1, 2, 3, 4]:
df = pd.read_csv('motor_' + pos + str(t) + '_res.csv')
mat = df.pivot("K", "delta_t", "false_positive_ratio")
ax = plt.axes()
g = sns.heatmap(mat, ax=ax, vmin=0, vmax=35)
sns.plt.suptitle('The false positive ratio depends on \"K\" and \"delta_t\" (' + pos + ' ' + str(t) + 'min)',
fontsize=14)
plt.savefig(pos + '_' + str(t) + 'min_heatmap.png')
plt.clf()
# plt.show()
# print(df)
if __name__ == '__main__':
main4()