[ypred,accuracy1,decision_values1] = svmpredict(LabelS1',Xg,model);
Length of label vector does not match # of instances

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% load training set and testing set
clear all;
train_set   = loadMNISTImages('train-images.idx3-ubyte')';
train_label = loadMNISTLabels('train-labels.idx1-ubyte');
test_set    = loadMNISTImages('t10k-images.idx3-ubyte')';
test_label  = loadMNISTLabels('t10k-labels.idx1-ubyte');
%training
tic; 
model = svmtrain(train_label, train_set, '-s 0 -t 0');
t1 = toc;
% classification
tic;
[predicted_label, accuracy, decision_values]=svmpredict(test_label, test_set, model);
t2 = toc;
disp(num2str(t1));
disp(num2str(t2));
%%%%%%%%%%%%%%%%%%plot%%%%%%%%%%%%%
train_set1=train_set;
test_set1=test_set;
nt=220.6940;
m=521.0442;
[Pa,V,me1,l1] = pcaproj(train_set1,2);
[n,p]=size(test_set1);
Pt=(test_set1-ones(n,1)*me1)*V;
min(Pa);
max(Pa);
min(Pt);
max(Pt);
m1 = -1;
 M1 = 2.5;
 m2 = -1.5;
 M2 = 1;
 ind1 = 0.25;
 ind2 = 0.25;
[xg yg]  = meshgrid([m1:ind1:M1],[m2:ind2:M2]); 
[nx,ny] = size(xg); 
X = [reshape(xg ,nx*ny,1) reshape(yg ,nx*ny,1)]; 
[n,p] = size(X);
Xg = X*V' + ones(n,1)*me1;
LabelS1=[1*ones(1,3334) 2*ones(1,3333) 3*ones(1,3333)];
[ypred,accuracy1,decision_values1] = svmpredict(LabelS1',Xg,model);
decision_values1=decision_values1';
maxi=max(decision_values1);
ypred = reshape(ypred,nx,ny); 
contourf(xg,yg,ypred);shading flat;hold on;
[cs,h]=contour(xg,yg,ypred,[1 2 3]);
clabel(cs,h); 
style= ['^+*'];
color= ['kkk']; 
hold on;
nbclass=max(LS);
for i=0:nbclass-1
     h=plot(Pt(i*nt+1:(i+1)*nt,1),Pt(i*nt+1:(i+1)*nt,2),[style(i+1) color(i+1)]);hold on;
end;