fitcsvm decision boundary equation

145 ビュー (過去 30 日間)
Shaybe 2019 年 2 月 17 日
編集済み: Brendan Hamm 2019 年 3 月 11 日
I have trained a linear SVM on 2D data and can't seem to get the line equation describing the decision boundary.
Here is some code that fails miserably.
Y=logical([1 0 0 0 0]);
gscatter(X(:,1),X(:,2),Y); hold on;
Would appreciate help!
  1 件のコメント
Brendan Hamm
Brendan Hamm 2019 年 3 月 11 日
It seems to me the reason why this fails is you are trying to train a model with only 5 points. Stop and think, how do you make a support vector with only one data point for the True class? An infinite number of ways should be your answer.
One other issue you seem to have is in the orientation of your data. X is a 5-by-2 and Y is 1-by-5. So, you should transpose your response. No that this solves the above problem.
Y=logical([1 0 0 0 0])';
Otherwise what you have for the plotting seems fine.


回答 (1 件)

Brendan Hamm
Brendan Hamm 2019 年 3 月 11 日
編集済み: Brendan Hamm 2019 年 3 月 11 日
Generate some data for the classes
n = 100;
X = [2 + 0.5*randn(n,2);...
3 + 0.6*randn(n,2)];
Y = [zeros(n,1);ones(n,1)];
Fit a model
mdl = fitcsvm(X,Y);
Make a plot showing the decision boundary
Begin by making a grid of values
x = linspace(0,5);
y = linspace(0,5);
[XX,YY] = meshgrid(x,y);
Stack the values into an m-by-2 matrix
pred = [XX(:),YY(:)];
p = predict(mdl,pred);
Look at a scatter of the predictions
Define the boundary function, note that:
f = @(x) -(x*mdl.Beta(1) + mdl.Bias)/mdl.Beta(2);
y = f(x);
hold on
hold off
On the original data
hold on
hold off
More generally for ECOC you might consider the code in this example:

Community Treasure Hunt

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

Start Hunting!

Translated by