def processData(): dataLoader.loadTrainingSets(testIndex=-1, fast=False, sampleSize=150, dt_type=config.dataset_type.mnist_hw) dataLoader.loadTestSets(dt_type=config.dataset_type.mnist_hw) data = { 'train': { 'img': shd.TrainingDataSet.imagesDataSet, 'lbl': shd.TrainingDataSet.labelsDataSet }, 'test': { 'img': shd.TestSetData.imagesDataSet, 'lbl': shd.TestSetData.labelsDataSet } } shd.TrainingDataSet.imagesDataSet = None shd.TrainingDataSet.labelsDataSet = None shd.TestSetData.imagesDataSet = None shd.TestSetData.labelsDataSet = None return data
def loadData(): dataLoader.loadTrainingSets(testIndex=-1, fast=False, sampleSize=5000, dt_type=config.dataset_type.mnist_hw) dataLoader.loadTestSets(dt_type=config.dataset_type.mnist_hw)
sharedData.KNN_Results_5.resultByIndex[testLabel] = rslArr else: rslArr[predictedLabel_3] += 1 def findNearestNeighbors(inputVector): distanceDic = defaultdict(list) for i in range(len(sharedData.TrainingDataSet.imagesDataSet)): distance = mh.calculateDistance(inputVector, sharedData.TrainingDataSet.imagesDataSet[i]) distanceDic[distance] = sharedData.TrainingDataSet.labelsDataSet[i] # who care if distance for two or more is equal? return distanceDic dataLoader.loadTrainingSets(testIndex=-1, fast=False, sampleSize=100) dataLoader.loadTestSets() k_array = [1, 3, 5] for i in tqdm(range(len(sharedData.TestSetData.imagesDataSet))): testVector = sharedData.TestSetData.imagesDataSet[i] testLabel = sharedData.TestSetData.labelsDataSet[i] distanceDic = findNearestNeighbors(inputVector=testVector) calculateResults(testLabel=testLabel, resultDic=distanceDic) print('----1NN--------') i =0 for key in sorted(sharedData.KNN_Results_1.resultByIndex):
def load_data(): dataLoader.loadTrainingSets(testIndex=-1, fast=True, sampleSize=100, dt_type=config.dataset_type.mnist_fashion) dataLoader.loadTestSets(dt_type=config.dataset_type.mnist_fashion)