# How to get optimal value that best distinguishes two groups using SVM

1 view (last 30 days)
Prabhjot Dhami on 1 Feb 2021
Answered: Aditya Patil on 16 Feb 2021
Greetings,
I am trying to learn more about classification using support vector machines. Accordingly, I have been following the MATLAB examples.
Now, with my own data, I have two groups, and one predictor variable (let's call it heart rate). My goal is to find the optimval value for heart rate that best distinguishes the two groups. I want to come up with a single value for heart rate for which I can say if they are above, they likely belong to group A, and if below, they likely belong to group B.
I have followed the fitcsvm and perfcurve examples, but am still confused as to how to come up with such an optimal value.
Any guidance with this would be greatly appreciated.
Thank you.

Aditya Patil on 16 Feb 2021
For svm with linear kernel, the boundary is given by the hyperplane at which the score function is equal to zero. In case of a single predictor, the "hyperplane" is a point. And the score function is where β is the coefficient, and b is bias. Hence, you can get the boundary for solving the equation for . Refer the code below for example.
X = [1:100]';
y = X < 80;
mdl = fitcsvm(X,y, 'KernelFunction',"linear");
% the equation for decision boundary is beta * x + bias = 0
% so x = -bias/beta
bnd = -1 * mdl.Bias / mdl.Beta
Note that this works only for linear kernels. For non linear kernels, SVM does not calculate score in terms of parameters, hence it's not possible to get an equation for the boundary. See this answers for details. You should use linear classifier in such a situation.