how to do cross validation for multi svm classification ?

3 visualizaciones (últimos 30 días)
Hadeer tawfik
Hadeer tawfik el 23 de Oct. de 2016
Editada: Hadeer tawfik el 24 de Oct. de 2016
I am totally confused about how to do cross validation for this multisvm code,I have tried the crossval function but it is not working, and shows me this error
Error using crossval (line 160)
At least two inputs are needed.
Error in deteectsoilme (line 27)
CVMdl = crossval(results);
*here is the code*
srcFiles = dir('E:\sense\Soil Detection_Upload\Soil Detection_Code\all\*.jpg');
for i = 1 : length(srcFiles)
filename = strcat('E:\sense\Soil Detection_Upload\Soil Detection_Code\all\',srcFiles(i).name);
Img = imread(filename);
Img = imresize(Img,[256,256]);
%figure, imshow(Img); title('Query Image');
% Enhance Contrast
I = imadjust(Img,stretchlim(Img));
%figure, imshow(I);title('Contrast Enhanced');
% Extract Features from query image
[Feature_Vector] = Extract_FeaturesofSoilforall(I);
whos Feature_Vector
% Load Training Features
[X,T] = cataractdataset;
TrainFeat = X;
Train_Label = T;
test = Feature_Vector;
result = multisvm(TrainFeat,Train_Label,test);
%disp(result)
CVMdl = crossval(results);% Trying crossval function
%if result == 1
%helpdlg(' grade1');
%disp(' grade1 ');
%elseif result == 2
%helpdlg(' last ');
%disp('last');
%elseif result == 3
%helpdlg('normal');
%disp(' normal ');
end
% Tabulate the results using a confusion matrix.
confMat = confusionmat(Train_Label, results)
diag(confMat)
and this is the multisvm code:
function [itrfin] = multisvm( T,C,test )
%Inputs: T=Training Matrix, C=Group, test=Testing matrix
%Outputs: itrfin=Resultant class
itrind=size(test,1);
itrfin=[];
Cb=C;
Tb=T;
for tempind=1:itrind
tst=test(tempind,:);
C=Cb;
T=Tb;
u=unique(C);
N=length(u);
c4=[];
c3=[];
j=1;
k=1;
if(N>2)
itr=1;
classes=0;
cond=max(C)-min(C);
while((classes~=1)&&(itr<=length(u))&& size(C,2)>1 && cond>0)
%This while loop is the multiclass SVM Trick
c1=(C==u(itr));
newClass=c1;
%svmStruct = svmtrain(T,newClass,'kernel_function','rbf'); % I am using rbf kernel function, you must change it also
svmStruct = svmtrain(T,newClass,'kernel_function','rbf');
classes = svmclassify(svmStruct,tst);
% This is the loop for Reduction of Training Set
for i=1:size(newClass,2)
if newClass(1,i)==0;
c3(k,:)=T(i,:);
k=k+1;
end
end
T=c3;
c3=[];
k=1;
% This is the loop for reduction of group
for i=1:size(newClass,2)
if newClass(1,i)==0;
c4(1,j)=C(1,i);
j=j+1;
end
end
C=c4;
c4=[];
j=1;
cond=max(C)-min(C); % Condition for avoiding group
%to contain similar type of values
%and the reduce them to process
% This condition can select the particular value of iteration
% base on classes
if classes~=1
itr=itr+1;
end
end
end
valt=Cb==u(itr); % This logic is used to allow classification
val=Cb(valt==1); % of multiple rows testing matrix
val=unique(val);
itrfin(tempind,:)=val;
end
end
any help please? or suggestions

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by