Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
TensorFlow 1.x Deep Learning Cookbook
TensorFlow 1.x Deep Learning Cookbook

TensorFlow 1.x Deep Learning Cookbook: Over 90 unique recipes to solve artificial-intelligence driven problems with Python

eBook
$39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

TensorFlow 1.x Deep Learning Cookbook

Regression

This chapter shows how regression can be done using TensorFlow. In this chapter, we will cover the following topics:

  • Choosing loss functions
  • Optimizers in TensorFlow
  • Reading from CSV files and preprocessing data
  • House price estimation-simple linear regression
  • House price estimation-multiple linear regression
  • Logistic regression on the MNIST dataset

Introduction

Regression is one of the oldest and yet quite powerful tools for mathematical modelling, classification, and prediction. Regression finds application in varied fields ranging from engineering, physical science, biology, and the financial market to social sciences. It is the basic tool in the hand of a data scientist.

Regression is normally the first algorithm that people in machine learning work with. It allows us to make predictions from data by learning the relationship between the dependent and independent variables. For example, in the case of house price estimation, we determine the relationship between the area of the house (independent variable) and its price (dependent variable); this relationship can be then used to predict the price of any house given its area. We can have multiple independent variables impacting the dependent variable. Thus, there are two...

Choosing loss functions

As discussed earlier, in regression we define the loss function or objective function and the aim is to find the coefficients such that the loss is minimized. In this recipe, you will learn how to define loss functions in TensorFlow and choose a proper loss function depending on the problem at hand.

Getting ready

Declaring a loss function requires defining the coefficients as variables and the dataset as placeholders. One can have a constant learning rate or changing learning rate and regularization constant. In the following code, let m be the number of samples, n the number of features, and P the number of classes. We should define these global parameters before the code:

m = 1000
n = 15
P = 2
...

Optimizers in TensorFlow

From your high school math, you must know that a function's first derivative is zero at its maxima and minima. The gradient descent algorithm is based on the same principle--the coefficients (weights and biases) are adjusted such that the gradient of the loss function decreases. In regression, we use gradient descent to optimize the loss function and obtain coefficients. In this recipe, you will learn how to use the gradient descent optimizer of TensorFlow and some of its variants.

Getting ready

The update of coefficients (W and b) is done proportionally to the negative of the gradient of the loss function. There are three variations of gradient descent depending on the size of the training sample...

Reading from CSV files and preprocessing data

Most of you will already be familiar with Pandas and its usefulness in handling large dataset files. TensorFlow also offers methods to read from the files. In the first chapter, we went through the recipe for reading from files in TensorFlow; in this recipe, we will focus on how to read from CSV files and preprocess the data before training.

Getting ready

We will consider the Boston housing price dataset (http://lib.stat.cmu.edu/datasets/boston) collected by Harrison and Rubinfield in 1978. The dataset contains 506 sample cases. Each house is assigned 14 attributes:

  • CRIM: per capita crime rate by town
  • ZN: Proportion of residential land zoned for lots over 25,000 sq.ft
  • INDUS: Proportion...

House price estimation-simple linear regression

In this recipe, we will perform simple linear regression based on the number of rooms (RM) on the Boston house price dataset.

Getting ready

Our goal is to predict the house price given in the last column (MEDV). In this recipe, we load the dataset from the TensorFlow Contrib dataset directly. We optimize the coefficients for an individual training sample using the stochastic gradient descent optimizer.

How to do it...

We proceed with the recipe as follows:

  1. The first step is to import all the packages that we will need:
...

House price estimation-multiple linear regression

We can do multiple linear regression on the same data by making a slight modification in the declaration of weights and placeholders. In the case of multiple linear regression, as each feature has different value ranges, normalization becomes essential. Here is the code for multiple linear regression on the Boston house price dataset, using all the 13 input features.

How to do it...

Here is how we proceed with the recipe:

  1. The first step is to import all the packages that we will need:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
  1. We need to normalize the feature data since the data ranges of all the features are varied. We define a normalize...

Logistic regression on the MNIST dataset

This recipe is based on the logistic regressor for MNIST provided at https://www.tensorflow.org/get_started/mnist/beginners, but we will add some TensorBoard summaries to understand it better. Most of you must already be familiar with the MNIST dataset--it is like the ABC of machine learning. It contains images of handwritten digits and a label for each image, saying which digit it is.

For logistic regression, we use one-hot encoding for the output Y. Thus, we have 10 bits representing the output; each bit can have a value either 0 or 1, and being one-hot means that for each image in label Y, only one bit out of the 10 will have value 1, the rest will be zeros. Here, you can see the image of the handwritten numeral 8, along with its hot encoded value [0 0 0 0 0 0 0 0 1 0]:

...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Skill up and implement tricky neural networks using Google's TensorFlow 1.x
  • An easy-to-follow guide that lets you explore reinforcement learning, GANs, autoencoders, multilayer perceptrons and more.
  • Hands-on recipes to work with Tensorflow on desktop, mobile, and cloud environment

Description

Deep neural networks (DNNs) have achieved a lot of success in the field of computer vision, speech recognition, and natural language processing. This exciting recipe-based guide will take you from the realm of DNN theory to implementing them practically to solve real-life problems in the artificial intelligence domain. In this book, you will learn how to efficiently use TensorFlow, Google’s open source framework for deep learning. You will implement different deep learning networks, such as Convolutional Neural Networks (CNNs), Recurrent Neural Networks (RNNs), Deep Q-learning Networks (DQNs), and Generative Adversarial Networks (GANs), with easy-to-follow standalone recipes. You will learn how to use TensorFlow with Keras as the backend. You will learn how different DNNs perform on some popularly used datasets, such as MNIST, CIFAR-10, and Youtube8m. You will not only learn about the different mobile and embedded platforms supported by TensorFlow, but also how to set up cloud platforms for deep learning applications. You will also get a sneak peek at TPU architecture and how it will affect the future of DNNs. By using crisp, no-nonsense recipes, you will become an expert in implementing deep learning techniques in growing real-world applications and research areas such as reinforcement learning, GANs, and autoencoders.

Who is this book for?

This book is intended for data analysts, data scientists, machine learning practitioners and deep learning enthusiasts who want to perform deep learning tasks on a regular basis and are looking for a handy guide they can refer to. People who are slightly familiar with neural networks, and now want to gain expertise in working with different types of neural networks and datasets, will find this book quite useful.

What you will learn

  • • Leverage different data sets such as MNIST, CIFAR-10, and Youtube8m with TensorFlow and learn how to access and use them in your code
  • • Use TensorBoard to understand neural network architectures, optimize the learning process, and peek inside the neural network black box
  • • Use different regression techniques for prediction and classifi cation problems
  • • Build single and multilayer perceptrons in TensorFlow
  • • Implement a CNN and a RNN in TensorFlow, and use them to solve real-world problems
  • • Learn how Restricted Boltzmann Machines can be used to recommend movies
  • • Understand the implementation of autoencoders and deep belief networks, and use them for emotion detection
  • • Master the different reinforcement learning methods in order to implement game playing agents

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 12, 2017
Length: 536 pages
Edition : 1st
Language : English
ISBN-13 : 9781788293594
Vendor :
Google
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 12, 2017
Length: 536 pages
Edition : 1st
Language : English
ISBN-13 : 9781788293594
Vendor :
Google
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 131.97
TensorFlow 1.x Deep Learning Cookbook
$48.99
Mastering TensorFlow 1.x
$38.99
Neural Network Programming with TensorFlow
$43.99
Total $ 131.97 Stars icon

Table of Contents

14 Chapters
TensorFlow - An Introduction Chevron down icon Chevron up icon
Regression Chevron down icon Chevron up icon
Neural Networks - Perceptron Chevron down icon Chevron up icon
Convolutional Neural Networks Chevron down icon Chevron up icon
Advanced Convolutional Neural Networks Chevron down icon Chevron up icon
Recurrent Neural Networks Chevron down icon Chevron up icon
Unsupervised Learning Chevron down icon Chevron up icon
Autoencoders Chevron down icon Chevron up icon
Reinforcement Learning Chevron down icon Chevron up icon
Mobile Computation Chevron down icon Chevron up icon
Generative Models and CapsNet Chevron down icon Chevron up icon
Distributed TensorFlow and Cloud Deep Learning Chevron down icon Chevron up icon
Learning to Learn with AutoML (Meta-Learning) Chevron down icon Chevron up icon
TensorFlow Processing Units Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.4
(16 Ratings)
5 star 50%
4 star 6.3%
3 star 12.5%
2 star 0%
1 star 31.3%
Filter icon Filter
Top Reviews

Filter reviews by




NSingh Jan 15, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Without using complicated maths, authors have very meticulously implemented deep neural networks.The book is not for novices; instead, it is for advanced users. You will make most of the book if you:1. Are advanced Python users and looking to build an understanding of Deep Neural Networks. OR2. Know deep learning, and want to shift to TensorFlow for your work.The recipes use standard datasets already built into TensorFlow library, and this allows one to focus on implementation details of the model.I especially liked the chapter on Autoencoders as it very exhaustively covered the implementation of different types of Autoencoders on the same dataset allowing me to compare their performance. The chapter on Reinforcement learning was refreshingly simple, I could copy the recipe and with little modification had my policy gradient model working in the different game environment in no time.The book also gives step by step instruction on how to use Tensorflow models for mobile apps both on IOS and Android.The USP of the book is that it covers almost all DL models starting from the basic MLP to the recently released CAPSNet. Another great thing about the book is that it has given the references to the research papers it has implemented. The hands-on approach of the book makes it a useful reference for research.For codes, I would suggest you use the GitHub link provided in the book.Overall it is a great book.
Amazon Verified review Amazon
Juan Lopez Feb 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Even for a good chef a recipe book always come handy, and thanks to the authors all Deep Learning professionals, enthusiasts, or beginners will have this Cookbook for consulting. From simple Linear Regressions to Generative Adversarial Networks you will find easy recipes to follow and learn how to implement all these kind of networks.
Amazon Verified review Amazon
Gayan Aug 18, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good product good read
Amazon Verified review Amazon
Kishore A Feb 16, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book gives a very good overview of the various algorithms to get one started in deep learning. I have especially liked the fact that it walks the reader through multiple use cases across all the algorithms. Additionally, it has a broad coverage including CNN, RNN, RL, Auto encoders, Capsule networks and even the implementation of tensorflow on mobile devices.Definitely a great buy!
Amazon Verified review Amazon
A. Jaokar Jan 11, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought this book (physical copy) from the Packt based on reading the author's previous book(on Keras). I have enjoyed the previous book and use it extensively because of its practical implementation approach. The same is followed here (but for core tensorflow instead of Keras). The cookbook approach helps a lot for tensorflow. Apart from CNNs, RNNS etc the book also covers Tensorflow mobile (which is of interest for me personally). The section on distributed tensorflow(Chapter 12) was new and interesting for me. Like in the first book, I referred to the author's git repo which I found useful. I used this book mainly to get a deeper understanding of tensorflow(I was starting from keras). It is also a good approach to learning tensorflow itself because of the cookbook approach. It even talks of Capsule networks. Hence, at the time of review(Jan 18) - its as current as Tensorflow can be. The distributed tensorflow also covers Azure and Amazon in addition to Google cloud(was nice to see the open approach). finally, I suggest that future versions of the book could expand on TPUs(also an interest for me based on my work)
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.