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
Imports
We need to import the required libraries.
Press + to interact
# required importsimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.svm import SVCfrom 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 versionsfrom sklearn.datasets import make_blobsX, 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 plotsplt.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 plotplt.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
Access this course and 1400+ top-rated courses and projects.