Skip to content

Commit

Permalink
added margin as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-taylor committed Jun 4, 2024
1 parent 6e010ff commit cb62290
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ISLP/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def plot(X,
'''
Graphical representation of fitted support vector classifier.
There are two types of support vectors:
- Points violating the margin but correctly classified. These are marked with a black '+'.
- Misclassified points. These are marked with a red 'x'.
Parameters
----------
Expand Down Expand Up @@ -113,9 +119,19 @@ def plot(X,
cmap=decision_cmap,
alpha=alpha)

decision_val = svm.decision_function(X_pred)

# add the support vectors

if svm.classes_.shape[0] == 2: # 2-class problem

ax.contourf(xval,
yval,
decision_val.reshape(yval.shape),
levels=[-1,1],
cmap=decision_cmap,
alpha=alpha)

D = svm.decision_function(X[svm.support_])
Y_ = (2 * (Y[svm.support_] == svm.classes_[1]) - 1)
violate_margin = (Y_ * D) > 0
Expand Down

0 comments on commit cb62290

Please sign in to comment.