KNN Alogorithm
Is there anyone have any idea with this function in Python? def test_knn(train_x, train_y, test_x, num_nn): return None def main(): # Read the data file szDatasetPath = './letter-recognition.data' # Put this file in the same place as this script listClasses = [] listAttrs = [] with open(szDatasetPath) as csvFile: csvReader = csv.reader(csvFile, delimiter=',') for row in csvReader: listClasses.append(row[0]) listAttrs.append(list(map(float, row[1:]))) # Generate the mapping from class name to integer IDs mapCls2Int = dict([(y, x) for x, y in enumerate(sorted(set(listClasses)))]) # Store the dataset with numpy array dataX = np.array(listAttrs) dataY = np.array([mapCls2Int[cls] for cls in listClasses]) # Split the dataset as the training set and test set nNumTrainingExamples = 15000 trainX = dataX[:nNumTrainingExamples, :] trainY = dataY[:nNumTrainingExamples] testX = dataX[nNumTrainingExamples:, :] testY = dataY[nNumTrainingExamples:]