jeudi 20 avril 2017

MATLAB Error using seqminopt>seqminoptImpl: svm doesn't work after randperm

I have these errors:

Error using seqminopt>seqminoptImpl (line 198)
No convergence achieved within maximum number of iterations.

Error in seqminopt (line 81)
[alphas offset] = seqminoptImpl(data, targetLabels, ...

Error in svmtrain (line 499)
    [alpha, bias] = seqminopt(training, groupIndex, ...

Error in checkConfusionMatrix2 (line 64)
        SVMStructCM1 = svmtrain(outfeatureMatrixRnd([l2:max],:),outsexbRnd([l2:max])); %1)

This is my code:

max = 10000;

kfold=10;

VetY = zeros(max,1);
VectX = zeros(1,max);

step = max/kfold;

rng(1);
size(featureMatrix)
size(sexb)



featureMatrix(1:10)

OrgSizeFeatureMatrix = size(featureMatrix);
featureMatrixRnd = randperm(numel(featureMatrix))';
outfeatureMatrixRnd = reshape(featureMatrix(featureMatrixRnd),OrgSizeFeatureMatrix);




OrgSizeSexb = size(sexb);
sexbRnd = randperm(numel(sexb));
outsexbRnd = reshape(sexb(sexbRnd),OrgSizeSexb);

outfeatureMatrixRnd(1:10)
outsexbRnd(1:10)
sexb(1:10)


size(outfeatureMatrixRnd)
size(outsexbRnd)

for k=1:step:max
    
    l1 = k-step+1;
    l2 = k+step;
    
    if(l1<0 && l2<max)
        SVMStructCM1 = svmtrain(outfeatureMatrixRnd([l2:max],:),outsexbRnd([l2:max])); %1)
    elseif(l2<max)
        SVMStructCM1 = svmtrain(outfeatureMatrixRnd([1:l1,l2:max],:),outsexbRnd([1:l1,l2:max])); %1)
    else
        SVMStructCM1 = svmtrain(outfeatureMatrixRnd([1:l1],:),outsexbRnd([1:l1])); %1)  
    end
   

    
  
    
    for(i=k:l2-1)
        VetY(i,1) = outsexbRnd([i]);
        VetX(1,i) = svmclassify(SVMStructCM1,outfeatureMatrixRnd(i,:));
    end
   
    %sexbcm1(kk,:) =  sexb(k:k+step-1); %3)

  
end

[C,order] = confusionmat(VetX,VetY)

accuracy = sum(diag(C))/sum(sum(C)) %accuracy of the result
SVMStructCM1 = svmtrain(outfeatureMatrixRnd([l2:max],:),outsexbRnd([l2:max])); %1)

outfeatureMatrixRnd is featureMatrix shuffled, the same with outsexRnd. I tried to look if size(featureMatrixMatrixRnd) is the same of size(featureMatrix), and it's the same. It's strange because using "featureMatrix" it works good, but using outfeatureMatrixRnd and outsexbRnd it show me this error. Why? How can I fix it?




Aucun commentaire:

Enregistrer un commentaire