Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1.

b)
% Generate Data Set

rng(1);

full_data = [];

xrange = 5;

for i = 1:50

x1 = xrange * rand(1,1);

x2 = xrange * rand(1,1);

if x2 >= 0.6 * (x1-1)*(x1-2)*(x1-4) + 3

x2 = x2 + 0.25;

z = 1;

else

x2 = x2 - 0.25;

z = 0;

end

full_data = [full_data ; [x1 x2 z]];

end

% Split the dataset into Training set and Test Set

data_Train = full_data(1:40,:);

data_Test = full_data(40:50,:);

figure(1);

plotpv([full_data(:,1)'; full_data(:,2)'],full_data(:,3)');

axis([-1 6 -1 6]);
set(gcf, 'Position', [100, 100, 750, 350]);
% Initialize Input Vector with Training Dataset

pList = [data_Train(:,1)'; data_Train(:,2)'];

tList = data_Train(:,3)';

mdl = fitcsvm([data_Train(:,1) data_Train(:,2)],tList)


pred = predict(mdl,[data_Train(:,1) data_Train(:,2)]);
figure(2);

plotpv(pList,tList);
hold on;
plot(mdl.SupportVectors);

You might also like