webmining u4 update
This commit is contained in:
parent
b62232dacd
commit
7c7759b248
@ -16,14 +16,22 @@ document_count = 0
|
||||
precision = [0,0,0,0,0,0,0,0,0,0,0]
|
||||
precision_avg = 0
|
||||
|
||||
def load_predictionfile():
|
||||
def load_predictionfile(file):
|
||||
global document_count
|
||||
for line in open(predfile,'r'):
|
||||
for line in open(file,'r'):
|
||||
document_count += 1
|
||||
str = line.split("\t")
|
||||
preds.append([str[0],str[1].split("\n")[0]])
|
||||
|
||||
def confusion_matrix():
|
||||
'''
|
||||
c1 c2 ... c11
|
||||
c1
|
||||
c2
|
||||
c3
|
||||
...
|
||||
c11
|
||||
'''
|
||||
for pred in preds:
|
||||
for c in classes:
|
||||
if os.path.isfile(trainDir +"/"+ c[0]+"/"+ pred[0]):
|
||||
@ -32,6 +40,7 @@ def confusion_matrix():
|
||||
conf_matr[p[1]][c[1]] += 1
|
||||
|
||||
def accuracy():
|
||||
#alle werte auf der diagonale addiert / n (anzahl der dokumente)
|
||||
global accuracy
|
||||
global document_count
|
||||
i = 0
|
||||
@ -69,15 +78,38 @@ def avg_prec():
|
||||
for p in precision:
|
||||
precision_avg += p
|
||||
precision_avg = float(precision_avg) / 11
|
||||
|
||||
|
||||
|
||||
def pp_confusionmatrix():
|
||||
print "\tc1\tc2\tc3\tc4\tc5\tc6\tc7\tc8\tc9\tc10\tc11"
|
||||
lines = ["c1\t","c2\t","c3\t","c4\t","c5\t","c6\t","c7\t","c8\t","c9\t","c10\t","c11\t"]
|
||||
for column in conf_matr:
|
||||
lines[0] += str(column[0]) + "\t"
|
||||
lines[1] += str(column[1]) + "\t"
|
||||
lines[2] += str(column[2]) + "\t"
|
||||
lines[3] += str(column[3]) + "\t"
|
||||
lines[4] += str(column[4]) + "\t"
|
||||
lines[5] += str(column[5]) + "\t"
|
||||
lines[6] += str(column[6]) + "\t"
|
||||
lines[7] += str(column[7]) + "\t"
|
||||
lines[8] += str(column[8]) + "\t"
|
||||
lines[9] += str(column[9]) + "\t"
|
||||
lines[10] += str(column[10]) + "\t"
|
||||
|
||||
for l in lines:
|
||||
print l
|
||||
|
||||
def pp_accuracy():
|
||||
print "Accuracy: "+str(round(accuracy*100,4))+"%"
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_predictionfile()
|
||||
load_predictionfile(predfile)
|
||||
#print preds
|
||||
confusion_matrix()
|
||||
pp_confusionmatrix()
|
||||
#print conf_matr
|
||||
accuracy()
|
||||
#print "Accuracy: "+str(accuracy)
|
||||
pp_accuracy()
|
||||
prec()
|
||||
print precision
|
||||
avg_prec()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user