-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.py
28 lines (23 loc) · 999 Bytes
/
utils.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
import seaborn as sns
import matplotlib.pyplot as plt
def plot_predictions(preds, threshold, bins = 80):
sns.displot(preds, bins = bins, kde = True, height = 8, aspect = 2)
plt.axvline(x = threshold, color = 'r', linestyle = '--', label = 'Chosen Threshold')
plt.title('Loss Distribution')
plt.legend()
def loss_plot(preds, threshold):
preds.plot(figsize = (15,8), title = 'Chosen Threshold', label = 'Loss')
plt.axhline(y = threshold, color = 'r', linestyle = '--', label = 'Chosen Threshold')
plt.legend()
plt.show();
def ts_plot(df, preds, threshold, alg = 'DeepAnT', range = None):
idx = preds.loc[lambda x: x > threshold].index
plt.figure(figsize = (20,8))
if range is not None:
min, max = range
df = df[min:max]
plt.plot(df, label = '_nolegend_')
plt.scatter(idx, df.loc[idx], color = 'red', label = 'Detected Anomalies by DeepAnt')
plt.title('Detected Anomalies in Time Series')
plt.legend()
plt.show();