matlab - Chance level accuracy for clearly separable data -


i have written believe quite simple svm-classifier [svm = support vector machine]. "testing" distributed data different parameters, classifier returning me 50% accuracy. wrong?

here code, results should reproducible:

features1 = normrnd(1,5,[100,5]); features2 = normrnd(50,5,[100,5]); features = [features1;features2]; labels = [zeros(100,1);ones(100,1)];  %% svm-classification nrfolds = 10; %number of folds of crossvalidation kernel = 'linear'; % 'linear', 'rbf' or 'polynomial' c = 1; % c 'boxconstraint' parameter.   cvfolds = crossvalind('kfold', labels, nrfolds);   = 1:nrfolds                            % iterate through each fold     testidx = (cvfolds == i);                % indices test instances     trainidx = ~testidx;                     % indices training instances      % train svm     cl = fitcsvm(features(trainidx,:), labels(trainidx),'kernelfunction',kernel,'standardize',true,...     'boxconstraint',c,'classnames',[0,1]);      [label,scores] =  predict(cl, features(testidx,:));     eq = sum(labels(testidx));     accuracy(i) = eq/numel(labels(testidx));  end  crossvalacc = mean(accuracy) 

you not computing accuracy correctly. need determine how many predictions match original data. summing total number of 1s in test set, not actual number of correct predictions.

therefore must change eq statement this:

eq = sum(labels(testidx) == label); 

recall labels(testidx) extracts true label test set , label predicted results svm model. correctly generates vector of 0/1 0 means prediction not match actual label test set , 1 means agree. summing on each time agree, or each time vector 1 way compute accuracy.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -