machine learning - Cross validation with KNN classifier in Matlab -


i trying extend this answer knn classifier:

load fisheriris;  % // convert species double isnum = cellfun(@isnumeric,species); result = nan(size(species)); result(isnum) = [species{isnum}];  % // crossvalidation vals = crossval(@(xtrain, ytrain, xtest, ytest)fun_knn(xtrain, ytrain, xtest, ytest), meas, result); 

the fun_knn funcion is:

function testval = fun_knn(xtrain, ytrain, xtest, ytest)     yknn = knnclassify(xtest, xtrain, ytrain);           [~,classnet] = max(yknn,[],2);     [~,classtest] = max(ytest,[],2);     [~,classtest] = find(ytest);         cp = classperf(classtest, classnet);             testval = cp.correctrate; end 

i receive error: ground truth must have @ least 2 classes.

seems problem knnclassify produces empty result.i use more modern funcitons fitcknn, dont know how can use training , task input function.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -