TensorFlow Basics
Deep Learning
● This section will expand on what we’ve
learned and explore the TensorFlow’s
Framework approach to Neural
Networks
● You’ll see lots of parallels with our own
simple implementation!
Deep Learning
● TensorFlow Basics
○ TF Basic Syntax
○ TF Graphs
○ TF Variables
○ TF Placeholders
● TensorFlow Neural Network
Deep Learning
● TensorFlow Regression Code Along
● TensorFlow Classification Code Along
● Regression Exercise
○ Solution
● Classification Exercise
○ Solution
Let’s get started!
TensorFlow Basic
Syntax
TensorFlow Graphs
Deep Learning
● Graphs are sets of connected nodes
(vertices).
● The connections are referred to as edges.
● In TensorFlow each node is an operation
with possible inputs that can supply
some output.
Deep Learning
● In general, with TensorFlow we will
construct a graph and then execute it.
● Let’s start showing some simple
examples in Python!
● We’ll also discuss how TensorFlow uses a
default graph.
Deep Learning
● We’ll start by building out this graph:
Constant
n1
1
Constant Add
2
n2 n3 3
Variables and
Placeholders
Deep Learning
● There are two main types of tensor
objects in a Graph:
○ Variables
○ Placeholders
Deep Learning
● During the optimization process
TensorFlow tunes the parameters of the
model.
● Variables can hold the values of weights
and biases throughout the session.
● Variables need to be initialized.
Deep Learning
● Placeholders are initially empty and are
used to feed in the actual training
examples.
● However they do need a declared
expected data type (tf.float32) with an
optional shape argument.
Deep Learning
● Let’s see some examples of each.
● Once we understand how they work
we’ll be ready to build our first model
with TensorFlow!
First TF Neural Network
Deep Learning
● We’ve learned about Sessions, Graphs,
Variables, and Placeholders.
● With these building blocks we can
create our first neuron!
● We’ll create a neuron that performs a
very simple linear fit to some 2-D data.
Deep Learning
● Our steps are:
○ Build a Graph
○ Initiate the Session
○ Feed Data In and get Output
● We’ll use the basics we’ve learned so
far to accomplish this task!
Deep Learning
What does the graph of wx+b=z look
like?
W
Variable
Activation
tf.matmul() tf.add() Function
Operation Operation
X
Placeholder b
Variable
Deep Learning
● Afterwards you can add in the cost
function in order to train your network to
optimize the parameters!
● Let’s go build this neural network!
TensorFlow Regression
Deep Learning
● Let’s code along with a more realistic
regression example and introduce
tf.estimator!
TensorFlow
Estimator API
Deep Learning
● Let’s now explore the Estimator API from
TensorFlow!
● There are lots of other higher level APIs
(Keras, Layers, etc), we cover those later
on in the Miscellaneous Section.
Deep Learning
● The tf.estimator API has several model
types to choose from.
● Let’s quickly show you the options!
Deep Learning
● Here are the Estimator Types
○ tf.estimator.LinearClassifier:
Constructs a linear classification
model.
○ tf.estimator.LinearRegressor:
Constructs a linear regression
model.
Deep Learning
● Here are the Estimator Types
○ tf.estimator.DNNClassifier:
Construct a neural network
classification model.
○ tf.estimator.DNNRegressor:
Construct a neural network
regression model.
Deep Learning
● Here are the Estimator Types
○ Tf.estimator.
DNNLinearCombinedClassifier:
Construct a neural network and
linear combined classification
model.
Deep Learning
● Here are the Estimator Types
○ Tf.estimator.
DNNLinearCombinedRegressor:
Construct a neural network and
linear combined regression model.
Deep Learning
● In general, to use the Estimator API we
do the following:
○ Define a list of feature columns
○ Create the Estimator Model
○ Create a Data Input Function
○ Call train,evaluate, and predict
methods on the estimator object.
Deep Learning
● Let’s go ahead and show a simple
example of using this Estimator API.
TensorFlow Classification
Deep Learning
● Pima Indians Diabetes Dataset
● Tf.estimator API
● Categorical and Continuous Features
● LinearClassifier and DNNClassifier
● Let’s get started!
TF Regression Exercise
Deep Learning
● Time to test your new skills!
● You will create a model to predict
housing prices using the tf.estimator API.
● Let’s review the exercise notebook.
● Optional - skip to the solutions and treat
the exercise as a code-along lecture.
TF Regression Exercise
Solution
TF Classification Exercise
TF Classification Exercise
Solution