I am trying to plot the hyperplane of the SVM from a libsvm. My dataset has 3 features. So referring to the code here I have the following code so far.
% now plot decision area
[xi,yi, zi] = meshgrid([min(d(:,1)):0.01:max(d(:,1))], [min(d(:,2)):0.01:max(d(:,2))],[min(d(:,3)):0.01:max(d(:,3))]);
dd = [xi(:),yi(:), zi(:)];
tic; [predict_label, accuracy, decision_values] = svmpredict(zeros(size(dd,1),1), dd, model);toc
pos = find(predict_label==1);
hold on;
redcolor = [1 0.8 0.8];
bluecolor = [0.8 0.8 1];
h1 = plot3(dd(pos,1),dd(pos,2), dd(pos,3),'s','color',redcolor,'MarkerSize',2,'MarkerEdgeColor',redcolor,'MarkerFaceColor',redcolor);
pos = find(predict_label==0);
hold on;
h2 = plot3(dd(pos,1),dd(pos,2), dd(pos,3),'s','color',bluecolor,'MarkerSize',2,'MarkerEdgeColor',bluecolor,'MarkerFaceColor',bluecolor);
What I get from that is as follows:
My questions:
Am I doing anything wrong here? Why changes to the code are required to see it properly?
If there are more than 3 features, what is the recommended way to visualize the hyperplane?