How to do it...

We proceed with the recipe as follows:

  1. First, we load the necessary libraries and start a graph session, as follows:
import matplotlib.pyplot as plt 
import numpy as np 
import tensorflow as tf 
from sklearn import datasets 
sess = tf.Session() 
  1. Now, we generate the data. The data we will generate will be two concentric rings of data; each ring will belong to a different class. We have to make sure that the classes are -1 or 1 only. Then we will split the data into x and y values for each class for plotting purposes. To do this, use the following code:
(x_vals, y_vals) = datasets.make_circles(n_samples=500, factor=.5, noise=.1) y_vals = np.array([1 if y==1 else -1 for y in y_vals]) class1_x = [x[0] for i,x in enumerate(x_vals) ...

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.