defimg2vector(filename):
returnVect = np.zeros((1,1024))
with open(filename, 'r') as fr:
for i, line in enumerate(fr.readlines()):
#line为str类型,str和list类型均可用len()方法获取长度,#str可以strip(),list不能strip()。#将字符串分割成单个字符串没有什么好办法,只有如下办法。for j in range(len(line.strip())):
returnVect[0,32*i+j] = int(line[j])
return returnVect
filename = 'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\testDigits\\0_0.txt'
c = img2vector(filename)
c
array([[ 0., 0., 0., ..., 0., 0., 0.]])
c.shape
(1, 1024)
import os
os.listdir('C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\trainingDigits')
defhandwritingClassTest():
hwLabels = []
#os.listdir()返回list形式的该目录下的文件列表。
filedir = 'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\'
trainingFileList = os.listdir(filedir + 'trainingDigits')
m = len(trainingFileList)
trainingMat = np.zeros((m,1024))
for i in range(m):
fileNameStr = trainingFileList[i]
fileStr = fileNameStr.split('.')[0]
#获得label,返回int类型0-9中的一个
classNumStr = int(fileStr.split('_')[0])
#存储label为列表形式
hwLabels.append(classNumStr)
#img2vector返回(1,1024)数组
trainingMat[i,:] = img2vector(filedir + 'trainingDigits\\{}'\
.format(fileNameStr))
testFileList = os.listdir(filedir + 'testDigits')
errorCount = 0.0
mTest = len(testFileList)
for i in range(mTest):
fileNameStr = testFileList[i]
fileStr = fileNameStr.split('.')[0]
#获得真实label,返回int类型0-9中的一个
classNumStr = int(fileStr.split('_')[0])
#vectorUnderMat没有[i,:]
vectorUnderTest = img2vector(filedir + 'testDigits\\{}'\
.format(fileNameStr))
#输入test的一个数据的(1,1024)数组,进行kNN算法后,与label做对比#(1,1024)变成(m,1024),想减,求距离,argsort,返回最小的k个邻近,判断
classifierResult = classify0(vectorUnderTest, trainingMat, hwLabels, 3)
print("the classifier came back with:{0}, the real answer is :{1}".format(classifierResult, classNumStr))
if(classifierResult != classNumStr):
errorCount += 1.0
print("\n total error rate is :{}".format(errorCount/float(mTest)))
handwritingClassTest()
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:0, the real answer is :0
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:7, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:1, the real answer is :1
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:2, the real answer is :2
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:9, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:9, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:3, the real answer is :3
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:4, the real answer is :4
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:3, the real answer is :5
the classifier came back with:6, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:5, the real answer is :5
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:6, the real answer is :6
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:7, the real answer is :7
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:6, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:3, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:1, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:1, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:8, the real answer is :8
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:1, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:7, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
the classifier came back with:9, the real answer is :9
total error rate is :0.011627906976744186
filename = 'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\testDigits\\0_0.txt'with open(filename, 'r') as fr:
#line中含有'\n',所以print会再加一个'\n'出现隔一行for i, line in enumerate(fr.readlines()):
print(i,line)
print("********************************************************")
with open(filename, 'r') as fr:
for i, line in enumerate(fr.readlines()):
print(i,line.strip())