ISML Machine Learning, Class 6 Lab - 
Local methods & Bias
-Variance Trade-Off


This lab is about local methods for binary classification on synthetic data. The goal of the lab is to get familiar with the k-Nearest Neighbors (kNN) algorithm and to get a practical grasp of what we have discussed in class. Follow the instructions below. Think hard before you call the instructors!

Extract the zip file in a folder and set the Matlab path to that folder.

0. Generate Data

1. Core - kNN classifier

The k-Nearest Neighbors algorithm (kNN) assigns to a test point the most frequent label of its k closest examples in the training set.

figure;

scatter(Xte(:,1),Xte(:,2),25,Yte); %plot test points (empty circles) associating a different color to each "true" label

hold on

sel = (Ypred ~= Yte);

scatter(Xte(sel,1),Xte(sel,2),200,Yte(sel),'x'); % plot wrongly predicted test points (filled circles)



Matlab line: sum(Ypred~=Yte)/Nt %Nt number of test data points

2. Parameter selection - What is a good value for k?

So far, we have considered an arbitrary k.

3. If you have time - More experiments