Write your own Nearest-neighbor classifier

We have begun to write a nearest neighbor classifier, but we have left out the best part. Write the for loop that iterates over every sample in the testing data and assigns a single label from the training targets to each of the test samples based on which is nearest (where ‘nearest’, for now, is defined based on Euclidean distance). Test your classifiers on pairwise or multi-class datasets.

Your function should have the following signature:

function predicted = cosmo_classify_nn(samples_train, targets_train, samples_test, unused)

Hint: cosmo classify nn skl

Full solution: cosmo classify nn

Extra exercise: write a nearest-mean classifier.

Extra exercise: Try correlation instead of Euclidean distance.

Advanced exercise: write a k-nearest neighbor classifier that considers the nearest k neighbors for each test sample. Bonus points if this classifier uses cosmo winner indices in case of a tie. (solution: cosmo classify knn).

Matlab output: run_classify_naive_bayes