-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.py
More file actions
43 lines (38 loc) · 1.3 KB
/
test.py
File metadata and controls
43 lines (38 loc) · 1.3 KB
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
from sklearn.externals import joblib
from sklearn.metrics import recall_score, precision_score, confusion_matrix
import build_dataset
def metrics(y, y_pred):
tp = 0
tn = 0
fp = 0
fn = 0
for index, element_y in enumerate(y):
if element_y == 1:
if y_pred[index] == -1:
fn+= 1
else:
tp+= 1
else:
if y_pred[index] == -1:
tn+= 1
else:
fp+= 1
return tp, tn, fp, fn
print("Data set is building...")
X_train, y_train = build_dataset.run("Data/processed-training-data/", "Data/training-class")
X_test, y_test = build_dataset.run("Data/processed-test-data/", "Data/test-class")
loaded_model = joblib.load('Models/svm.pkl')
y_test_pred = loaded_model.predict(X_test[0:])
y_train_pred = loaded_model.predict(X_train[0:])
print("---- Train Results ----")
tp, tn, fp, fn = metrics(y_train, y_train_pred)
print ("True Positive = " + str(tp))
print ("False Positive = " + str(fp))
print ("True Negative = " + str(tn))
print ("False Negative = " + str(fn))
print("---- Test Results ----")
tp, tn, fp, fn = metrics(y_test, y_test_pred)
print ("True Positive = " + str(tp))
print ("False Positive = " + str(fp))
print ("True Negative = " + str(tn))
print ("False Negative = " + str(fn))