Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
TensorFlow Machine Learning Cookbook
TensorFlow Machine Learning Cookbook

TensorFlow Machine Learning Cookbook: Over 60 recipes to build intelligent machine learning systems with the power of Python , Second Edition

Arrow left icon
Profile Icon Nick McClure Profile Icon Sujit Pal
Arrow right icon
₹800 per month
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2 (3 Ratings)
Paperback Aug 2018 422 pages 2nd Edition
eBook
₹799.99 ₹2671.99
Paperback
₹2904.99
Subscription
Free Trial
Renews at ₹800p/m
Arrow left icon
Profile Icon Nick McClure Profile Icon Sujit Pal
Arrow right icon
₹800 per month
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2 (3 Ratings)
Paperback Aug 2018 422 pages 2nd Edition
eBook
₹799.99 ₹2671.99
Paperback
₹2904.99
Subscription
Free Trial
Renews at ₹800p/m
eBook
₹799.99 ₹2671.99
Paperback
₹2904.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 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 Machine Learning Cookbook

The TensorFlow Way

In this chapter, we will introduce the key components of how TensorFlow operates. Then, we will tie it together to create a simple classifier and evaluate the outcomes. By the end of the chapter, you should have learned about the following:

  • Operations in a computational graph
  • Layering nested operations
  • Working with multiple layers
  • Implementing loss functions
  • Implementing backpropagation
  • Working with batch and stochastic training
  • Combining everything together
  • Evaluating models

Introduction

Now that we have introduced how TensorFlow creates tensors, and uses variables and placeholders, we will introduce how to act on these objects in a computational graph. From this, we can set up a simple classifier and see how well it performs.

Also, remember that the current and updated code from this book is available online on GitHub at https://github.com/nfmcclure/tensorflow_cookbook.

Operations in a computational graph

Now that we can put objects into our computational graph, we will introduce operations that act on such objects.

Getting ready

To start a graph, we load TensorFlow and create a session, as follows:

import tensorflow as tf 
sess = tf.Session() 

How to do it...

In this example, we will combine what we have learned and feed each number in a list into an operation in a graph and print the output:

First, we declare our tensors and placeholders. Here, we will create a NumPy array to feed into our operation:

import numpy as np 
x_vals = np...

Layering nested operations

In this recipe, we will learn how to put multiple operations on the same computational graph.

Getting ready

It's important to know how to chain operations together. This will set up layered operations in the computational graph. For a demonstration, we will multiply a placeholder by two matrices and then perform addition. We will feed in two matrices in the form of a three-dimensional NumPy array:

import tensorflow as tf 
sess = tf.Session() 

How to do it...

It is also important to note how the data will change shape as it passes through...

Working with multiple layers

Now that we have covered multiple operations, we will cover how to connect various layers that have data propagating through them.

Getting ready

In this recipe, we will introduce how to best connect various layers, including custom layers. The data we will generate and use will be representative of small random images. It is best to understand this type of operation with a simple example and see how we can use some built-in layers to perform calculations. The first layer we will explore is called a moving window. We will perform a small moving window average across a 2D image and then the second layer will be a custom operation layer.

In this section, we will see that the computational graph can...

Implementing loss functions

Loss functions are very important for machine learning algorithms. They measure the distance between the model outputs and the target (truth) values. In this recipe, we show various loss function implementations in TensorFlow.

Getting ready

In order to optimize our machine learning algorithms, we will need to evaluate the outcomes. Evaluating outcomes in TensorFlow depends on specifying a loss function. A loss function tells TensorFlow how good or bad the predictions are compared to the desired result. In most cases, we will have a set of data and a target on which to train our algorithm. The loss function compares the target to the prediction and gives a numerical distance between the two.

For...

Implementing backpropagation

One of the benefits of using TensorFlow is that it can keep track of operations and automatically update model variables based on back propagation. In this recipe, we will introduce how to use this aspect to our advantage when training machine learning models.

Getting ready

Now, we will introduce how to change our variables in the model in such a way that a loss function is minimized. We have learned how to use objects and operations, and create loss functions that will measure the distance between our predictions and targets. Now, we just have to tell TensorFlow how to back propagate errors through our computational graph to update the variables and minimize the loss function. This is done via...

Working with batch and stochastic training

While TensorFlow updates our model variables according to back propagation, it can operate on anything from one-datum observation to a large batch of data at once. Operating on one training example can make for a very erratic learning process, while using too large a batch can be computationally expensive. Choosing the right type of training is crucial for getting our machine learning algorithms to converge to a solution.

Getting ready

In order for TensorFlow to compute the variable gradients for back propagation to work, we have to measure the loss on a sample or multiple samples. Stochastic training only works on one randomly sampled data-target pair at a time, just as we did in...

Combining everything together

In this section, we will combine everything we have illustrated so far and create a classifier for the iris dataset.

Getting ready

The iris dataset is described in more detail in the Working with data sources recipe in Chapter 1, Getting Started with TensorFlow. We will load this data and make a simple binary classifier to predict whether a flower is the species Iris setosa or not. To be clear, this dataset has three species, but we will only predict whether a flower is a single species, I. setosa or not, giving us a binary classifier. We will start by loading the libraries and data, then transform the target accordingly.

...

Evaluating models

We have already learned how to train a regression and classification algorithm in TensorFlow. After this, we must be able to evaluate the model's predictions to determine how well it did.

Getting ready

Evaluating models is very important and every subsequent model will have some form of model evaluation. Using TensorFlow, we must build this feature into the computational graph and call it while our model is training and/or after it has finished training.

Evaluating models during training gives us an insight into the algorithm and may give us hints to debug it, improve it, or change models entirely. While evaluation during training isn't always necessary, we will show how to do it with both regression...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Exploit the features of Tensorflow to build and deploy machine learning models
  • Train neural networks to tackle real-world problems in Computer Vision and NLP
  • Handy techniques to write production-ready code for your Tensorflow models

Description

TensorFlow is an open source software library for Machine Intelligence. The independent recipes in this book will teach you how to use TensorFlow for complex data computations and allow you to dig deeper and gain more insights into your data than ever before. With the help of this book, you will work with recipes for training models, model evaluation, sentiment analysis, regression analysis, clustering analysis, artificial neural networks, and more. You will explore RNNs, CNNs, GANs, reinforcement learning, and capsule networks, each using Google's machine learning library, TensorFlow. Through real-world examples, you will get hands-on experience with linear regression techniques with TensorFlow. Once you are familiar and comfortable with the TensorFlow ecosystem, you will be shown how to take it to production. By the end of the book, you will be proficient in the field of machine intelligence using TensorFlow. You will also have good insight into deep learning and be capable of implementing machine learning algorithms in real-world scenarios.

Who is this book for?

If you are a data scientist or a machine learning engineer with some knowledge of linear algebra, statistics, and machine learning, this book is for you. If you want to skip the theory and build production-ready machine learning models using Tensorflow without reading pages and pages of material, this book is for you. Some background in Python programming is assumed.

What you will learn

  • Become familiar with the basic features of the TensorFlow library
  • Get to know Linear Regression techniques with TensorFlow
  • Learn SVMs with hands-on recipes
  • Implement neural networks to improve predictive modeling
  • Apply NLP and sentiment analysis to your data
  • Master CNN and RNN through practical recipes
  • Implement the gradient boosted random forest to predict housing prices
  • Take TensorFlow into production

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 31, 2018
Length: 422 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789131680
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 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 : Aug 31, 2018
Length: 422 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789131680
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 9,906.97
TensorFlow Machine Learning Projects
₹2904.99
Machine Learning Algorithms
₹4096.99
TensorFlow Machine Learning Cookbook
₹2904.99
Total 9,906.97 Stars icon

Table of Contents

12 Chapters
Getting Started with TensorFlow Chevron down icon Chevron up icon
The TensorFlow Way Chevron down icon Chevron up icon
Linear Regression Chevron down icon Chevron up icon
Support Vector Machines Chevron down icon Chevron up icon
Nearest-Neighbor Methods Chevron down icon Chevron up icon
Neural Networks Chevron down icon Chevron up icon
Natural Language Processing Chevron down icon Chevron up icon
Convolutional Neural Networks Chevron down icon Chevron up icon
Recurrent Neural Networks Chevron down icon Chevron up icon
Taking TensorFlow to Production Chevron down icon Chevron up icon
More with TensorFlow Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
(3 Ratings)
5 star 0%
4 star 0%
3 star 33.3%
2 star 33.3%
1 star 33.3%
science-dude Feb 29, 2024
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Sadly this book is a bit out of date when Tensorflow 2 was released and Tensorflow 1 made obsolete.
Amazon Verified review Amazon
Stephen P. Owens Jul 31, 2022
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
For starters the book is dated, and the code examples are no longer functional so the first thing I had to do was go in and fix all the code before I could run the examples. The second thing is that this book really doesn't explain or teach anything, you could save the money on the book and go to their Github website download all the example code, fix it till it works and then read the code, you will get just as much out of that as you will by the useless info they add to the code base within the book.
Amazon Verified review Amazon
Amazon Customer Feb 15, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Purchased the latest Edition as I read the first one had lot of errors and typos.When I read around first 50 pages of the book, there were around many typos and more than 8 syntactical errors.Right now I have even stopped counting. The language is very poor. Very poorly written. It miserably fails to explain the concepts. I have read lots of other books on DL but honestly this is the worst book ever. Even if you go to the github repository of this book to refer codes, you will find two versions, one is .ipynb and the other one is .py. Even those files have errors. I don't know how they published the books with out sorting out all these problems.I have finished many DL books within 2-3 weeks because they felt really interesting. Examples: Deep Learning with python, Deep Learning BookBut right now I don't even feel like reading the book because the author has has made simple things way too complicated.Example: we can split data into train n test using sklearn train_test_split. Instead the author is writing 4 lines of code to split them every time. Why man why???I would recommend to go for some other book
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.