How to do it...

We proceed with the recipe as follows:

  1. We first load the necessary libraries, which includes the scikit-learn datasets so that we can load the iris data. Then, we will start a graph session. Use the following code:
import matplotlib.pyplot as plt 
import numpy as np 
import tensorflow as tf 
from sklearn import datasets 
sess = tf.Session() 
  1. Next, we will load the iris data, extract the sepal length and petal width, and separate the x and y values for each class (for plotting purposes later), as follows:
iris = datasets.load_iris() x_vals = np.array([[x[0], x[3]] for x in iris.data]) y_vals = np.array([1 if y==0 else -1 for y in iris.target]) class1_x = [x[0] for i,x in enumerate(x_vals) if y_vals[i]==1] class1_y = [x[1] for ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.