-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_kstream_data.py
65 lines (54 loc) · 1.66 KB
/
evaluate_kstream_data.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
import pandas as pd
from sklearn import datasets, linear_model
from sklearn.model_selection import train_test_split
from sklearn import svm
from matplotlib import pyplot as plt
import numpy
#One-time use code for training a SVC classifier on the Knowledge Stream test data
#Outputs accuracy, precision, recall and F-measure
#File can be replaced with 'scores_file_avg.csv' to get results for the average function
df = pd.read_csv('scores_file_max.csv', names=['score','class'])
clf = svm.SVC()
train, test = train_test_split(df, test_size=0.2)
clf.fit(train[['score']], train[['class']])
result = numpy.zeros([149, 2])
count = 0
for item in test['class']:
result[count][0] = item
count += 1
count = 0
for item in test['score']:
result[count][1] = clf.predict(item)
count += 1
true_positive = 0
true_negative = 0
false_positive = 0
false_negative = 0
for row in result:
if row[1] == 0 and row[0] == 0:
true_negative += 1
if row[1] == 1 and row[0] == 1:
true_positive += 1
if row[1] == 1 and row[0] == 0:
false_positive += 1
if row[1] == 0 and row[0] == 1:
false_negative += 1
print(df.shape)
n = 0
p = 0
for row in result:
if row[0] == 0:
n += 1
else:
p += 1
print("Positive/negative split of test set: %s/%s" % (p,n))
precision = true_positive/(true_positive+false_positive)
recall = true_positive/(true_positive+false_negative)
accuracy = (true_positive+true_negative)/(true_positive+true_negative+false_positive+false_negative)
f1_score = (2*precision*recall)/(precision+recall)
print("\n\nResults:\n\n")
print("Accuracy: "+str(accuracy))
print("\nPrecision: "+str(precision))
print("\nRecall: "+str(recall))
print("\nF-measure: "+str(f1_score))
print(test.shape)