I need some help to classify a test image to belong to the correct person.

I am using PCA with a SVM classifier to classify the image.

I have 40 subjects, each with 5 features (= total of 200 images).

I therefore have the "train_label" matrix as [1;1;1;1;1;2;2;2;2;2;3;3;3;3;3;4;4;4;4;4;5...40;40;40;40;40]

  1. I got the projected images down to a 200 x 200 matrix using the PCA analysis - "projectimg".

  2. I then used the following command to "Train" the SVM classifier:

    SVMModel = fitrsvm(projectimg', train_label,'Standardize',true,'KernelFunction','RBF',... 'KernelScale','auto');

  3. I then generated the projected test image, - "projtestimg".

I now wanted to classify this test image, so I use the following command:

[label] = predict(SVMModel,projtestimg');

I always get the wrong value for the label, meaning that the label value never correlates to the correct subject. I think that I am implementing the classify part incorrectly.

Can you please tell me how to correctly predict the class of the test image after the PCA analysis using the SVM method in Matlab? Thanks!


1 Answer 1


I don't follow your PCA pipeline, but you are using fitrsvm, which is meant for regression problems for a multi-class classification problem. Won't work.

fitcsvm implements svm classification but it doesn't handle multiclass classification. try fitcecoc, which warps binary svm classifiers by a multiclass error-correcting output codes classifier or even fitcnb for naive Gaussian bayes. For mutli-class SVM extensions, you'll have to look outside of Mathworks' toolboxes.

  • $\begingroup$ Hello, when I tried your suggestion of fitcecoc, I got a success rate of 82.5%. This is worse than the KNN algorithm that I implemented. Can you possibly tell me why this would be the case? $\endgroup$
    – Joe
    Nov 21, 2016 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.