![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203481/image.jpeg)
How to draw hyperplane using 'fitcsvm'
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Takashi KOSHIMIZU
el 9 de Feb. de 2019
Respondida: Takashi KOSHIMIZU
el 10 de Feb. de 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 comentarios
Respuesta aceptada
Yosuke Matsuki
el 10 de Feb. de 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203481/image.jpeg)
上記コードは下記のページを参考にしました。
以上
0 comentarios
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!