Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to python3 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Digit Recognizer/kNN/kNN_by_myself.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def classify(inX, dataSet, labels, k):
for i in range(k):
voteIlabel = labels[sortedDistIndicies[i],0]
classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1
sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True)
sortedClassCount = sorted(classCount.items(), key=operator.itemgetter(1), reverse=True)
return sortedClassCount[0][0]

def saveResult(result):
with open('result.csv','wb') as myFile:
with open('result.csv','w') as myFile:
myWriter=csv.writer(myFile)
for i in result:
tmp=[]
Expand All @@ -97,10 +97,10 @@ def handwritingClassTest():
for i in range(m):
classifierResult = classify(testData[i], trainData, trainLabel.transpose(), 5)
resultList.append(classifierResult)
print "the classifier came back with: %d, the real answer is: %d" % (classifierResult, testLabel[0,i])
print ("the classifier came back with: " + str(classifierResult) + ", the real answer is: " + str(testLabel[0,i]))
if (classifierResult != testLabel[0,i]): errorCount += 1.0
print "\nthe total number of errors is: %d" % errorCount
print "\nthe total error rate is: %f" % (errorCount/float(m))
print ("the total number of errors is: " + str(errorCount))
print ("the total error rate is: " + str((errorCount/float(m))))
saveResult(resultList)
'''
trainData[0:20000], trainLabel.transpose()[0:20000]
Expand Down