How to Plot Decision Boundary for SVM
22 ビュー (過去 30 日間)
古いコメントを表示
Hi,
after i make my model using 'fitcsvm' and predict the test data, id like to know the boundary and plot it
i cant find anything inside the model variable (1x1 ClassificationSVM) but i cant find anything thats like points so i can plot the line
heres the code i use if needed:
model=fitcsvm(trainD',trainL','Standardize',1);
trainD is 2x200 (100 for each class and 2 features)
ALSO
for some reason i dont understand, using linear svm gives me 100% accuracy while non lienar gives me about 75% (test data is too little 12 sample each)
回答 (1 件)
Meet
2024 年 11 月 12 日 9:16
編集済み: Meet
2024 年 11 月 12 日 9:16
Hi Kamyar,
To plot a decision boundary using an SVM model, you can follow these steps:
- Obtain the linear coefficients (Beta) and the bias (Bias) from the SVM model using 'model.Beta' and 'model.Bias'.
- Use the equation from the "fitcsvm" documentation to plot the decision boundary.
- Determine the margin width and plot lines parallel to the decision boundary to visualize the margins.
- Display the data points, support vectors, decision boundary, and margins on a plot.
Regarding model accuracy, the difference between linear and non-linear SVM models arises because linear SVMs perform well on linearly separable data. In contrast, non-linear models can capture more complex patterns but might overfit, especially with small datasets.
Please refer to the below documentation link for an example to fit decision boundary of SVM:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!