forked from ClustProject/KUDataOutlier
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
26 lines (19 loc) · 798 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
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
# Standard scaling (mean=0, variance=1)
def normalization(X_train, X_test):
scaler = StandardScaler()
scaler = scaler.fit(X_train)
X_train_scaled = pd.DataFrame(scaler.transform(X_train), columns=X_train.columns, index=X_train.index)
X_test_scaled = pd.DataFrame(scaler.transform(X_test), columns=X_test.columns, index=X_test.index)
return X_train_scaled, X_test_scaled
# anomaly score plot
def draw_plot(scores, save_path):
plt.figure(figsize=(12, 5))
plt.scatter(scores.index, scores['score'], c='blue', s=3)
plt.xlabel('Date')
plt.ylabel('Anomaly Score')
plt.xlim(scores.index[0], scores.index[-1])
plt.savefig(save_path)
plt.close()