TensorFlow Machine Learning Cookbook - Nick McClure - E-Book

TensorFlow Machine Learning Cookbook E-Book

Nick McClure

0,0
44,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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 will let you dig deeper and gain more insights into your data than ever before. You’ll work through recipes on training models, model evaluation, sentiment analysis, regression analysis, clustering analysis, artificial neural networks, and deep learning – each using Google’s machine learning library TensorFlow.
This guide starts with the fundamentals of the TensorFlow library which includes variables, matrices, and various data sources. Moving ahead, you will get hands-on experience with Linear Regression techniques with TensorFlow. The next chapters cover important high-level concepts such as neural networks, CNN, RNN, and NLP.
Once you are familiar and comfortable with the TensorFlow ecosystem, the last chapter will show you how to take it to production.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 392

Veröffentlichungsjahr: 2017

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

TensorFlow Machine Learning Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Piracy
Questions
1. Getting Started with TensorFlow
Introduction
How TensorFlow Works
Getting ready
How to do it…
How it works…
See also
Declaring Tensors
Getting ready
How to do it…
How it works…
There's more…
Using Placeholders and Variables
Getting ready
How to do it…
How it works…
There's more…
Working with Matrices
Getting ready
How to do it…
How it works…
Declaring Operations
Getting ready
How to do it…
How it works…
There's more…
Implementing Activation Functions
Getting ready
How to do it…
How it works…
There's more…
Working with Data Sources
Getting ready
How to do it…
How it works…
See also
Additional Resources
Getting ready
How to do it…
See also
2. The TensorFlow Way
Introduction
Operations in a Computational Graph
Getting ready
How to do it…
How it works…
Layering Nested Operations
Getting ready
How to do it…
How it works…
There's more…
Working with Multiple Layers
Getting ready
How to do it…
How it works…
Implementing Loss Functions
Getting ready
How to do it…
How it works…
There's more…
Implementing Back Propagation
Getting ready
How to do it…
How it works…
There's more…
See also
Working with Batch and Stochastic Training
Getting ready
How to do it…
How it works…
There's more…
Combining Everything Together
Getting ready
How to do it…
How it works…
There's more…
See also
Evaluating Models
Getting ready
How to do it…
How it works…
3. Linear Regression
Introduction
Using the Matrix Inverse Method
Getting ready
How to do it…
How it works…
Implementing a Decomposition Method
Getting ready
How to do it…
How it works…
Learning The TensorFlow Way of Linear Regression
Getting ready
How to do it…
How it works…
Understanding Loss Functions in Linear Regression
Getting ready
How to do it…
How it works…
There's more…
Implementing Deming regression
Getting ready
How to do it…
How it works…
Implementing Lasso and Ridge Regression
Getting ready
How to do it…
How it works…
There's' more…
Implementing Elastic Net Regression
Getting ready
How to do it…
How it works…
Implementing Logistic Regression
Getting ready
How to do it…
How it works…
4. Support Vector Machines
Introduction
Working with a Linear SVM
Getting ready
How to do it…
How it works…
Reduction to Linear Regression
Getting ready
How to do it…
How it works…
Working with Kernels in TensorFlow
Getting ready
How to do it…
How it works…
There's more…
Implementing a Non-Linear SVM
Getting ready
How to do it…
How it works…
Implementing a Multi-Class SVM
Getting ready
How to do it…
How it works…
5. Nearest Neighbor Methods
Introduction
Working with Nearest Neighbors
Getting ready
How to do it…
How it works…
There's more…
Working with Text-Based Distances
Getting ready
How to do it…
How it works…
There's more…
Computing with Mixed Distance Functions
Getting ready
How to do it…
How it works…
There's more…
Using an Address Matching Example
Getting ready
How to do it…
How it works…
Using Nearest Neighbors for Image Recognition
Getting ready
How to do it…
How it works…
There's more…
6. Neural Networks
Introduction
Implementing Operational Gates
Getting ready
How to do it…
How it works…
Working with Gates and Activation Functions
Getting ready
How to do it…
How it works…
There's more…
Implementing a One-Layer Neural Network
Getting ready
How to do it…
How it works…
There's more…
Implementing Different Layers
Getting ready
How to do it…
How it works…
Using a Multilayer Neural Network
Getting ready
How to do it…
How it works…
Improving the Predictions of Linear Models
Getting ready
How to do it
How it works…
Learning to Play Tic Tac Toe
Getting ready
How to do it…
How it works…
7. Natural Language Processing
Introduction
Working with bag of words
Getting ready
How to do it…
How it works…
There's more…
Implementing TF-IDF
Getting ready
How to do it…
How it works…
There's more…
Working with Skip-gram Embeddings
Getting ready
How to do it…
How it works…
There's more…
Working with CBOW Embeddings
Getting ready
How to do it…
How it works…
There's more…
Making Predictions with Word2vec
Getting ready
How to do it…
How it works…
There's more…
Using Doc2vec for Sentiment Analysis
Getting ready
How to do it…
How it works…
8. Convolutional Neural Networks
Introduction
Implementing a Simpler CNN
Getting ready
How to do it…
How it works…
There's more…
See also
Implementing an Advanced CNN
Getting ready
How to do it…
How it works…
See also
Retraining Existing CNNs models
Getting ready
How to do it…
How it works…
See also
Applying Stylenet/Neural-Style
Getting ready
How to do it…
How it works…
See also
Implementing DeepDream
Getting ready
How to do it…
There's more…
See also
9. Recurrent Neural Networks
Introduction
Implementing RNN for Spam Prediction
Getting ready
How to do it…
How it works…
There's more…
Implementing an LSTM Model
Getting ready
How to do it…
How it works…
There's more…
Stacking multiple LSTM Layers
Getting ready
How to do it…
How it works…
Creating Sequence-to-Sequence Models
Getting ready
How to do it…
How it works…
There's more…
Training a Siamese Similarity Measure
Getting ready
How to do it…
There's more…
10. Taking TensorFlow to Production
Introduction
Implementing unit tests
Getting ready
How it works…
Using Multiple Executors
Getting ready
How to do it…
How it works…
There's more…
Parallelizing TensorFlow
Getting ready
How to do it…
How it works…
Taking TensorFlow to Production
Getting ready
How to do it…
How it works…
Productionalizing TensorFlow – An Example
Getting ready
How to do it…
How it works…
11. More with TensorFlow
Introduction
Visualizing graphs in Tensorboard
Getting ready
How to do it…
There's more…
Working with a Genetic Algorithm
Getting ready
How to do it…
How it works…
There's more…
Clustering Using K-Means
Getting ready
How to do it…
There's more…
Solving a System of ODEs
Getting ready
How to do it…
How it works…
See also
Index

TensorFlow Machine Learning Cookbook

TensorFlow Machine Learning Cookbook

Copyright © 2017 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: February 2017

Production reference: 1090217

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78646-216-9

www.packtpub.com

Credits

Author

Nick McClure

Reviewer

Chetan Khatri

Commissioning Editor

Veena Pagare

Acquisition Editor

Manish Nainani

Content Development Editor

Sumeet Sawant

Technical Editor

Akash Patel

Copy Editor

Safis Editing

Project Coordinator

Shweta H Birwatkar

Proofreader

Safis Editing

Indexer

Mariammal Chettiyar

Graphics

Disha Haria

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

Nick McClure is currently a senior data scientist at PayScale, Inc. in Seattle, WA. Prior to this, he has worked at Zillow and Caesar's Entertainment. He got his degrees in Applied Mathematics from The University of Montana and the College of Saint Benedict and Saint John's University.

He has a passion for learning and advocating for analytics, machine learning, and artificial intelligence. Nick occasionally puts his thoughts and musings on his blog, http://fromdata.org/, or through his Twitter account, @nfmcclure.

I am very grateful to my parents, who have always encouraged me to pursue knowledge. I also want to thank my friends and partner, who have endured my long monologues about the subjects in this book and always have been encouraging and listening to me. Writing this book was made easier by the amazing efforts of the open source community and the great documentation of many projects out there related to TensorFlow.

A special thanks goes out to the TensorFlow developers at Google. Their great product and skill speaks volumes for itself, and is accompanied by great documentation, tutorials, and examples.

About the Reviewer

Chetan Khatri is a Data Science Researcher with a total of 5 years of experience in research and development. He works as a Lead – Technology at Accionlabs India. Prior to that he worked with Nazara Games where he was leading Data Science practice as a Principal Big Data Engineer for Gaming and Telecom Business. He has worked with leading data companies and a Big 4 companies, where he has managed the Data Science Practice Platform and one of the Big 4 company's resources teams.

He completed his master's degree in computer science and minor data science at KSKV Kachchh University and awarded a "Gold Medalist" by the Governer of Gujarat for his "University 1st Rank" achievements.

He contributes to society in various ways, including giving talks to sophomore students at universities and giving talks on the various fields of data science, machine learning, AI, and IoT in academia and at various conferences. He has excellent correlative knowledge of both academic research and industry best practices. Hence, he always comes forward to remove the gap between Industry and Academia, where he has good number of achievements. He is the co-author of various courses, such as Data Science, IoT, Machine Learning/AI, and Distributed Databases in PG/UG cariculla at University of Kachchh. Hence, University of Kachchh became first government university in Gujarat to introduce Python as the first programming language in Cariculla and India's first government university to introduce Data Science, AI, and IoT courses in cariculla entire success story presented by Chetan at Pycon India 2016 conference. He is one of the founding members of PyKutch—A Python Community.

Currently, he is working on Intelligent IoT Devices with Deep Learning , Reinforcement learning and Distributed computing with various modern architectures.

I would like to thanks Prof. Devji Chhanga, head of the Computer Science Department, University of Kachchh, for guiding me to the correct path and for his valuable guidance in the field of data science research.

I would also like to thanks Prof. Shweta Gorania for being the first to introduce Genetic Algorithms and Neural Networks.

Last but not least I would like to thank my beloved family for their support.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Customer Feedback

Thank you for purchasing this Packt book. We take our commitment to improving our content and products to meet your needs seriously—that's why your feedback is so valuable. Whatever your feelings about your purchase, please consider leaving a review on this book's Amazon page. Not only will this help us, more importantly it will also help others in the community to make an informed decision about the resources that they invest in to learn.

You can also review for us on a regular basis by joining our reviewers' club. If you're interested in joining, or would like to learn more about the benefits we offer, please contact us: <[email protected]>.

Preface

TensorFlow was open sourced in November of 2015 by Google, and since then it has become the most starred machine learning repository on GitHub. TensorFlow's popularity is due to the approach of creating computational graphs, automatic differentiation, and customizability. Because of these features, TensorFlow is a very powerful and adaptable tool that can be used to solve many different machine learning problems.

This book addresses many machine learning algorithms, applies them to real situations and data, and shows how to interpret the results.

What this book covers

Chapter 1, Getting Started with TensorFlow, covers the main objects and concepts in TensorFlow. We introduce tensors, variables, and placeholders. We also show how to work with matrices and various mathematical operations in TensorFlow. At the end of the chapter we show how to access the data sources used in the rest of the book.

Chapter 2, The TensorFlow Way, establishes how to connect all the algorithm components from Chapter 1 into a computational graph in multiple ways to create a simple classifier. Along the way, we cover computational graphs, loss functions, back propagation, and training with data.

Chapter 3, Linear Regression, focuses on using TensorFlow for exploring various linear regression techniques, such as Deming, lasso, ridge, elastic net, and logistic regression. We show how to implement each in a TensorFlow computational graph.

Chapter 4, Support Vector Machines, introduces support vector machines (SVMs) and shows how to use TensorFlow to implement linear SVMs, non-linear SVMs, and multi-class SVMs.

Chapter 5, Nearest Neighbor Methods, shows how to implement nearest neighbor techniques using numerical metrics, text metrics, and scaled distance functions. We use nearest neighbor techniques to perform record matching among addresses and to classify hand-written digits from the MNIST database.

Chapter 6, Neural Networks, covers how to implement neural networks in TensorFlow, starting with the operational gates and activation function concepts. We then show a shallow neural network and show how to build up various different types of layers. We end the chapter by teaching TensorFlow to play tic-tac-toe via a neural network method.

Chapter 7, Natural Language Processing, illustrates various text processing techniques with TensorFlow. We show how to implement the bag-of-words technique and TF-IDF for text. We then introduce neural network text representations with CBOW and skip-gram and use these techniques for Word2Vec and Doc2Vec for making real-world predictions.

Chapter 8, Convolutional Neural Networks, expands our knowledge of neural networks by illustrating how to use neural networks on images with convolutional neural networks (CNNs). We show how to build a simple CNN for MNIST digit recognition and extend it to color images in the CIFAR-10 task. We also illustrate how to extend prior trained image recognition models for custom tasks. We end the chapter by explaining and showing the stylenet/neural style and deep-dream algorithms in TensorFlow.

Chapter 9, Recurrent Neural Networks, explains how to implement recurrent neural networks (RNNs) in TensorFlow. We show how to do text-spam prediction, and expand the RNN model to do text generation based on Shakespeare. We also train a sequence to sequence model for German-English translation. We finish the chapter by showing the usage of Siamese RNN networks for record matching on addresses.

Chapter 10, Taking TensorFlow to Production, gives tips and examples on moving TensorFlow to a production environment and how to take advantage of multiple processing devices (for example GPUs) and setting up TensorFlow distributed on multiple machines.

Chapter 11, More with TensorFlow, show the versatility of TensorFlow by illustrating how to do k-means, genetic algorithms, and solve a system of ordinary differential equations (ODEs). We also show the various uses of Tensorboard, and how to view computational graph metrics.

What you need for this book

The recipes in this book use TensorFlow, which is available at https://www.tensorflow.org/ and are based on Python 3, available at https://www.python.org/downloads/. Most of the recipes will require the use of an Internet connection to download the necessary data.

Who this book is for

The TensorFlow Machine Learning Cookbook is for users that have some experience with machine learning and some experience with Python programming. Users with an extensive machine learning background may find the TensorFlow code enlightening, and users with an extensive Python programming background may find the explanations helpful.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it…, How it works…, There's more…, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book— what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to <[email protected]>, and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/TensorFlow-Machine-Learning-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

If you are using Tableau Public, you'll need to locate the workbooks that have been published to Tableau Public. These may be found at the following link: http://goo.gl/wJzfDO.

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Getting Started with TensorFlow

In this chapter, we will cover basic recipes in order to understand how TensorFlow works and how to access data for this book and additional resources. By the end of the chapter, you should have knowledge of the following:

How TensorFlow WorksDeclaring Variables and TensorsUsing Placeholders and VariablesWorking with MatricesDeclaring OperationsImplementing Activation FunctionsWorking with Data SourcesAdditional Resources

Introduction

Google's TensorFlow engine has a unique way of solving problems. This unique way allows us to solve machine learning problems very efficiently. Machine learning is used in almost all areas of life and work, but some of the more famous areas are computer vision, speech recognition, language translations, and healthcare. We will cover the basic steps to understand how TensorFlow operates and eventually build up to production code techniques later in the book. These fundamentals are important in order to understand the recipes in the rest of this book.