How can I find and plot the hyperplane to this simple dataset using SVM

30 views (last 30 days)
I have this simple dataset D={[(1,1),1],[(1,-1),1],[(-1,1),-1],[(-1,-1),-1]} in which 1 denotes red points and -1 shows blue points. How can I find the hyperplane by using SVM and plot it in matlab for this dataset? Does matlab gives me the equation of the hyperplane, as well?
Thanks in advance.

Answers (1)

Image Analyst
Image Analyst on 29 May 2021
Did you try fitcsvm()? From the help:
Description
fitcsvm trains or cross-validates a support vector machine (SVM) model for one-class and two-class (binary) classification on a low-dimensional or moderate-dimensional predictor data set. fitcsvm supports mapping the predictor data using kernel functions, and supports sequential minimal optimization (SMO), iterative single data algorithm (ISDA), or L1 soft-margin minimization via quadratic programming for objective-function minimization.
To train a linear SVM model for binary classification on a high-dimensional data set, that is, a data set that includes many predictor variables, use fitclinear instead.
For multiclass learning with combined binary SVM models, use error-correcting output codes (ECOC). For more details, see fitcecoc.
To train an SVM regression model, see fitrsvm for low-dimensional and moderate-dimensional predictor data sets, or fitrlinear for high-dimensional data sets.
  2 Comments
Mojtaba Mohareri
Mojtaba Mohareri on 2 Jun 2021
Edited: Mojtaba Mohareri on 2 Jun 2021
Thank you very much for your explanation. I don't know matlab very much. Could you please send me a simple code I can use to classify my above data and find the hyperplane?
Thanks in advance.
Image Analyst
Image Analyst on 2 Jun 2021
Sorry, I don't have any SVM demos made up yet. I'd have to fumble through the documentation just like you will. I'm pretty sure the documentation includes examples like nearly all function documentation does.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!