For helping Image processing & multiSVM & fitcsvm Error

2 次查看(过去 30 天)
Hi
i'm working on a university project and i'm doing image processing.
So when i researching on google for my project content, i found some codes and tried but matlab gives an error.
This is the code I found to use multisvm but I want to ask you because I couldn't find clear explanatory information about this subject.
Here is the error
****************
Error using ClassificationSVM.prepareData (line 630)
Invalid data type. X must be a double or single matrix.
Error in classreg.learning.FitTemplate/fit (line 218)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationSVM.fit (line 240)
this = fit(temp,X,Y);
Error in fitcsvm (line 343)
obj = ClassificationSVM.fit(X,Y,RemainingArgs{:});
Error in multisvm (line 29)
classes = predict(fitcsvm(svmStruct,tst,'KernelFunction','rbf'));
Error in mainproject (line 76)
result = multisvm(dataset,diseasetype,feature);
****************
As far as I understand the main cause of the error
svmStruct = fitcsvm(T,newClass);
classes = predict(fitcsvm(svmStruct,tst,'KernelFunction','rbf'));
Here is the code that i use
function [itrfin] = multisvm( T,C,test )
%Inputs: T=Training Matrix, C=Group, test=Testing matrix
%Outputs: itrfin=Resultant class
%C=str2num(cell2mat(C));
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 = fitcsvm(T,newClass,'kernel_function','rbf'); % I am using rbf kernel function, you must change it also
svmStruct = fitcsvm(T,newClass);
classes = predict(fitcsvm(svmStruct,tst,'KernelFunction','rbf'));
% 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
% Give more suggestions for improving the program.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by