...

/

Visualize the Working of the Support Vector Machine

Visualize the Working of the Support Vector Machine

Visualize the working of the support vector machine.

Now that we have enough understanding of the support vector machine algorithm, let's move and create interactive plots to see the effect of the CC parameter.

Imports

We need to import the required libraries.

Press + to interact
# required imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from ipywidgets import interact

Sample data

Let's create a dataset for binary class classification.

Press + to interact
# from sklearn.datasets.samples_generator import make_blobs # older versions
from sklearn.datasets import make_blobs
X, y = make_blobs(n_samples=50, centers=2,random_state=121,cluster_std=0.90)
# try different values of cluster_std e.g. 0.60, 0.70, 0.80 ...etc and
# observe the margins in the interactive plots
plt.figure(figsize=(16,8))
ax = plt.gca()
ax.set_xticks([])
ax.set_yticks([])
ax.set_xlabel('X1')
ax.set_ylabel('X2')
# plotting data as a scatter plot
plt.scatter(X[:, 0], X[:, 1], c=y, s=100, cmap=plt.cm.Set1, edgecolors='black', linewidth=2);

Now that we have the data, let’s move on and write some functions to create the interactive plots and understand the effect of the CC ...

Access this course and 1400+ top-rated courses and projects.