Working with a linear SVM
For this example, we will create a linear separator from the iris dataset. We know from prior chapters that the sepal length and petal width create a linear separable binary dataset for predicting whether 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 proceed with the recipe as follows:
- We start by loading the necessary libraries. This will include the
scikit-learn
dataset library for access to the iris dataset. 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...