Skip to content
Snippets Groups Projects
Commit c7d1e9b3 authored by che12's avatar che12
Browse files

latest code

parent 5a7b633f
No related branches found
No related tags found
No related merge requests found
......@@ -41,11 +41,32 @@ def classify(k,p):
neighbors_labels=[trainimage_labels[index] for index in neighbors_indices]
counts = np.bincount(neighbors_labels)
result=np.argmax(counts)
print result
#print result
test_result.append(result)
totalCount=len(testimage_labels)
overallAccuracy=sum(testimage_labels[i]==test_result[i] for i in range(totalCount))
print"overall accuracy",overallAccuracy/float(totalCount)
classify(5,2)
\ No newline at end of file
print "k is ",k
confusion_matrix=[[0 for i in range(10)] for j in range(10)]
classCount=[0]*10
for i in range(totalCount):
experiment_class=test_result[i]
real_class=testimage_labels[i]
classCount[int(real_class)]+=1
confusion_matrix[int(real_class)][int(experiment_class)]+=1
for i in range(10):
for j in range(10):
confusion_matrix[i][j]/=float(classCount[i])
confusion_matrix = np.array(confusion_matrix)
#np.set_printoptions(3)
print(confusion_matrix)
'''
for i in range (9):
classify(i+1,2)
'''
classify(5,10)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment