Home How to plot boundary line of binary classification algorithm
Reply: 0

# How to plot boundary line of binary classification algorithm

Daniel.V
1#
Daniel.V Published in 2017-12-07 13:18:27Z
 I was trying to implement a binary classification in Matlab using loss function which weights can be calculated from this after I calculate weights in matlab I wanted to draw boundry line which seperate my two inputs classess, however the result line doesn't seems to be correct here is my matlab code: clear; clc; close all; %number of test cases data_size = 10; features = 2; [x1,x2] = ginput(data_size); y = zeros(data_size,0); % I assumed first 5 inputs are one class and the others are in the other class for i=1:data_size if i <= 5 y(i) = 1; else y(i) =-1; end end x = x1; x(1:data_size,3) = 1; x(1:data_size,2) = x2; first_sigma = y(1) * x(1,:); for i=2:data_size first_sigma = first_sigma + (y(i) * x(i,:)); end second_sigma = transpose(x(1,:)) * x(1,:); for i=2:data_size second_sigma = second_sigma + transpose(x(1,:)) * x(1,:); end weight = first_sigma/second_sigma; slope = -(weight(3)/weight(2))/(weight(3)/weight(1)); intercept = -weight(3)/weight(2); new_x = 0.1:0.01:1; new_y = new_x*slope + intercept; figure scatter(x1,x2,25,y,'filled'); hold on plot(new_x,new_y); hold off  I am wondering where is the problem here I checked my code with formula and all seems to be correct however ploted line is wrong
 You need to login account before you can post.
Processed in 0.511758 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO