-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluation.py
76 lines (68 loc) · 2.65 KB
/
Evaluation.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
66
67
68
69
70
71
72
73
74
75
76
import pandas as pd
labels_actual = []
labels_predicted = []
with open('tweets_actual_labels.txt', encoding='utf-8') as actual_file:
labels_a = actual_file.readlines()
for label in labels_a:
labels_actual.append(label.replace('\n', ''))
actual_file.close()
with open('tweets_predicted_labels.txt', encoding='utf-8') as predicted_file:
labels_p = predicted_file.readlines()
for label in labels_p:
labels_predicted.append(label.replace('\n', ''))
predicted_file.close()
list_true = []
list_false = []
net = 'netral'
neg = 'negatif'
pos = 'positif'
netpos = 'netpos'
netneg = 'netneg'
negnet = 'negnet'
negpos = 'negpos'
posnet = 'posnet'
posneg = 'posneg'
# netpos = predicted netral, but actually positif
# netneg = predicted netral, but actually negatif
# negnet = predicted negatif, but actually netral
# negpos = predicted negatif, but actually positif
# posnet = predicted positif, but actually netral
# posneg = predicted positif, but actually negatif
for i in range(len(labels_actual)):
index = i - 1
actual = labels_actual[index]
predicted = labels_predicted[index]
number = index + 1
if predicted not in actual:
list_false.append(predicted[:3] + actual[:3])
print('%s Predicted %s, but actually is %s' % (number, predicted, actual))
else:
list_true.append(predicted)
total_net = list_true.count(net)
total_neg = list_true.count(neg)
total_pos = list_true.count(pos)
total_true = len(list_true)
total_netneg = list_false.count(netneg)
total_netpos = list_false.count(netpos)
total_negnet = list_false.count(negnet)
total_negpos = list_false.count(negpos)
total_posnet = list_false.count(posnet)
total_posneg = list_false.count(posneg)
total_false_net = total_netneg + total_netpos
total_false_neg = total_negnet + total_negpos
total_false_pos = total_posnet + total_posneg
total_false = len(list_false)
accuracy = total_true / (total_true + total_false)
df_confusion_matrix = pd.DataFrame({pos: [total_pos, total_netpos, total_negpos, ''],
net: [total_posnet, total_net, total_negnet, ''],
neg: [total_posneg, total_netneg, total_neg, ''],
'< actual': ['', '', '', '']},
[pos, net, neg, '^ predicted'])
df_accuracy = pd.DataFrame({'true': total_true,
'false': total_false,
'accuracy': accuracy},
['total'])
print('\nTable Confusion Matrix')
print(df_confusion_matrix, '\n')
print('Table Accuracy')
print(df_accuracy)