-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
64 lines (49 loc) · 1.89 KB
/
validate.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
import json
import sys
import joblib
from sklearn.metrics import classification_report
from utils import (
HEICLOUD_DATA,
TIME_INTERVAL_CONFIG,
TS_TYPE,
fdr,
fpr,
fttar,
load_dataset,
)
def validate(name):
for ts in TS_TYPE:
for ti in TIME_INTERVAL_CONFIG:
clf = joblib.load(
f"/mnt/data/models/model_{name}_{ti['time_interval_name']}_{ts}.pickle"
)
for i in range(len(HEICLOUD_DATA)):
result = dict()
result["time_interval"] = ti["time_interval_name"]
result["ts_type"] = ts
result["model"] = name
result["day"] = HEICLOUD_DATA[i]
print("Predicting production set...")
result["prod"] = {}
X_new, y_new, _, _ = load_dataset(
ti["time_interval_name"], ts_type=ts, data=[HEICLOUD_DATA[i]],
)
print(f"Data has shape: {X_new.shape}")
y_pred = clf.predict(X_new)
report = classification_report(y_new, y_pred, output_dict=True)
fttar_test = fttar(y_new, y_pred)
fpr_test = fpr(y_new, y_pred)
fdr_test = fdr(y_new, y_pred)
result["prod"]["report"] = report
result["prod"]["fttar"] = fttar_test
result["prod"]["fpr"] = fpr_test
result["prod"]["fdr"] = fdr_test
print(report)
print(f"FTTAR: {fttar_test}")
print(f"False Positive Rate: {fpr_test}")
print(f"False Discovery Rate: {fdr_test}")
with open(f"result_{ti['time_interval_name']}.json", "a+") as f:
f.write(json.dumps(result) + "\n")
if __name__ == "__main__":
name = sys.argv[1]
validate(name)