problem in plottin kernel svm inplementation

Hi,
I am implementing the Kernel SVM for a non-linear separable data set. I have implemented the algorithm for 4 points to see the results and then generalize for a larger data set. When I plot the results, I can see the surfaces separating the data sets but for a larger data set it does not give proper results, so I am not sure if I am plotting in the right way. Could someone please let me know how to plot the results.
Thanks in advance, Sharmi
I have added the Kernel SVM code below
% kernel function g = @(x,y) (x*y'+1).^2; X_data = cat(1,data_set(1:N1,1:2),-data_set(N1+1:N1+N2,1:2)); y = cat(1,data_set(1:N1,3),data_set(N1+1:N1+N2,3)); H = (y*y').*g(X_data,X_data); f=-ones(N1+N2,1); Aeq=y'; beq=0; lb=zeros(N1+N2,1); ub=C*ones(N1+N2,1); lambda=quadprog(H,f,[],[],Aeq,beq,lb,ub);
lambda(floor(10000*abs(lambda))==0)=0; s =g(X_data,X_data);
% weight vector w = g(data_set,data_set)*(y.*lambda); q=find(lambda>0 & lambda<C-.000001);
x_min=-1+floor(min(abs(g(data_set,data_set)))); x_max=1+ceil(max(abs(g(data_set,data_set)))); y_min=-1+floor(min(abs(data_set(:,2)))); y_max=1+ceil(max(abs(data_set(:,2))));
xi=x_min:x_max; for i=1:N1+N2 yi=(y.*lambda)*g(data_set(i,:),data_set); end
xi= xi(1:size(yi));
axis equal figure plot(xi,yi,'k') figure mesh(yi);
data_set is the 2D non-linearly separable random data set which is augmented for each class and normalized for the second class.

2 comentarios

Shashank Prasanna
Shashank Prasanna el 11 de Mzo. de 2013
Could you shed more light on "does not give proper results"? Do you get an error message? What seems to be the issue?
rini
rini el 12 de Mzo. de 2013
I want to plot my data set along with the results of Kernel svm in the same figure. However, with this code, if I try to plot the data and the hyper-planes, I get an error that vectors should be of same length. I want to know if I could show the hyper-planes separating the non-linear data set. Other than this, I am not getting any error in the code
Thanks

Respuestas (0)

La pregunta está cerrada.

Preguntada:

el 11 de Mzo. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by