I understood the first example that they have provided because they have clearly explained what happens in each line. But for the second example which is usually the one that would be used in practice the most is not explained and iam having a hard time trying to understand it :(. The following are the code lines that iam having trouble with
training = [mvnrnd([ 1 1], eye(2), 100); ...
mvnrnd([-1 -1], 2*eye(2), 100)];
group = [repmat(1,100,1); repmat(2,100,1)];
and
sample = unifrnd(-5, 5, 100, 2);
and this is the link -> http://www.mathworks.in/help/toolbox/bioinfo/ref/knnclassify.html
Could someone please explain this as this will not only be beneficial to me, but for all others as well.
The first line of the code you site constructs a training set of vectors, drawn from a multivariate normal distribution, centered around [ 1 1] and [-1 -1] respectively, with standard deviations of 1 and 1 for the sigma x and sigma y for the first class, and 2 and 2 for sigma x and sigma y for the second class. Take 100 of those vectors for each group ( or class).
Then you construct the group vector, which contains group labels: the first 100 are from class 1 (
repmat(1,100,1)is actually the same asones(100,1)) and the second 100 are from class 2 (repmat(2,100,1) == ones(100,1)*2).The second chunk of code you cite actually just generates a matrix containing 100 random data rows, all in the range [-5 , 5] having 2 dimensions (so 2 columns). This matrix gets used to test the classification on.
You might also take the habit of using the matlab help or doc function on functions you don’t know/understand.