机器学习实战-kNN分类手写数字笔记

import numpy as np
import pandas as pd
def classify0(inX, dataSet, labels, k):
    #inX代表输入的数据坐标,DataSet:n个m维数据,大小n*m
    dataSetSize = dataSet.shape[0]
    #求x与各数据坐标的差,形成n*m的差值数组
    diffMat = np.tile(inX, (dataSetSize,1)) - dataSet
    sqDiffMat = diffMat ** 2 
    #np.sum(axis = 0/1);python自带的sum(sequence,[start,])求和再加start
    sqDistances = sqDiffMat.sum(axis = 1)
    distances = sqDistances ** 0.5
    #np.argsort(x),返回排序升序序号。http://blog.csdn.net/maoersong/article/details/21875705
    sortedDistIndicies = distances.argsort()
    classCount = {}
    for i in range(k):
        voteLabel = labels[sortedDistIndicies[i]]
        classCount[voteLabel] = classCount.get(voteLabel, 0) +1
    #http://www.cnblogs.com/zle1992/p/6271105.html
    #http://blog.csdn.net/dongtingzhizi/article/details/12068205
    #key = operator.itemgetter(1) 提取classCount第2个域作为排序
    #python3 中 用dict.items()没有iteritems()方法了
    #key = operator.itemgetter(1)
    sortedClassCount = sorted(classCount.items(), key = lambda x:x[1], reverse = True)
    #sortedClassCount[0]为行最小第一项,第二个[0]提取第一项的列class
    return sortedClassCount[0][0]
def img2vector(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')
['0_0.txt',
 '0_1.txt',
 '0_10.txt',
 '0_100.txt',
 '0_101.txt',
 '0_102.txt',
 '0_103.txt',
 '0_104.txt',
 '0_105.txt',
 '0_106.txt',
 '0_107.txt',
 '0_108.txt',
 '0_109.txt',
 '0_11.txt',
 '0_110.txt',
 '0_111.txt',
 '0_112.txt',
 '0_113.txt',
 '0_114.txt',
 '0_115.txt',
 '0_116.txt',
 '0_117.txt',
 '0_118.txt',
 '0_119.txt',
 '0_12.txt',
 '0_120.txt',
 '0_121.txt',
 '0_122.txt',
 '0_123.txt',
 '0_124.txt',
 '0_125.txt',
 '0_126.txt',
 '0_127.txt',
 '0_128.txt',
 '0_129.txt',
 '0_13.txt',
 '0_130.txt',
 '0_131.txt',
 '0_132.txt',
 '0_133.txt',
 '0_134.txt',
 '0_135.txt',
 '0_136.txt',
 '0_137.txt',
 '0_138.txt',
 '0_139.txt',
 '0_14.txt',
 '0_140.txt',
 '0_141.txt',
 '0_142.txt',
 '0_143.txt',
 '0_144.txt',
 '0_145.txt',
 '0_146.txt',
 '0_147.txt',
 '0_148.txt',
 '0_149.txt',
 '0_15.txt',
 '0_150.txt',
 '0_151.txt',
 '0_152.txt',
 '0_153.txt',
 '0_154.txt',
 '0_155.txt',
 '0_156.txt',
 '0_157.txt',
 '0_158.txt',
 '0_159.txt',
 '0_16.txt',
 '0_160.txt',
 '0_161.txt',
 '0_162.txt',
 '0_163.txt',
 '0_164.txt',
 '0_165.txt',
 '0_166.txt',
 '0_167.txt',
 '0_168.txt',
 '0_169.txt',
 '0_17.txt',
 '0_170.txt',
 '0_171.txt',
 '0_172.txt',
 '0_173.txt',
 '0_174.txt',
 '0_175.txt',
 '0_176.txt',
 '0_177.txt',
 '0_178.txt',
 '0_179.txt',
 '0_18.txt',
 '0_180.txt',
 '0_181.txt',
 '0_182.txt',
 '0_183.txt',
 '0_184.txt',
 '0_185.txt',
 '0_186.txt',
 '0_187.txt',
 '0_188.txt',
 '0_19.txt',
 '0_2.txt',
 '0_20.txt',
 '0_21.txt',
 '0_22.txt',
 '0_23.txt',
 '0_24.txt',
 '0_25.txt',
 '0_26.txt',
 '0_27.txt',
 '0_28.txt',
 '0_29.txt',
 '0_3.txt',
 '0_30.txt',
 '0_31.txt',
 '0_32.txt',
 '0_33.txt',
 '0_34.txt',
 '0_35.txt',
 '0_36.txt',
 '0_37.txt',
 '0_38.txt',
 '0_39.txt',
 '0_4.txt',
 '0_40.txt',
 '0_41.txt',
 '0_42.txt',
 '0_43.txt',
 '0_44.txt',
 '0_45.txt',
 '0_46.txt',
 '0_47.txt',
 '0_48.txt',
 '0_49.txt',
 '0_5.txt',
 '0_50.txt',
 '0_51.txt',
 '0_52.txt',
 '0_53.txt',
 '0_54.txt',
 '0_55.txt',
 '0_56.txt',
 '0_57.txt',
 '0_58.txt',
 '0_59.txt',
 '0_6.txt',
 '0_60.txt',
 '0_61.txt',
 '0_62.txt',
 '0_63.txt',
 '0_64.txt',
 '0_65.txt',
 '0_66.txt',
 '0_67.txt',
 '0_68.txt',
 '0_69.txt',
 '0_7.txt',
 '0_70.txt',
 '0_71.txt',
 '0_72.txt',
 '0_73.txt',
 '0_74.txt',
 '0_75.txt',
 '0_76.txt',
 '0_77.txt',
 '0_78.txt',
 '0_79.txt',
 '0_8.txt',
 '0_80.txt',
 '0_81.txt',
 '0_82.txt',
 '0_83.txt',
 '0_84.txt',
 '0_85.txt',
 '0_86.txt',
 '0_87.txt',
 '0_88.txt',
 '0_89.txt',
 '0_9.txt',
 '0_90.txt',
 '0_91.txt',
 '0_92.txt',
 '0_93.txt',
 '0_94.txt',
 '0_95.txt',
 '0_96.txt',
 '0_97.txt',
 '0_98.txt',
 '0_99.txt',
 '1_0.txt',
 '1_1.txt',
 '1_10.txt',
 '1_100.txt',
 '1_101.txt',
 '1_102.txt',
 '1_103.txt',
 '1_104.txt',
 '1_105.txt',
 '1_106.txt',
 '1_107.txt',
 '1_108.txt',
 '1_109.txt',
 '1_11.txt',
 '1_110.txt',
 '1_111.txt',
 '1_112.txt',
 '1_113.txt',
 '1_114.txt',
 '1_115.txt',
 '1_116.txt',
 '1_117.txt',
 '1_118.txt',
 '1_119.txt',
 '1_12.txt',
 '1_120.txt',
 '1_121.txt',
 '1_122.txt',
 '1_123.txt',
 '1_124.txt',
 '1_125.txt',
 '1_126.txt',
 '1_127.txt',
 '1_128.txt',
 '1_129.txt',
 '1_13.txt',
 '1_130.txt',
 '1_131.txt',
 '1_132.txt',
 '1_133.txt',
 '1_134.txt',
 '1_135.txt',
 '1_136.txt',
 '1_137.txt',
 '1_138.txt',
 '1_139.txt',
 '1_14.txt',
 '1_140.txt',
 '1_141.txt',
 '1_142.txt',
 '1_143.txt',
 '1_144.txt',
 '1_145.txt',
 '1_146.txt',
 '1_147.txt',
 '1_148.txt',
 '1_149.txt',
 '1_15.txt',
 '1_150.txt',
 '1_151.txt',
 '1_152.txt',
 '1_153.txt',
 '1_154.txt',
 '1_155.txt',
 '1_156.txt',
 '1_157.txt',
 '1_158.txt',
 '1_159.txt',
 '1_16.txt',
 '1_160.txt',
 '1_161.txt',
 '1_162.txt',
 '1_163.txt',
 '1_164.txt',
 '1_165.txt',
 '1_166.txt',
 '1_167.txt',
 '1_168.txt',
 '1_169.txt',
 '1_17.txt',
 '1_170.txt',
 '1_171.txt',
 '1_172.txt',
 '1_173.txt',
 '1_174.txt',
 '1_175.txt',
 '1_176.txt',
 '1_177.txt',
 '1_178.txt',
 '1_179.txt',
 '1_18.txt',
 '1_180.txt',
 '1_181.txt',
 '1_182.txt',
 '1_183.txt',
 '1_184.txt',
 '1_185.txt',
 '1_186.txt',
 '1_187.txt',
 '1_188.txt',
 '1_189.txt',
 '1_19.txt',
 '1_190.txt',
 '1_191.txt',
 '1_192.txt',
 '1_193.txt',
 '1_194.txt',
 '1_195.txt',
 '1_196.txt',
 '1_197.txt',
 '1_2.txt',
 '1_20.txt',
 '1_21.txt',
 '1_22.txt',
 '1_23.txt',
 '1_24.txt',
 '1_25.txt',
 '1_26.txt',
 '1_27.txt',
 '1_28.txt',
 '1_29.txt',
 '1_3.txt',
 '1_30.txt',
 '1_31.txt',
 '1_32.txt',
 '1_33.txt',
 '1_34.txt',
 '1_35.txt',
 '1_36.txt',
 '1_37.txt',
 '1_38.txt',
 '1_39.txt',
 '1_4.txt',
 '1_40.txt',
 '1_41.txt',
 '1_42.txt',
 '1_43.txt',
 '1_44.txt',
 '1_45.txt',
 '1_46.txt',
 '1_47.txt',
 '1_48.txt',
 '1_49.txt',
 '1_5.txt',
 '1_50.txt',
 '1_51.txt',
 '1_52.txt',
 '1_53.txt',
 '1_54.txt',
 '1_55.txt',
 '1_56.txt',
 '1_57.txt',
 '1_58.txt',
 '1_59.txt',
 '1_6.txt',
 '1_60.txt',
 '1_61.txt',
 '1_62.txt',
 '1_63.txt',
 '1_64.txt',
 '1_65.txt',
 '1_66.txt',
 '1_67.txt',
 '1_68.txt',
 '1_69.txt',
 '1_7.txt',
 '1_70.txt',
 '1_71.txt',
 '1_72.txt',
 '1_73.txt',
 '1_74.txt',
 '1_75.txt',
 '1_76.txt',
 '1_77.txt',
 '1_78.txt',
 '1_79.txt',
 '1_8.txt',
 '1_80.txt',
 '1_81.txt',
 '1_82.txt',
 '1_83.txt',
 '1_84.txt',
 '1_85.txt',
 '1_86.txt',
 '1_87.txt',
 '1_88.txt',
 '1_89.txt',
 '1_9.txt',
 '1_90.txt',
 '1_91.txt',
 '1_92.txt',
 '1_93.txt',
 '1_94.txt',
 '1_95.txt',
 '1_96.txt',
 '1_97.txt',
 '1_98.txt',
 '1_99.txt',
 '2_0.txt',
 '2_1.txt',
 '2_10.txt',
 '2_100.txt',
 '2_101.txt',
 '2_102.txt',
 '2_103.txt',
 '2_104.txt',
 '2_105.txt',
 '2_106.txt',
 '2_107.txt',
 '2_108.txt',
 '2_109.txt',
 '2_11.txt',
 '2_110.txt',
 '2_111.txt',
 '2_112.txt',
 '2_113.txt',
 '2_114.txt',
 '2_115.txt',
 '2_116.txt',
 '2_117.txt',
 '2_118.txt',
 '2_119.txt',
 '2_12.txt',
 '2_120.txt',
 '2_121.txt',
 '2_122.txt',
 '2_123.txt',
 '2_124.txt',
 '2_125.txt',
 '2_126.txt',
 '2_127.txt',
 '2_128.txt',
 '2_129.txt',
 '2_13.txt',
 '2_130.txt',
 '2_131.txt',
 '2_132.txt',
 '2_133.txt',
 '2_134.txt',
 '2_135.txt',
 '2_136.txt',
 '2_137.txt',
 '2_138.txt',
 '2_139.txt',
 '2_14.txt',
 '2_140.txt',
 '2_141.txt',
 '2_142.txt',
 '2_143.txt',
 '2_144.txt',
 '2_145.txt',
 '2_146.txt',
 '2_147.txt',
 '2_148.txt',
 '2_149.txt',
 '2_15.txt',
 '2_150.txt',
 '2_151.txt',
 '2_152.txt',
 '2_153.txt',
 '2_154.txt',
 '2_155.txt',
 '2_156.txt',
 '2_157.txt',
 '2_158.txt',
 '2_159.txt',
 '2_16.txt',
 '2_160.txt',
 '2_161.txt',
 '2_162.txt',
 '2_163.txt',
 '2_164.txt',
 '2_165.txt',
 '2_166.txt',
 '2_167.txt',
 '2_168.txt',
 '2_169.txt',
 '2_17.txt',
 '2_170.txt',
 '2_171.txt',
 '2_172.txt',
 '2_173.txt',
 '2_174.txt',
 '2_175.txt',
 '2_176.txt',
 '2_177.txt',
 '2_178.txt',
 '2_179.txt',
 '2_18.txt',
 '2_180.txt',
 '2_181.txt',
 '2_182.txt',
 '2_183.txt',
 '2_184.txt',
 '2_185.txt',
 '2_186.txt',
 '2_187.txt',
 '2_188.txt',
 '2_189.txt',
 '2_19.txt',
 '2_190.txt',
 '2_191.txt',
 '2_192.txt',
 '2_193.txt',
 '2_194.txt',
 '2_2.txt',
 '2_20.txt',
 '2_21.txt',
 '2_22.txt',
 '2_23.txt',
 '2_24.txt',
 '2_25.txt',
 '2_26.txt',
 '2_27.txt',
 '2_28.txt',
 '2_29.txt',
 '2_3.txt',
 '2_30.txt',
 '2_31.txt',
 '2_32.txt',
 '2_33.txt',
 '2_34.txt',
 '2_35.txt',
 '2_36.txt',
 '2_37.txt',
 '2_38.txt',
 '2_39.txt',
 '2_4.txt',
 '2_40.txt',
 '2_41.txt',
 '2_42.txt',
 '2_43.txt',
 '2_44.txt',
 '2_45.txt',
 '2_46.txt',
 '2_47.txt',
 '2_48.txt',
 '2_49.txt',
 '2_5.txt',
 '2_50.txt',
 '2_51.txt',
 '2_52.txt',
 '2_53.txt',
 '2_54.txt',
 '2_55.txt',
 '2_56.txt',
 '2_57.txt',
 '2_58.txt',
 '2_59.txt',
 '2_6.txt',
 '2_60.txt',
 '2_61.txt',
 '2_62.txt',
 '2_63.txt',
 '2_64.txt',
 '2_65.txt',
 '2_66.txt',
 '2_67.txt',
 '2_68.txt',
 '2_69.txt',
 '2_7.txt',
 '2_70.txt',
 '2_71.txt',
 '2_72.txt',
 '2_73.txt',
 '2_74.txt',
 '2_75.txt',
 '2_76.txt',
 '2_77.txt',
 '2_78.txt',
 '2_79.txt',
 '2_8.txt',
 '2_80.txt',
 '2_81.txt',
 '2_82.txt',
 '2_83.txt',
 '2_84.txt',
 '2_85.txt',
 '2_86.txt',
 '2_87.txt',
 '2_88.txt',
 '2_89.txt',
 '2_9.txt',
 '2_90.txt',
 '2_91.txt',
 '2_92.txt',
 '2_93.txt',
 '2_94.txt',
 '2_95.txt',
 '2_96.txt',
 '2_97.txt',
 '2_98.txt',
 '2_99.txt',
 '3_0.txt',
 '3_1.txt',
 '3_10.txt',
 '3_100.txt',
 '3_101.txt',
 '3_102.txt',
 '3_103.txt',
 '3_104.txt',
 '3_105.txt',
 '3_106.txt',
 '3_107.txt',
 '3_108.txt',
 '3_109.txt',
 '3_11.txt',
 '3_110.txt',
 '3_111.txt',
 '3_112.txt',
 '3_113.txt',
 '3_114.txt',
 '3_115.txt',
 '3_116.txt',
 '3_117.txt',
 '3_118.txt',
 '3_119.txt',
 '3_12.txt',
 '3_120.txt',
 '3_121.txt',
 '3_122.txt',
 '3_123.txt',
 '3_124.txt',
 '3_125.txt',
 '3_126.txt',
 '3_127.txt',
 '3_128.txt',
 '3_129.txt',
 '3_13.txt',
 '3_130.txt',
 '3_131.txt',
 '3_132.txt',
 '3_133.txt',
 '3_134.txt',
 '3_135.txt',
 '3_136.txt',
 '3_137.txt',
 '3_138.txt',
 '3_139.txt',
 '3_14.txt',
 '3_140.txt',
 '3_141.txt',
 '3_142.txt',
 '3_143.txt',
 '3_144.txt',
 '3_145.txt',
 '3_146.txt',
 '3_147.txt',
 '3_148.txt',
 '3_149.txt',
 '3_15.txt',
 '3_150.txt',
 '3_151.txt',
 '3_152.txt',
 '3_153.txt',
 '3_154.txt',
 '3_155.txt',
 '3_156.txt',
 '3_157.txt',
 '3_158.txt',
 '3_159.txt',
 '3_16.txt',
 '3_160.txt',
 '3_161.txt',
 '3_162.txt',
 '3_163.txt',
 '3_164.txt',
 '3_165.txt',
 '3_166.txt',
 '3_167.txt',
 '3_168.txt',
 '3_169.txt',
 '3_17.txt',
 '3_170.txt',
 '3_171.txt',
 '3_172.txt',
 '3_173.txt',
 '3_174.txt',
 '3_175.txt',
 '3_176.txt',
 '3_177.txt',
 '3_178.txt',
 '3_179.txt',
 '3_18.txt',
 '3_180.txt',
 '3_181.txt',
 '3_182.txt',
 '3_183.txt',
 '3_184.txt',
 '3_185.txt',
 '3_186.txt',
 '3_187.txt',
 '3_188.txt',
 '3_189.txt',
 '3_19.txt',
 '3_190.txt',
 '3_191.txt',
 '3_192.txt',
 '3_193.txt',
 '3_194.txt',
 '3_195.txt',
 '3_196.txt',
 '3_197.txt',
 '3_198.txt',
 '3_2.txt',
 '3_20.txt',
 '3_21.txt',
 '3_22.txt',
 '3_23.txt',
 '3_24.txt',
 '3_25.txt',
 '3_26.txt',
 '3_27.txt',
 '3_28.txt',
 '3_29.txt',
 '3_3.txt',
 '3_30.txt',
 '3_31.txt',
 '3_32.txt',
 '3_33.txt',
 '3_34.txt',
 '3_35.txt',
 '3_36.txt',
 '3_37.txt',
 '3_38.txt',
 '3_39.txt',
 '3_4.txt',
 '3_40.txt',
 '3_41.txt',
 '3_42.txt',
 '3_43.txt',
 '3_44.txt',
 '3_45.txt',
 '3_46.txt',
 '3_47.txt',
 '3_48.txt',
 '3_49.txt',
 '3_5.txt',
 '3_50.txt',
 '3_51.txt',
 '3_52.txt',
 '3_53.txt',
 '3_54.txt',
 '3_55.txt',
 '3_56.txt',
 '3_57.txt',
 '3_58.txt',
 '3_59.txt',
 '3_6.txt',
 '3_60.txt',
 '3_61.txt',
 '3_62.txt',
 '3_63.txt',
 '3_64.txt',
 '3_65.txt',
 '3_66.txt',
 '3_67.txt',
 '3_68.txt',
 '3_69.txt',
 '3_7.txt',
 '3_70.txt',
 '3_71.txt',
 '3_72.txt',
 '3_73.txt',
 '3_74.txt',
 '3_75.txt',
 '3_76.txt',
 '3_77.txt',
 '3_78.txt',
 '3_79.txt',
 '3_8.txt',
 '3_80.txt',
 '3_81.txt',
 '3_82.txt',
 '3_83.txt',
 '3_84.txt',
 '3_85.txt',
 '3_86.txt',
 '3_87.txt',
 '3_88.txt',
 '3_89.txt',
 '3_9.txt',
 '3_90.txt',
 '3_91.txt',
 '3_92.txt',
 '3_93.txt',
 '3_94.txt',
 '3_95.txt',
 '3_96.txt',
 '3_97.txt',
 '3_98.txt',
 '3_99.txt',
 '4_0.txt',
 '4_1.txt',
 '4_10.txt',
 '4_100.txt',
 '4_101.txt',
 '4_102.txt',
 '4_103.txt',
 '4_104.txt',
 '4_105.txt',
 '4_106.txt',
 '4_107.txt',
 '4_108.txt',
 '4_109.txt',
 '4_11.txt',
 '4_110.txt',
 '4_111.txt',
 '4_112.txt',
 '4_113.txt',
 '4_114.txt',
 '4_115.txt',
 '4_116.txt',
 '4_117.txt',
 '4_118.txt',
 '4_119.txt',
 '4_12.txt',
 '4_120.txt',
 '4_121.txt',
 '4_122.txt',
 '4_123.txt',
 '4_124.txt',
 '4_125.txt',
 '4_126.txt',
 '4_127.txt',
 '4_128.txt',
 '4_129.txt',
 '4_13.txt',
 '4_130.txt',
 '4_131.txt',
 '4_132.txt',
 '4_133.txt',
 '4_134.txt',
 '4_135.txt',
 '4_136.txt',
 '4_137.txt',
 '4_138.txt',
 '4_139.txt',
 '4_14.txt',
 '4_140.txt',
 '4_141.txt',
 '4_142.txt',
 '4_143.txt',
 '4_144.txt',
 '4_145.txt',
 '4_146.txt',
 '4_147.txt',
 '4_148.txt',
 '4_149.txt',
 '4_15.txt',
 '4_150.txt',
 '4_151.txt',
 '4_152.txt',
 '4_153.txt',
 '4_154.txt',
 '4_155.txt',
 '4_156.txt',
 '4_157.txt',
 '4_158.txt',
 '4_159.txt',
 '4_16.txt',
 '4_160.txt',
 '4_161.txt',
 '4_162.txt',
 '4_163.txt',
 '4_164.txt',
 '4_165.txt',
 '4_166.txt',
 '4_167.txt',
 '4_168.txt',
 '4_169.txt',
 '4_17.txt',
 '4_170.txt',
 '4_171.txt',
 '4_172.txt',
 '4_173.txt',
 '4_174.txt',
 '4_175.txt',
 '4_176.txt',
 '4_177.txt',
 '4_178.txt',
 '4_179.txt',
 '4_18.txt',
 '4_180.txt',
 '4_181.txt',
 '4_182.txt',
 '4_183.txt',
 '4_184.txt',
 '4_185.txt',
 '4_19.txt',
 '4_2.txt',
 '4_20.txt',
 '4_21.txt',
 '4_22.txt',
 '4_23.txt',
 '4_24.txt',
 '4_25.txt',
 '4_26.txt',
 '4_27.txt',
 '4_28.txt',
 '4_29.txt',
 '4_3.txt',
 '4_30.txt',
 '4_31.txt',
 '4_32.txt',
 '4_33.txt',
 '4_34.txt',
 '4_35.txt',
 '4_36.txt',
 '4_37.txt',
 '4_38.txt',
 '4_39.txt',
 '4_4.txt',
 '4_40.txt',
 '4_41.txt',
 '4_42.txt',
 '4_43.txt',
 '4_44.txt',
 '4_45.txt',
 '4_46.txt',
 '4_47.txt',
 '4_48.txt',
 '4_49.txt',
 '4_5.txt',
 '4_50.txt',
 '4_51.txt',
 '4_52.txt',
 '4_53.txt',
 '4_54.txt',
 '4_55.txt',
 '4_56.txt',
 '4_57.txt',
 '4_58.txt',
 '4_59.txt',
 '4_6.txt',
 '4_60.txt',
 '4_61.txt',
 '4_62.txt',
 '4_63.txt',
 '4_64.txt',
 '4_65.txt',
 '4_66.txt',
 '4_67.txt',
 '4_68.txt',
 '4_69.txt',
 '4_7.txt',
 '4_70.txt',
 '4_71.txt',
 '4_72.txt',
 '4_73.txt',
 '4_74.txt',
 '4_75.txt',
 '4_76.txt',
 '4_77.txt',
 '4_78.txt',
 '4_79.txt',
 '4_8.txt',
 '4_80.txt',
 '4_81.txt',
 '4_82.txt',
 '4_83.txt',
 '4_84.txt',
 '4_85.txt',
 '4_86.txt',
 '4_87.txt',
 '4_88.txt',
 '4_89.txt',
 '4_9.txt',
 '4_90.txt',
 '4_91.txt',
 '4_92.txt',
 '4_93.txt',
 '4_94.txt',
 '4_95.txt',
 '4_96.txt',
 '4_97.txt',
 '4_98.txt',
 '4_99.txt',
 '5_0.txt',
 '5_1.txt',
 '5_10.txt',
 '5_100.txt',
 '5_101.txt',
 '5_102.txt',
 '5_103.txt',
 '5_104.txt',
 '5_105.txt',
 '5_106.txt',
 '5_107.txt',
 '5_108.txt',
 '5_109.txt',
 '5_11.txt',
 '5_110.txt',
 '5_111.txt',
 '5_112.txt',
 '5_113.txt',
 '5_114.txt',
 '5_115.txt',
 '5_116.txt',
 '5_117.txt',
 '5_118.txt',
 '5_119.txt',
 '5_12.txt',
 '5_120.txt',
 '5_121.txt',
 '5_122.txt',
 '5_123.txt',
 '5_124.txt',
 '5_125.txt',
 '5_126.txt',
 '5_127.txt',
 ...]
file = 'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\trainingDigits'
'\\'.join(file.split('\\')[:-1])+'\\'
'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\'
def handwritingClassTest():
    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
filedir = 'C:\\Users\\Administrator\\Desktop\\data\\machinelearninginaction\\Ch02\\digits\\'
os.listdir(filedir + 'trainingDigits')
['0_0.txt',
 '0_1.txt',
 '0_10.txt',
 '0_100.txt',
 '0_101.txt',
 '0_102.txt',
 '0_103.txt',
 '0_104.txt',
 '0_105.txt',
 '0_106.txt',
 '0_107.txt',
 '0_108.txt',
 '0_109.txt',
 '0_11.txt',
 '0_110.txt',
 '0_111.txt',
 '0_112.txt',
 '0_113.txt',
 '0_114.txt',
 '0_115.txt',
 '0_116.txt',
 '0_117.txt',
 '0_118.txt',
 '0_119.txt',
 '0_12.txt',
 '0_120.txt',
 '0_121.txt',
 '0_122.txt',
 '0_123.txt',
 '0_124.txt',
 '0_125.txt',
 '0_126.txt',
 '0_127.txt',
 '0_128.txt',
 '0_129.txt',
 '0_13.txt',
 '0_130.txt',
 '0_131.txt',
 '0_132.txt',
 '0_133.txt',
 '0_134.txt',
 '0_135.txt',
 '0_136.txt',
 '0_137.txt',
 '0_138.txt',
 '0_139.txt',
 '0_14.txt',
 '0_140.txt',
 '0_141.txt',
 '0_142.txt',
 '0_143.txt',
 '0_144.txt',
 '0_145.txt',
 '0_146.txt',
 '0_147.txt',
 '0_148.txt',
 '0_149.txt',
 '0_15.txt',
 '0_150.txt',
 '0_151.txt',
 '0_152.txt',
 '0_153.txt',
 '0_154.txt',
 '0_155.txt',
 '0_156.txt',
 '0_157.txt',
 '0_158.txt',
 '0_159.txt',
 '0_16.txt',
 '0_160.txt',
 '0_161.txt',
 '0_162.txt',
 '0_163.txt',
 '0_164.txt',
 '0_165.txt',
 '0_166.txt',
 '0_167.txt',
 '0_168.txt',
 '0_169.txt',
 '0_17.txt',
 '0_170.txt',
 '0_171.txt',
 '0_172.txt',
 '0_173.txt',
 '0_174.txt',
 '0_175.txt',
 '0_176.txt',
 '0_177.txt',
 '0_178.txt',
 '0_179.txt',
 '0_18.txt',
 '0_180.txt',
 '0_181.txt',
 '0_182.txt',
 '0_183.txt',
 '0_184.txt',
 '0_185.txt',
 '0_186.txt',
 '0_187.txt',
 '0_188.txt',
 '0_19.txt',
 '0_2.txt',
 '0_20.txt',
 '0_21.txt',
 '0_22.txt',
 '0_23.txt',
 '0_24.txt',
 '0_25.txt',
 '0_26.txt',
 '0_27.txt',
 '0_28.txt',
 '0_29.txt',
 '0_3.txt',
 '0_30.txt',
 '0_31.txt',
 '0_32.txt',
 '0_33.txt',
 '0_34.txt',
 '0_35.txt',
 '0_36.txt',
 '0_37.txt',
 '0_38.txt',
 '0_39.txt',
 '0_4.txt',
 '0_40.txt',
 '0_41.txt',
 '0_42.txt',
 '0_43.txt',
 '0_44.txt',
 '0_45.txt',
 '0_46.txt',
 '0_47.txt',
 '0_48.txt',
 '0_49.txt',
 '0_5.txt',
 '0_50.txt',
 '0_51.txt',
 '0_52.txt',
 '0_53.txt',
 '0_54.txt',
 '0_55.txt',
 '0_56.txt',
 '0_57.txt',
 '0_58.txt',
 '0_59.txt',
 '0_6.txt',
 '0_60.txt',
 '0_61.txt',
 '0_62.txt',
 '0_63.txt',
 '0_64.txt',
 '0_65.txt',
 '0_66.txt',
 '0_67.txt',
 '0_68.txt',
 '0_69.txt',
 '0_7.txt',
 '0_70.txt',
 '0_71.txt',
 '0_72.txt',
 '0_73.txt',
 '0_74.txt',
 '0_75.txt',
 '0_76.txt',
 '0_77.txt',
 '0_78.txt',
 '0_79.txt',
 '0_8.txt',
 '0_80.txt',
 '0_81.txt',
 '0_82.txt',
 '0_83.txt',
 '0_84.txt',
 '0_85.txt',
 '0_86.txt',
 '0_87.txt',
 '0_88.txt',
 '0_89.txt',
 '0_9.txt',
 '0_90.txt',
 '0_91.txt',
 '0_92.txt',
 '0_93.txt',
 '0_94.txt',
 '0_95.txt',
 '0_96.txt',
 '0_97.txt',
 '0_98.txt',
 '0_99.txt',
 '1_0.txt',
 '1_1.txt',
 '1_10.txt',
 '1_100.txt',
 '1_101.txt',
 '1_102.txt',
 '1_103.txt',
 '1_104.txt',
 '1_105.txt',
 '1_106.txt',
 '1_107.txt',
 '1_108.txt',
 '1_109.txt',
 '1_11.txt',
 '1_110.txt',
 '1_111.txt',
 '1_112.txt',
 '1_113.txt',
 '1_114.txt',
 '1_115.txt',
 '1_116.txt',
 '1_117.txt',
 '1_118.txt',
 '1_119.txt',
 '1_12.txt',
 '1_120.txt',
 '1_121.txt',
 '1_122.txt',
 '1_123.txt',
 '1_124.txt',
 '1_125.txt',
 '1_126.txt',
 '1_127.txt',
 '1_128.txt',
 '1_129.txt',
 '1_13.txt',
 '1_130.txt',
 '1_131.txt',
 '1_132.txt',
 '1_133.txt',
 '1_134.txt',
 '1_135.txt',
 '1_136.txt',
 '1_137.txt',
 '1_138.txt',
 '1_139.txt',
 '1_14.txt',
 '1_140.txt',
 '1_141.txt',
 '1_142.txt',
 '1_143.txt',
 '1_144.txt',
 '1_145.txt',
 '1_146.txt',
 '1_147.txt',
 '1_148.txt',
 '1_149.txt',
 '1_15.txt',
 '1_150.txt',
 '1_151.txt',
 '1_152.txt',
 '1_153.txt',
 '1_154.txt',
 '1_155.txt',
 '1_156.txt',
 '1_157.txt',
 '1_158.txt',
 '1_159.txt',
 '1_16.txt',
 '1_160.txt',
 '1_161.txt',
 '1_162.txt',
 '1_163.txt',
 '1_164.txt',
 '1_165.txt',
 '1_166.txt',
 '1_167.txt',
 '1_168.txt',
 '1_169.txt',
 '1_17.txt',
 '1_170.txt',
 '1_171.txt',
 '1_172.txt',
 '1_173.txt',
 '1_174.txt',
 '1_175.txt',
 '1_176.txt',
 '1_177.txt',
 '1_178.txt',
 '1_179.txt',
 '1_18.txt',
 '1_180.txt',
 '1_181.txt',
 '1_182.txt',
 '1_183.txt',
 '1_184.txt',
 '1_185.txt',
 '1_186.txt',
 '1_187.txt',
 '1_188.txt',
 '1_189.txt',
 '1_19.txt',
 '1_190.txt',
 '1_191.txt',
 '1_192.txt',
 '1_193.txt',
 '1_194.txt',
 '1_195.txt',
 '1_196.txt',
 '1_197.txt',
 '1_2.txt',
 '1_20.txt',
 '1_21.txt',
 '1_22.txt',
 '1_23.txt',
 '1_24.txt',
 '1_25.txt',
 '1_26.txt',
 '1_27.txt',
 '1_28.txt',
 '1_29.txt',
 '1_3.txt',
 '1_30.txt',
 '1_31.txt',
 '1_32.txt',
 '1_33.txt',
 '1_34.txt',
 '1_35.txt',
 '1_36.txt',
 '1_37.txt',
 '1_38.txt',
 '1_39.txt',
 '1_4.txt',
 '1_40.txt',
 '1_41.txt',
 '1_42.txt',
 '1_43.txt',
 '1_44.txt',
 '1_45.txt',
 '1_46.txt',
 '1_47.txt',
 '1_48.txt',
 '1_49.txt',
 '1_5.txt',
 '1_50.txt',
 '1_51.txt',
 '1_52.txt',
 '1_53.txt',
 '1_54.txt',
 '1_55.txt',
 '1_56.txt',
 '1_57.txt',
 '1_58.txt',
 '1_59.txt',
 '1_6.txt',
 '1_60.txt',
 '1_61.txt',
 '1_62.txt',
 '1_63.txt',
 '1_64.txt',
 '1_65.txt',
 '1_66.txt',
 '1_67.txt',
 '1_68.txt',
 '1_69.txt',
 '1_7.txt',
 '1_70.txt',
 '1_71.txt',
 '1_72.txt',
 '1_73.txt',
 '1_74.txt',
 '1_75.txt',
 '1_76.txt',
 '1_77.txt',
 '1_78.txt',
 '1_79.txt',
 '1_8.txt',
 '1_80.txt',
 '1_81.txt',
 '1_82.txt',
 '1_83.txt',
 '1_84.txt',
 '1_85.txt',
 '1_86.txt',
 '1_87.txt',
 '1_88.txt',
 '1_89.txt',
 '1_9.txt',
 '1_90.txt',
 '1_91.txt',
 '1_92.txt',
 '1_93.txt',
 '1_94.txt',
 '1_95.txt',
 '1_96.txt',
 '1_97.txt',
 '1_98.txt',
 '1_99.txt',
 '2_0.txt',
 '2_1.txt',
 '2_10.txt',
 '2_100.txt',
 '2_101.txt',
 '2_102.txt',
 '2_103.txt',
 '2_104.txt',
 '2_105.txt',
 '2_106.txt',
 '2_107.txt',
 '2_108.txt',
 '2_109.txt',
 '2_11.txt',
 '2_110.txt',
 '2_111.txt',
 '2_112.txt',
 '2_113.txt',
 '2_114.txt',
 '2_115.txt',
 '2_116.txt',
 '2_117.txt',
 '2_118.txt',
 '2_119.txt',
 '2_12.txt',
 '2_120.txt',
 '2_121.txt',
 '2_122.txt',
 '2_123.txt',
 '2_124.txt',
 '2_125.txt',
 '2_126.txt',
 '2_127.txt',
 '2_128.txt',
 '2_129.txt',
 '2_13.txt',
 '2_130.txt',
 '2_131.txt',
 '2_132.txt',
 '2_133.txt',
 '2_134.txt',
 '2_135.txt',
 '2_136.txt',
 '2_137.txt',
 '2_138.txt',
 '2_139.txt',
 '2_14.txt',
 '2_140.txt',
 '2_141.txt',
 '2_142.txt',
 '2_143.txt',
 '2_144.txt',
 '2_145.txt',
 '2_146.txt',
 '2_147.txt',
 '2_148.txt',
 '2_149.txt',
 '2_15.txt',
 '2_150.txt',
 '2_151.txt',
 '2_152.txt',
 '2_153.txt',
 '2_154.txt',
 '2_155.txt',
 '2_156.txt',
 '2_157.txt',
 '2_158.txt',
 '2_159.txt',
 '2_16.txt',
 '2_160.txt',
 '2_161.txt',
 '2_162.txt',
 '2_163.txt',
 '2_164.txt',
 '2_165.txt',
 '2_166.txt',
 '2_167.txt',
 '2_168.txt',
 '2_169.txt',
 '2_17.txt',
 '2_170.txt',
 '2_171.txt',
 '2_172.txt',
 '2_173.txt',
 '2_174.txt',
 '2_175.txt',
 '2_176.txt',
 '2_177.txt',
 '2_178.txt',
 '2_179.txt',
 '2_18.txt',
 '2_180.txt',
 '2_181.txt',
 '2_182.txt',
 '2_183.txt',
 '2_184.txt',
 '2_185.txt',
 '2_186.txt',
 '2_187.txt',
 '2_188.txt',
 '2_189.txt',
 '2_19.txt',
 '2_190.txt',
 '2_191.txt',
 '2_192.txt',
 '2_193.txt',
 '2_194.txt',
 '2_2.txt',
 '2_20.txt',
 '2_21.txt',
 '2_22.txt',
 '2_23.txt',
 '2_24.txt',
 '2_25.txt',
 '2_26.txt',
 '2_27.txt',
 '2_28.txt',
 '2_29.txt',
 '2_3.txt',
 '2_30.txt',
 '2_31.txt',
 '2_32.txt',
 '2_33.txt',
 '2_34.txt',
 '2_35.txt',
 '2_36.txt',
 '2_37.txt',
 '2_38.txt',
 '2_39.txt',
 '2_4.txt',
 '2_40.txt',
 '2_41.txt',
 '2_42.txt',
 '2_43.txt',
 '2_44.txt',
 '2_45.txt',
 '2_46.txt',
 '2_47.txt',
 '2_48.txt',
 '2_49.txt',
 '2_5.txt',
 '2_50.txt',
 '2_51.txt',
 '2_52.txt',
 '2_53.txt',
 '2_54.txt',
 '2_55.txt',
 '2_56.txt',
 '2_57.txt',
 '2_58.txt',
 '2_59.txt',
 '2_6.txt',
 '2_60.txt',
 '2_61.txt',
 '2_62.txt',
 '2_63.txt',
 '2_64.txt',
 '2_65.txt',
 '2_66.txt',
 '2_67.txt',
 '2_68.txt',
 '2_69.txt',
 '2_7.txt',
 '2_70.txt',
 '2_71.txt',
 '2_72.txt',
 '2_73.txt',
 '2_74.txt',
 '2_75.txt',
 '2_76.txt',
 '2_77.txt',
 '2_78.txt',
 '2_79.txt',
 '2_8.txt',
 '2_80.txt',
 '2_81.txt',
 '2_82.txt',
 '2_83.txt',
 '2_84.txt',
 '2_85.txt',
 '2_86.txt',
 '2_87.txt',
 '2_88.txt',
 '2_89.txt',
 '2_9.txt',
 '2_90.txt',
 '2_91.txt',
 '2_92.txt',
 '2_93.txt',
 '2_94.txt',
 '2_95.txt',
 '2_96.txt',
 '2_97.txt',
 '2_98.txt',
 '2_99.txt',
 '3_0.txt',
 '3_1.txt',
 '3_10.txt',
 '3_100.txt',
 '3_101.txt',
 '3_102.txt',
 '3_103.txt',
 '3_104.txt',
 '3_105.txt',
 '3_106.txt',
 '3_107.txt',
 '3_108.txt',
 '3_109.txt',
 '3_11.txt',
 '3_110.txt',
 '3_111.txt',
 '3_112.txt',
 '3_113.txt',
 '3_114.txt',
 '3_115.txt',
 '3_116.txt',
 '3_117.txt',
 '3_118.txt',
 '3_119.txt',
 '3_12.txt',
 '3_120.txt',
 '3_121.txt',
 '3_122.txt',
 '3_123.txt',
 '3_124.txt',
 '3_125.txt',
 '3_126.txt',
 '3_127.txt',
 '3_128.txt',
 '3_129.txt',
 '3_13.txt',
 '3_130.txt',
 '3_131.txt',
 '3_132.txt',
 '3_133.txt',
 '3_134.txt',
 '3_135.txt',
 '3_136.txt',
 '3_137.txt',
 '3_138.txt',
 '3_139.txt',
 '3_14.txt',
 '3_140.txt',
 '3_141.txt',
 '3_142.txt',
 '3_143.txt',
 '3_144.txt',
 '3_145.txt',
 '3_146.txt',
 '3_147.txt',
 '3_148.txt',
 '3_149.txt',
 '3_15.txt',
 '3_150.txt',
 '3_151.txt',
 '3_152.txt',
 '3_153.txt',
 '3_154.txt',
 '3_155.txt',
 '3_156.txt',
 '3_157.txt',
 '3_158.txt',
 '3_159.txt',
 '3_16.txt',
 '3_160.txt',
 '3_161.txt',
 '3_162.txt',
 '3_163.txt',
 '3_164.txt',
 '3_165.txt',
 '3_166.txt',
 '3_167.txt',
 '3_168.txt',
 '3_169.txt',
 '3_17.txt',
 '3_170.txt',
 '3_171.txt',
 '3_172.txt',
 '3_173.txt',
 '3_174.txt',
 '3_175.txt',
 '3_176.txt',
 '3_177.txt',
 '3_178.txt',
 '3_179.txt',
 '3_18.txt',
 '3_180.txt',
 '3_181.txt',
 '3_182.txt',
 '3_183.txt',
 '3_184.txt',
 '3_185.txt',
 '3_186.txt',
 '3_187.txt',
 '3_188.txt',
 '3_189.txt',
 '3_19.txt',
 '3_190.txt',
 '3_191.txt',
 '3_192.txt',
 '3_193.txt',
 '3_194.txt',
 '3_195.txt',
 '3_196.txt',
 '3_197.txt',
 '3_198.txt',
 '3_2.txt',
 '3_20.txt',
 '3_21.txt',
 '3_22.txt',
 '3_23.txt',
 '3_24.txt',
 '3_25.txt',
 '3_26.txt',
 '3_27.txt',
 '3_28.txt',
 '3_29.txt',
 '3_3.txt',
 '3_30.txt',
 '3_31.txt',
 '3_32.txt',
 '3_33.txt',
 '3_34.txt',
 '3_35.txt',
 '3_36.txt',
 '3_37.txt',
 '3_38.txt',
 '3_39.txt',
 '3_4.txt',
 '3_40.txt',
 '3_41.txt',
 '3_42.txt',
 '3_43.txt',
 '3_44.txt',
 '3_45.txt',
 '3_46.txt',
 '3_47.txt',
 '3_48.txt',
 '3_49.txt',
 '3_5.txt',
 '3_50.txt',
 '3_51.txt',
 '3_52.txt',
 '3_53.txt',
 '3_54.txt',
 '3_55.txt',
 '3_56.txt',
 '3_57.txt',
 '3_58.txt',
 '3_59.txt',
 '3_6.txt',
 '3_60.txt',
 '3_61.txt',
 '3_62.txt',
 '3_63.txt',
 '3_64.txt',
 '3_65.txt',
 '3_66.txt',
 '3_67.txt',
 '3_68.txt',
 '3_69.txt',
 '3_7.txt',
 '3_70.txt',
 '3_71.txt',
 '3_72.txt',
 '3_73.txt',
 '3_74.txt',
 '3_75.txt',
 '3_76.txt',
 '3_77.txt',
 '3_78.txt',
 '3_79.txt',
 '3_8.txt',
 '3_80.txt',
 '3_81.txt',
 '3_82.txt',
 '3_83.txt',
 '3_84.txt',
 '3_85.txt',
 '3_86.txt',
 '3_87.txt',
 '3_88.txt',
 '3_89.txt',
 '3_9.txt',
 '3_90.txt',
 '3_91.txt',
 '3_92.txt',
 '3_93.txt',
 '3_94.txt',
 '3_95.txt',
 '3_96.txt',
 '3_97.txt',
 '3_98.txt',
 '3_99.txt',
 '4_0.txt',
 '4_1.txt',
 '4_10.txt',
 '4_100.txt',
 '4_101.txt',
 '4_102.txt',
 '4_103.txt',
 '4_104.txt',
 '4_105.txt',
 '4_106.txt',
 '4_107.txt',
 '4_108.txt',
 '4_109.txt',
 '4_11.txt',
 '4_110.txt',
 '4_111.txt',
 '4_112.txt',
 '4_113.txt',
 '4_114.txt',
 '4_115.txt',
 '4_116.txt',
 '4_117.txt',
 '4_118.txt',
 '4_119.txt',
 '4_12.txt',
 '4_120.txt',
 '4_121.txt',
 '4_122.txt',
 '4_123.txt',
 '4_124.txt',
 '4_125.txt',
 '4_126.txt',
 '4_127.txt',
 '4_128.txt',
 '4_129.txt',
 '4_13.txt',
 '4_130.txt',
 '4_131.txt',
 '4_132.txt',
 '4_133.txt',
 '4_134.txt',
 '4_135.txt',
 '4_136.txt',
 '4_137.txt',
 '4_138.txt',
 '4_139.txt',
 '4_14.txt',
 '4_140.txt',
 '4_141.txt',
 '4_142.txt',
 '4_143.txt',
 '4_144.txt',
 '4_145.txt',
 '4_146.txt',
 '4_147.txt',
 '4_148.txt',
 '4_149.txt',
 '4_15.txt',
 '4_150.txt',
 '4_151.txt',
 '4_152.txt',
 '4_153.txt',
 '4_154.txt',
 '4_155.txt',
 '4_156.txt',
 '4_157.txt',
 '4_158.txt',
 '4_159.txt',
 '4_16.txt',
 '4_160.txt',
 '4_161.txt',
 '4_162.txt',
 '4_163.txt',
 '4_164.txt',
 '4_165.txt',
 '4_166.txt',
 '4_167.txt',
 '4_168.txt',
 '4_169.txt',
 '4_17.txt',
 '4_170.txt',
 '4_171.txt',
 '4_172.txt',
 '4_173.txt',
 '4_174.txt',
 '4_175.txt',
 '4_176.txt',
 '4_177.txt',
 '4_178.txt',
 '4_179.txt',
 '4_18.txt',
 '4_180.txt',
 '4_181.txt',
 '4_182.txt',
 '4_183.txt',
 '4_184.txt',
 '4_185.txt',
 '4_19.txt',
 '4_2.txt',
 '4_20.txt',
 '4_21.txt',
 '4_22.txt',
 '4_23.txt',
 '4_24.txt',
 '4_25.txt',
 '4_26.txt',
 '4_27.txt',
 '4_28.txt',
 '4_29.txt',
 '4_3.txt',
 '4_30.txt',
 '4_31.txt',
 '4_32.txt',
 '4_33.txt',
 '4_34.txt',
 '4_35.txt',
 '4_36.txt',
 '4_37.txt',
 '4_38.txt',
 '4_39.txt',
 '4_4.txt',
 '4_40.txt',
 '4_41.txt',
 '4_42.txt',
 '4_43.txt',
 '4_44.txt',
 '4_45.txt',
 '4_46.txt',
 '4_47.txt',
 '4_48.txt',
 '4_49.txt',
 '4_5.txt',
 '4_50.txt',
 '4_51.txt',
 '4_52.txt',
 '4_53.txt',
 '4_54.txt',
 '4_55.txt',
 '4_56.txt',
 '4_57.txt',
 '4_58.txt',
 '4_59.txt',
 '4_6.txt',
 '4_60.txt',
 '4_61.txt',
 '4_62.txt',
 '4_63.txt',
 '4_64.txt',
 '4_65.txt',
 '4_66.txt',
 '4_67.txt',
 '4_68.txt',
 '4_69.txt',
 '4_7.txt',
 '4_70.txt',
 '4_71.txt',
 '4_72.txt',
 '4_73.txt',
 '4_74.txt',
 '4_75.txt',
 '4_76.txt',
 '4_77.txt',
 '4_78.txt',
 '4_79.txt',
 '4_8.txt',
 '4_80.txt',
 '4_81.txt',
 '4_82.txt',
 '4_83.txt',
 '4_84.txt',
 '4_85.txt',
 '4_86.txt',
 '4_87.txt',
 '4_88.txt',
 '4_89.txt',
 '4_9.txt',
 '4_90.txt',
 '4_91.txt',
 '4_92.txt',
 '4_93.txt',
 '4_94.txt',
 '4_95.txt',
 '4_96.txt',
 '4_97.txt',
 '4_98.txt',
 '4_99.txt',
 '5_0.txt',
 '5_1.txt',
 '5_10.txt',
 '5_100.txt',
 '5_101.txt',
 '5_102.txt',
 '5_103.txt',
 '5_104.txt',
 '5_105.txt',
 '5_106.txt',
 '5_107.txt',
 '5_108.txt',
 '5_109.txt',
 '5_11.txt',
 '5_110.txt',
 '5_111.txt',
 '5_112.txt',
 '5_113.txt',
 '5_114.txt',
 '5_115.txt',
 '5_116.txt',
 '5_117.txt',
 '5_118.txt',
 '5_119.txt',
 '5_12.txt',
 '5_120.txt',
 '5_121.txt',
 '5_122.txt',
 '5_123.txt',
 '5_124.txt',
 '5_125.txt',
 '5_126.txt',
 '5_127.txt',
 ...]
str = '123'
list = ['12','23']
len(str)
3
len(list)
2
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())
0 00000000000001100000000000000000

1 00000000000011111100000000000000

2 00000000000111111111000000000000

3 00000000011111111111000000000000

4 00000001111111111111100000000000

5 00000000111111100011110000000000

6 00000001111110000001110000000000

7 00000001111110000001110000000000

8 00000011111100000001110000000000

9 00000011111100000001111000000000

10 00000011111100000000011100000000

11 00000011111100000000011100000000

12 00000011111000000000001110000000

13 00000011111000000000001110000000

14 00000001111100000000000111000000

15 00000001111100000000000111000000

16 00000001111100000000000111000000

17 00000011111000000000000111000000

18 00000011111000000000000111000000

19 00000000111100000000000011100000

20 00000000111100000000000111100000

21 00000000111100000000000111100000

22 00000000111100000000001111100000

23 00000000011110000000000111110000

24 00000000011111000000001111100000

25 00000000011111000000011111100000

26 00000000011111000000111111000000

27 00000000011111100011111111000000

28 00000000000111111111111110000000

29 00000000000111111111111100000000

30 00000000000011111111110000000000

31 00000000000000111110000000000000

********************************************************
0 00000000000001100000000000000000
1 00000000000011111100000000000000
2 00000000000111111111000000000000
3 00000000011111111111000000000000
4 00000001111111111111100000000000
5 00000000111111100011110000000000
6 00000001111110000001110000000000
7 00000001111110000001110000000000
8 00000011111100000001110000000000
9 00000011111100000001111000000000
10 00000011111100000000011100000000
11 00000011111100000000011100000000
12 00000011111000000000001110000000
13 00000011111000000000001110000000
14 00000001111100000000000111000000
15 00000001111100000000000111000000
16 00000001111100000000000111000000
17 00000011111000000000000111000000
18 00000011111000000000000111000000
19 00000000111100000000000011100000
20 00000000111100000000000111100000
21 00000000111100000000000111100000
22 00000000111100000000001111100000
23 00000000011110000000000111110000
24 00000000011111000000001111100000
25 00000000011111000000011111100000
26 00000000011111000000111111000000
27 00000000011111100011111111000000
28 00000000000111111111111110000000
29 00000000000111111111111100000000
30 00000000000011111111110000000000
31 00000000000000111110000000000000
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值