fisher isis, train a knn classifier. Create trainning and test set.

Hello. I want to train a Knn classifier (k=1, k=3, k=5) for fisher iris data. I want randomly to take the 120 of 150 for training set and the rest for testing. But randomly each time. I wrote this code
load fisheriris
randSamples = meas(randperm(size(meas, 1)), :);
trainingSet = randSamples((1:120), :);
testSet = randSamples((121:150), :);
But for fisher iris, the vector with the species should be change in the same way? how can i do this? in the command
dl = fitcknn(meas,species,'NumNeighbors',5,'Standardize',1);
i need 2 vectors with same count of rows. Any further help about knn would be useful. thanks in advance

Answers (1)

The Fisher iris example is actually in the documentation for fitcknn.
I can’t improve on the documentation example!

Asked:

on 15 Jan 2016

Answered:

on 15 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!