How to do it...

Here is how the regression example works:

  1. We start by loading the numpy and tensorflow numerical Python packages:
import numpy as np 
import tensorflow as tf 
  1. Now, we start a graph session:
sess = tf.Session() 
  1. Next, we create the data, placeholders, and the A variable:
x_vals = np.random.normal(1, 0.1, 100) 
y_vals = np.repeat(10., 100) 
x_data = tf.placeholder(shape=[1], dtype=tf.float32) 
y_target = tf.placeholder(shape=[1], dtype=tf.float32) 
A = tf.Variable(tf.random_normal(shape=[1])) 
  1. We add the multiplication operation to our graph:
my_output = tf.mul(x_data, A) 
  1. Next, we add our L2 Loss function between the multiplication output and the target data:
loss = tf.square(my_output - y_target)
  1. Now, we have to declare ...

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.