SVM classifier on digits dataset

5 次查看(过去 30 天)
verbose193
verbose193 2019-12-14
编辑: Ridwan Alam 2019-12-14
Hi,
I have to use SVM classifier on digits dataset. The dataset consists of images of digits 28x28 and a toal of 2000 images.
I tried to use svmtrain but the matlab gave an error that svmtrain has been removed. so now i am using fitcsvm.
My code is as below:
labelData = zeros(2000,1);
for i=1:1000
labelData(i,1)=1;
end
for j=1001:2000
labelData(j,1)=1;
end
SVMStruct =fitcsvm(trainingData,labelData)
%where training data is the set of images of digits.
I need to know how i can predict the outputs of test data using svm? Further is my code correct?

回答(1 个)

Ridwan Alam
Ridwan Alam 2019-12-14
编辑:Ridwan Alam 2019-12-14
fitcsvm() is not designed to train directly on 28x28 images. You need to extract feature vectors for each image. After feature extraction, you will have a dataset with size 2000xN, where N is the number of features for each image. Let's say X is this new extracted feature set of size 2000xN, and Y is your labeledData of size 2000x1.
Now, before training fitcsvm(), you need to use cvpartition() (or something similar, maybe your custom method) to divide both the features and the labels data into training and testing dataset. Then, you can use
SVMStruct =fitcsvm(trainingData,trainingLabelData)
As far as I know, you can use Convolutional Neural Networks (CNN) to train directly on images.
Minor issues with your code:
  1. in both loops, you are assigning the labelData the same value.
  2. you don't really need those loops: labelData(1:1000) = 0; labelData(1001:2000) = 1;
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by