Filter löschen
Filter löschen

How to draw hyperplane using 'fitcsvm'

8 Ansichten (letzte 30 Tage)
Takashi KOSHIMIZU
Takashi KOSHIMIZU am 9 Feb. 2019
以下が fitcsvmのサンプルコードですが、最後のPlotの中に、2つのカテゴリを分類するhyperplane を描きたいのですが、
ご存知の方、方法をご教授願えませんでしょうか。宜しくご確認お願い致します。
https://jp.mathworks.com/help/stats/fitcsvm.html
-----------------------------------------
load fisheriris
inds = ~strcmp(species,'setosa');
X = meas(inds,3:4);
y = species(inds);
SVMModel = fitcsvm(X,y);
sv = SVMModel.SupportVectors;
figure
gscatter(X(:,1),X(:,2),y)
hold on
plot(sv(:,1),sv(:,2),'ko','MarkerSize',10)
legend('versicolor','virginica','Support Vector')
hold off

Akzeptierte Antwort

Yosuke Matsuki
Yosuke Matsuki am 10 Feb. 2019
最終行 hold off の1行前に、下記コードを追加することでhyperplaneを描画可能です。
等高線(contour)として描画する方法になります。dは等高線のメッシュサイズです。
d = 0.02;
[x1Grid,x2Grid] = meshgrid(min(X(:,1)):d:max(X(:,1)),...
min(X(:,2)):d:max(X(:,2)));
xGrid = [x1Grid(:),x2Grid(:)];
[~,scores] = predict(SVMModel,xGrid);
contour(x1Grid,x2Grid,reshape(scores(:,2),size(x1Grid)),[0 0],'k');
上記コードは下記のページを参考にしました。
以上

Weitere Antworten (1)

Takashi KOSHIMIZU
Takashi KOSHIMIZU am 10 Feb. 2019
投稿有難うございました。
無事、上手く動作致しました。本件誠に有難うございます。パラメータを操作して、もう少し理解を深めてみます。

Kategorien

Mehr zu MATLAB 入門 finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!