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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.