-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscore2.py
More file actions
62 lines (46 loc) · 1.37 KB
/
score2.py
File metadata and controls
62 lines (46 loc) · 1.37 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os,sys
if len(sys.argv)<3:
print("usage: python score.py <prediction-file> <test-file>")
sys.exit(2)
predictionFile = open(sys.argv[1],'r')
testDataFile = open(sys.argv[2],'r')
predictions = predictionFile.readlines()
testData = testDataFile.readlines()
predictionFile.close()
testDataFile.close()
folders = os.listdir("test")
correct = [[0 for i in range(25)] for j in range(25)]
output = open("output",'w')
for i in range(len(predictions)):
guess = int(predictions[i].split()[0]) -1
answer = int(testData[i].split()[0]) -1
correct[answer][guess] = int(correct[answer][guess]) + 1
for col in range(len(sorted(folders))):
output.write("\t")
output.write(sorted(folders)[col][0:2])
print "\t",
print sorted(folders)[col][0:2],
output.write("\n")
print
rowCount = 0
for row in correct:
output.write(sorted(folders)[rowCount][0:2])
output.write("\t")
print sorted(folders)[rowCount][0:2],
print "\t",
rowCount = rowCount+1
for col in row:
output.write(str(col))
output.write("\t")
print str(col),
print "\t",
output.write("\n")
print
correctGuess = 0
for i in range(25):
correctGuess = correctGuess + correct[i][i]
print "Accuracy = ",
print (correctGuess*100.0)/len(testData)
output.write("Accuracy = ")
output.write(str((correctGuess*100.0)/len(testData)))
output.close()