决定边界分离3类(渔夫虹膜数据集)

时间:2016-01-31 14:57:15

标签: matlab svm least-squares perceptron

我编写了一个代码,我已经创建了一个LS-SVM和一个单层感知器分类器。我想做的,但我不知道如何绘制一个分隔我的类的决策边界。我必须澄清一下,我正在研究有3个类的Fisher虹膜数据集,因此它是一个多类分类问题。

我的代码:

% Least Squares
train_label2={zeros(40,1),ones(40,1),2*ones(40,1)};
train_cell2={meas(1:40,3:4),meas(51:90,3:4),meas(101:140,3:4)};
[svmstruct2,level2] = Train_DSVM(train_cell2,train_label2);
label2=[0 1 2];
test_mat2=[meas(41:50,3:4);meas(91:100,3:4);meas(141:150,3:4)];
[Class_test2] = Classify_DSVM(test_mat2,label2,svmstruct2,level2);
labels2=[zeros(1,10),ones(1,10),2*ones(1,10)];
[Cmat2,DA2]= confusion_matrix(Class_test2,labels2,{'A','B','C'});

fprintf('Program paused. Press enter to continue.\n');
pause

% Perceptron

t1 = randperm(50);
X1a = meas(t1(1:35),3:4);
t2 = randperm(100);
X2a = meas(50 + t2(1:35),3:4);
clear t1 t2;
Xa = [X1a X2a];
Ya = [-ones(1,35) ones(1,35)];
wa = rand(35,1);
wtaga = perceptron(Xa,Ya,wa); % call perceptron
ytaga = wtaga'*Xa; % predict
Yauxa = sign(wtaga'*Xa);

t1 = randperm(50);
X1b = meas(50+t1(1:35),3:4);
t2 = randperm(100);
X2b = meas(t2(1:35),3:4);
clear t1 t2;
Xb = [X1b X2b];
Yb = [-ones(1,35) ones(1,35)];
wb = rand(35,1);
wtagb = perceptron(Xb,Yb,wb); % call perceptron
ytagb = wtagb'*Xb; % predict
Yauxb = sign(wtagb'*Xb);

t1 = randperm(50);
X1c = meas(t1(1:35),3:4);
t2 = randperm(100);
X2c = meas(50 + t2(1:35),3:4);
clear t1 t2;
Xc = [X1c X2c];
Yc = [-ones(1,35) ones(1,35)];
wc = rand(35,1);
wtagc = perceptron(Xc,Yc,wc); % call perceptron
ytagc = wtagc'*Xc; % predict
Yauxc = sign(wtagc'*Xc);

%% Plotting

% Class A('Setosa')
figure;
hold on;


plot(X1a(1,:),X1a(2,:),'b.');
plot(X2a(1,:),X2a(2,:),'r.');

plot(Xa(1,ytaga<0),Xa(2,ytaga<0),'bo');
plot(Xa(1,ytaga>0),Xa(2,ytaga>0),'ro');

% plotpv(Xa(1:2,:),logical(Ya));

legend('class +1','class -1','pred +1','pred -1');
title('Setosa');

% Class B('Versicolor')

figure;
hold on;

plot(X1b(1,:),X1b(2,:),'b.');
plot(X2b(1,:),X2b(2,:),'r.');

plot(Xb(1,ytaga<0),Xb(2,ytaga<0),'bo');
plot(Xb(1,ytaga>0),Xb(2,ytaga>0),'ro');

legend('class +1','class -1','pred +1','pred -1');
title('Versicolor');

% Class C('Virginica')

figure;
hold on;

plot(X1c(1,:),X1c(2,:),'b.');
plot(X2c(1,:),X2c(2,:),'r.');

plot(Xc(1,ytaga<0),Xc(2,ytaga<0),'bo');
plot(Xc(1,ytaga>0),Xc(2,ytaga>0),'ro');

legend('class +1','class -1','pred +1','pred -1');
title('Virginica');

% ----Alltogether----

figure;
hold on;


plot(X1a(1,:),X1a(2,:),'b.');
plot(X2a(1,:),X2a(2,:),'r.');

plot(Xa(1,ytaga<0),Xa(2,ytaga<0),'bo');
plot(Xa(1,ytaga>0),Xa(2,ytaga>0),'ro');

plot(X1b(1,:),X1b(2,:),'b.');
plot(X2b(1,:),X2b(2,:),'r.');

plot(Xb(1,ytaga<0),Xb(2,ytaga<0),'bo');
plot(Xb(1,ytaga>0),Xb(2,ytaga>0),'ro');

plot(X1c(1,:),X1c(2,:),'b.');
plot(X2c(1,:),X2c(2,:),'r.');

plot(Xc(1,ytaga<0),Xc(2,ytaga<0),'bo');
plot(Xc(1,ytaga>0),Xc(2,ytaga>0),'ro');

legend('class +1','class -1','pred +1','pred -1');
title('All classes');

有人可以帮我完成任务吗?

我真的很感激!

0 个答案:

没有答案