def handwritingClassTest():
    hwLabels = []
    # trainingFileList = os.listdir('trainingdigit/trainingset')
    trainingFileList = listDirInMac('trainingdigit/trainingdigits-for-knn')
    m = len(trainingFileList)
    trainingMat = zeros((m, 1024))
    for i in range(m):
        fnameStr = trainingFileList[i]
        classStr = fnameStr.split("_")[0]
        hwLabels.append(classStr)
        trainingMat[i, :] = img2vector('trainingdigit/trainingdigits-for-knn/%s' % fnameStr)
    # testFileList = os.listdir('trainingdigit/testdigits')
    testFileList = listDirInMac('trainingdigit/testdigits-for-knn')
    errorCount = 0.0
    mTest = len(testFileList)
    for i in range(mTest):
        fnameStr = testFileList[i]
        classStr = fnameStr.split('_')[0]
        vTest = img2vector('trainingdigit/testdigits/%s' % fnameStr)
        classifierResult = classify0(vTest, trainingMat, hwLabels, 3)
        print "classifier result: %s, the real answer:%s" % (classifierResult, classStr),
        if (classifierResult != classStr):
            errorCount += 1.0
            print "wrong"
        else:
            print "correct"
    print "error number: %d" % errorCount
    print "error rate: %f" % (float(mTest) / errorCount)


# kNN algorithm
dataset/ETHPy150Open Yaoshicn/decaptcha/KNN-recognize.py/handwritingClassTest/swapped operands of `/`