Working with a Linear SVM
For this example, we will create a linear separator from the iris
data set. We know from prior chapters that the sepal length and petal width create a linear separable binary data set for predicting if a flower is I. setosa or not.
Getting ready
To implement a soft separable SVM in TensorFlow, we will implement the specific loss function, as follows:
Here, A is the vector of partial slopes, b is the intercept, is a vector of inputs, is the actual class, (-1 or 1) and is the soft separability regularization parameter.
How to do it…
We start by loading the necessary libraries. This will include the scikit learn dataset library for access to the iris data set. Use the following code:
import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from sklearn import datasets
Note
To set up Scikit-learn for this exercise, we just need to type
$pip install –U scikit-learn
. Note that it also comes installed with Anaconda as well.Next we start a graph session and...