def runTestKNNClassifier(self, short = <NUM_LIT:0>):
failures = "<STR_LIT>"<EOL>if short != <NUM_LIT:2>:<EOL><INDENT>numpy.random.seed(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>seed_value = int(time.time())<EOL>numpy.random.seed(seed_value)<EOL>LOGGER.info('<STR_LIT>', seed_value)<EOL>f = open('<STR_LIT>', '<STR_LIT:a>')<EOL>f.write(str(seed_value))<EOL>f.write('<STR_LIT:\n>')<EOL>f.close()<EOL><DEDENT>failures += simulateKMoreThanOne()<EOL>LOGGER.info("<STR_LIT>")<EOL>numPatterns, numClasses = getNumTestPatterns(short)<EOL>patternSize = <NUM_LIT:100><EOL>patterns = numpy.random.rand(numPatterns, patternSize)<EOL>patternDict = dict()<EOL>testDict = dict()<EOL>for i in xrange(numPatterns):<EOL><INDENT>patternDict[i] = dict()<EOL>patternDict[i]['<STR_LIT>'] = patterns[i]<EOL>patternDict[i]['<STR_LIT>'] = numpy.random.randint(<NUM_LIT:0>, numClasses-<NUM_LIT:1>)<EOL>testDict[i] = copy.deepcopy(patternDict[i])<EOL>testDict[i]['<STR_LIT>'][:int(<NUM_LIT>*patternSize)] = numpy.random.rand()<EOL>testDict[i]['<STR_LIT>'] = None<EOL><DEDENT>LOGGER.info("<STR_LIT>")<EOL>knn = KNNClassifier(k=<NUM_LIT:1>)<EOL>failures += simulateClassifier(knn, patternDict,"<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>")<EOL>knnL1 = KNNClassifier(k=<NUM_LIT:1>, distanceNorm=<NUM_LIT:1.0>)<EOL>failures += simulateClassifier(knnL1, patternDict,"<STR_LIT>")<EOL>LOGGER.info("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>knnExact = KNNClassifier(k=<NUM_LIT:1>, exact=True)<EOL>failures += simulateClassifier(knnExact,<EOL>patternDict,<EOL>"<STR_LIT>",<EOL>testDict=testDict)<EOL>numPatterns, numClasses = getNumTestPatterns(short)<EOL>patterns = (numpy.random.rand(numPatterns, <NUM_LIT>) > <NUM_LIT>).astype(RealNumpyDType)<EOL>patternDict = dict()<EOL>for i in patterns:<EOL><INDENT>iString = str(i.tolist())<EOL>if not patternDict.has_key(iString):<EOL><INDENT>randCategory = numpy.random.randint(<NUM_LIT:0>, numClasses-<NUM_LIT:1>)<EOL>patternDict[iString] = dict()<EOL>patternDict[iString]['<STR_LIT>'] = i<EOL>patternDict[iString]['<STR_LIT>'] = randCategory<EOL><DEDENT><DEDENT>LOGGER.info("<STR_LIT>")<EOL>knnDense = KNNClassifier(k=<NUM_LIT:1>)<EOL>failures += simulateClassifier(knnDense, patternDict,"<STR_LIT>")<EOL>self.assertEqual(len(failures), <NUM_LIT:0>,<EOL>"<STR_LIT>" + failures)<EOL>if short == <NUM_LIT:2>:<EOL><INDENT>f = open('<STR_LIT>', '<STR_LIT:a>')<EOL>f.write('<STR_LIT>')<EOL>f.close()<EOL><DEDENT>
Test the KNN classifier in this module. short can be:
            0 (short), 1 (medium), or 2 (long)