Effacer les filtres
Effacer les filtres

Plot Support Vectors, Margin and decision boundary using LIBSVM MATLAB interface

4 vues (au cours des 30 derniers jours)
Astha Ameta
Astha Ameta le 28 Jan 2017
Modifié(e) : KSSV le 20 Oct 2017
I am using Matlab-Libsvm Interface for binary classification using SVM. I have multi dimensional data. I need to plot decision boundary and margin along with support vectors.
Below is the code I used for this:
model = svmtrain(Y, X, sprintf('-c %f -w1 1 -w-1 5 -g %f', best_C, best_gamma));
w = model.SVs' * model.sv_coef;
b = -model.rho;
if (model.Label(1) == -1)
w = -w; b = -b;
end
y_hat = sign(w'*X' + b);
sv = full(model.SVs);
% plot support vectors
figure
plot(sv(:,1:14),'ko', 'MarkerSize', 10);
hold on
% plot decision boundary
plot_x = linspace(min(X(:,1)), max(X(:,1)), 30);
plot_y = (-1/w(2))*(w(1)*plot_x + b);
plot_z = sign(w(1)*plot_x + b)/norm(w);
plot(plot_x, plot_y, 'k-', 'LineWidth', 1)
hold on
plot(plot_x, plot_z, 'kx', 'LineWidth', 1);
hold off
hold off
But I am unable to plot decision boundary and margin using this code. Also, support vectors are plotted inappropriately.
Please let me know where I am wrong.
  1 commentaire
babita verma
babita verma le 19 Oct 2017
Hi Astha I am facing the same problem with plotting of the decision boundary. Were you able to resolve this issue?
regards

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by