0

I am using:

SvmModel= fitcsvm(X,Y);

to build an SVM model and I want to plot the resulting hyper plane in 2D. I am having trouble understanding the structure of the results I am getting. For x with 30 features over 455 samples (~80% breast cancer dataset) I was expecting a 30 by w vector plus a 1 by 1 b vector. I can only find the SVMModel.W variable which is 455 by 1.

I am trying to plot the output on a 2D space using pca in the wollowing way:

[coeff, score, ~, ~, ~, mu]=pca(X);
gscatter(score(:,1),score(:,2),Y,'br','.');
hold on; 

plot(score(SvmModel.IsSupportVector,1),...
score(SvmModel.IsSupportVector,2),'go');
%project and plot hyper plane
hold off;

In the commented line I want to project and plot the hyper plane.I have seen this answer for the 2D case, as well as, this answer for the 3D case. My problem has 30D and needs to be projected into 2D.

  • How do I make scence of the output?
  • How do I project the results on a 2D plain using 2 first PCA components?
havakok
  • 1,185
  • 2
  • 13
  • 45
  • 1
    Assuming `fitcsvm` returns a [ClassificationSVM](https://www.mathworks.com/help/stats/classificationsvm-class.html#bt63jyz-4) object (see [documentation](https://www.mathworks.com/help/stats/fitcsvm.html?searchHighlight=fitcsvm&s_tid=doc_srchtitle#outputarg_Mdl) for when this is the case), then the terms you are interested in are `SvmModel.Beta`, `SvmModel.Bias`, and `SvmModel.KernelParameters.Scale` where the hyperplane is defined by `f(x) = (x/Scale)'*Beta + Bias = 0` – jodag Jan 13 '18 at 18:21
  • As far as visualizing the decision boundary that's a problem. The projected plane almost certainly spans the entirety of the 2D space, i.e. the projection of the plane into 2D space is the entire 2D space. We get around this for 3D by doing things like drawing axes, plotting a subset of the plane, applying texture to the plot, etc... but these strategies don't meaningfully extend to high dimensional visualizations. – jodag Jan 13 '18 at 18:32

0 Answers0