How to draw hyperplane using 'fitcsvm'
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Takashi KOSHIMIZU
am 9 Feb. 2019
Beantwortet: Takashi KOSHIMIZU
am 10 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
0 Kommentare
Akzeptierte Antwort
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');
上記コードは下記のページを参考にしました。
以上
0 Kommentare
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!