Length of label vector does not match # of instances.
조회 수: 4 (최근 30일)
이전 댓글 표시
Length of label vector does not match # of instances. Error using reshape To RESHAPE the number of elements must not change.
Error in linear_kernel (line 48) ypred = reshape(ypred,nx,ny);
% 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;
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!