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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
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
Estimated delivery fee Deliver to Egypt

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$34.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Egypt

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$34.95
(Includes tracking information)

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela