How to do it...

We proceed with the recipe as follows: 

  1. To create the computational graph, we'll start by loading the following necessary libraries:
import matplotlib.pyplot as pltimport numpy as npimport tensorflow as tffrom sklearn import datasets 
  1. Now we'll load the Iris data and store the length as the target value. Then we'll start a graph session with the following code:
iris = datasets.load_iris() 
x_vals = np.array([x[0:3] for x in iris.data]) 
y_vals = np.array([x[3] for x in iris.data]) 
sess = tf.Session() 
  1. Since the dataset is smaller, we will want to set a seed to make the results reproducible, as follows:
seed = 2 
tf.set_random_seed(seed) 
np.random.seed(seed)
  1. To prepare the data, we'll create a 80-20 train-test split and ...

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.