Deep Learning with Structured Data 1st Edition Mark Ryan instant download
Deep Learning with Structured Data 1st Edition Mark Ryan instant download
https://textbookfull.com/product/deep-learning-with-structured-
data-1st-edition-mark-ryan/
https://textbookfull.com/product/deep-learning-with-structured-
data-1st-edition-mark-ryan-2/
https://textbookfull.com/product/machine-learning-pocket-
reference-working-with-structured-data-in-python-1st-edition-
matt-harrison/
https://textbookfull.com/product/deep-learning-innovations-and-
their-convergence-with-big-data-1st-edition-s-karthik/
https://textbookfull.com/product/advanced-data-analytics-using-
python-with-machine-learning-deep-learning-and-nlp-examples-
mukhopadhyay/
Deep Learning Pipeline: Building a Deep Learning Model
with TensorFlow 1st Edition Hisham El-Amir
https://textbookfull.com/product/deep-learning-pipeline-building-
a-deep-learning-model-with-tensorflow-1st-edition-hisham-el-amir/
https://textbookfull.com/product/deep-learning-with-python-1st-
edition-francois-chollet/
https://textbookfull.com/product/deep-learning-with-r-1st-
edition-francois-chollet/
https://textbookfull.com/product/deep-learning-with-pytorch-1st-
edition-eli-stevens/
https://textbookfull.com/product/roadside-video-data-analysis-
deep-learning-1st-edition-brijesh-verma/
Mark Ryan
MANNING
month: InputLayer
concatenate_5: Concatenate
dense: Dense
MARK RYAN
MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.
ISBN 9781617296727
Printed in the United States of America
To my daughter, Josephine,
who always reminds me that God is the Author.
brief contents
1 ■ Why deep learning with structured data? 1
2 ■ Introduction to the example problem and Pandas
dataframes 18
3 ■ Preparing the data, part 1: Exploring and cleansing the
data 45
4 ■ Preparing the data, part 2: Transforming the data 67
5 ■ Preparing and building the model 87
6 ■ Training the model and running experiments 120
7 ■ More experiments with the trained model 150
8 ■ Deploying the model 161
9 ■ Recommended next steps 192
vii
contents
preface xv
acknowledgments xvii
about this book xviii
about the author xxii
about the cover illustration xxiii
ix
x CONTENTS
xv
xvi PREFACE
xvii
about this book
This book takes you through the full journey of applying deep learning to a tabular,
structured dataset. By working through an extended, real-world example, you will
learn how to clean up a messy dataset and use it to train a deep learning model by
using the popular Keras framework. Then you will learn how to make your trained
deep learning model available to the world through a web page or a chatbot in Face-
book Messenger. Finally, you will learn how to extend and improve your deep learning
model, as well as how to apply the approach shown in this book to other problems
involving structured data.
xviii
ABOUT THIS BOOK xix
■
Chapter 2 explains the development environments you can use for the code
example in this book. It also introduces the Python library for tabular, struc-
tured data (Pandas) and describes the major example used throughout the rest
of the book: predicting delays on a light-rail transit system. This example is the
streetcar delay prediction problem. Finally, chapter 2 previews the details that
are coming in later chapters with a quick run through a simple example of
training a deep learning model.
■
Chapter 3 explores the dataset for the major example and describes how to deal
with a set of problems in the dataset. It also examines the question of how much
data is required to train a deep learning model.
■
Chapter 4 covers how to address additional problems in the dataset and what to
do with bad values that remain in the data after all the cleanup. It also shows
how to prepare non-numeric data to train a deep learning model. Chapter 4
wraps up with a summary of the end-to-end code example.
■
Chapter 5 describes the process of preparing and building the deep learning
model for the streetcar delay prediction problem. It explains the problem of
data leakage (training the model with data that won’t be available when you
want to make a prediction with the model) and how to avoid it. Then the chap-
ter walks through the details of the code that makes up the deep learning
model and shows you options for examining the structure of the model.
■
Chapter 6 explains the end-to-end model training process, from selecting sub-
sets of the input dataset to train and test the model, to conducting your first
training run, to iterating through a set of experiments to improve the perfor-
mance of the trained model.
■
Chapter 7 expands on the model training techniques introduced in chapter 6
by conducting three more in-depth experiments. The first experiment proves
that one of the cleanup steps from chapter 4 (removing records with invalid val-
ues) improves the performance of the model. The second experiment demon-
strates the performance benefit of associating learned vectors (embeddings)
with categorical columns. Finally, the third experiment compares the perfor-
mance of the deep learning model with the performance of a popular non-
deep learning approach, XGBoost.
■
Chapter 8 provides details on how you can make your trained deep learning
model useful to the outside world. First, it describes how to do a simple web
deployment of a trained model. Then it describes how to deploy a trained
model in Facebook Messenger by using the Rasa open source chatbot
framework.
■
Chapter 9 starts with a summary of what’s been covered in the book. Then it
describes additional data sources that could improve the performance of the
model, including location and weather data. Next, it describes how to adapt the
code accompanying the book to tackle a completely new problem in tabular,
structured data. The chapter wraps up with a list of additional books, courses,
xx ABOUT THIS BOOK
and online resources for learning more about deep learning with structured
data.
■
The appendix describes how you can use the free Colab environment to run
the code examples that accompany the book.
I suggest that you read this book sequentially, because each chapter builds on the con-
tent in the preceding chapters. You will get the most out of the book if you execute
the code samples that accompany the book—in particular the code for the streetcar
delay prediction problem. Finally, I strongly encourage you to exercise the experi-
ments described in chapters 6 and 7 and to explore the additional enhancements
described in chapter 9.
You can find all the code examples for this book in the GitHub repo at http://
mng.bz/v95x.
xxii
about the cover illustration
The figure on the cover of Deep Learning with Structured Data is captioned “Homme de
Navarre,” or “A man from Navarre,” a diverse northern region of northern Spain. The
illustration is taken from a collection of dress costumes from various countries by
Jacques Grasset de Saint-Sauveur (1757–1810), titled Costumes de Différents Pays, pub-
lished in France in 1797. Each illustration is finely drawn and colored by hand. The
rich variety of Grasset de Saint-Sauveur’s collection reminds us vividly of how cultur-
ally apart the world’s towns and regions were just 200 years ago. Isolated from each
other, people spoke different dialects and languages. In the streets or in the country-
side, it was easy to identify where they lived and what their trade or station in life was
just by their dress.
The way we dress has changed since then and the diversity by region, so rich at the
time, has faded away. It is now hard to tell apart the inhabitants of different conti-
nents, let alone different towns, regions, or countries. Perhaps we have traded cultural
diversity for a more varied personal life—certainly for a more varied and fast-paced
technological life.
At a time when it is hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
Grasset de Saint-Sauveur’s pictures.
xxiii
Why deep learning
with structured data?
Since 2012, we have witnessed what can only be called a renaissance of artificial
intelligence. A discipline that had lost its way in the late 1980s is important again.
What happened?
In October 2012, a team of students working with Geoffrey Hinton (a leading
academic proponent of deep learning based at the University of Toronto)
announced a result in the ImageNet computer vision contest that achieved an
error rate in identifying objects that was close to half that of the nearest competitor.
1
2 CHAPTER 1 Why deep learning with structured data?
This result exploited deep learning and ushered in an explosion of interest in the
topic. Since then, we have seen deep learning applications with world-class results in
many domains, including image processing, audio to text, and machine translation.
In the past couple of years, the tools and infrastructure for deep learning have
reached a level of maturity and accessibility that make it possible for nonspecialists to
take advantage of deep learning’s benefits. This book shows how you can use deep
learning to get insights into and make predictions about structured data: data orga-
nized as tables with rows and columns, as in a relational database. You will see the
capability of deep learning by going step by step through a complete, end-to-end
example of deep learning, from ingesting the raw input structured data to making the
deep learning model available to end users. By applying deep learning to a problem
with a real-world structured dataset, you will see the challenges and opportunities of
deep learning with structured data.
the transaction, and the currency and amount of the transaction. In addition to this
information, which is added to the table every time a transaction is reported, every
record has a field to indicate whether the transaction was reported as a fraud.
The credit card company plans to train a deep learning model on the historical
data in this table and use this trained model to predict whether new incoming transac-
tions are fraudulent. The goal is to identify potential fraud as quickly as possible (and
take corrective action) rather than waiting days for the customer or vendor to report
that a particular transaction is fraudulent.
Let’s examine the customer transaction table. Figure 1.1 contains a snippet of what
some records in this table would look like.
The columns customer ID, transaction date, transaction time, vendor ID, City,
Country, currency, and amount contain details about individual credit card
transactions for the previous quarter. The fraud column is special because it contains
the label: the value that we want the deep learning model to predict when it has been
trained on the training data. Assume that the default value in the fraud column is 0
(meaning “not a fraud”), and that when one of our customers or vendors reports a
fraudulent transaction, the value in the fraud column for that transaction in the table
is set to 1.
As new transactions arrive, we want to be able to predict whether they are fraudu-
lent so that we can quickly take corrective action. By training the deep learning model
on the historical dataset, we will be defining a function that can predict whether new
credit card transactions are fraudulent. In this example of supervised learning
(http://mng.bz/pzBE), the model is trained by means of a dataset that incorporates
examples with labels. The dataset that is used to train the model includes the value
that the trained model will predict (in this case, whether a transaction is fraudulent).
By contrast, in unsupervised learning the training dataset does not include labels.
Now that we have introduced the credit card fraud example, let’s use it to take a
brief tour of some of the concepts of deep learning. For a more in-depth description
of these concepts, see François Chollet’s Deep Learning with Python, 2nd ed.
(http://mng.bz/OvM2), which includes excellent descriptions of these concepts:
Another Random Document on
Scribd Without Any Related Topics
"Oh! Dubourg, how irritating you are! you have no idea of love!"
"Love, my friend, is a doll that everyone dresses according to his own
fancy;—isn't that so, Monsieur Ménard?"
"I cannot answer from experience, monsieur le baron."
In due time they arrived at Grenoble, where they dismissed their driver.
Their arrangements there were not the same as at Lyon; but although the
hotel was less palatial, they had an excellent table; poultry was abundant,
and the wine very good. Monsieur Ménard and Dubourg made the best of it.
On the day following their arrival, Frédéric and his companions started
off to visit the Carthusian monastery. Dubourg, having ceased to play the
grand seigneur, was quite as willing to accompany his friend as to remain
with Ménard, and the latter decided to go along, although he was a poor
walker, and Frédéric, the better to enjoy the country, proposed to go on foot.
The monastery, which they reached after half a day's walk, first appears
to the visitor surrounded by mountains covered with firs, by fertile valleys
and rich pasture lands. Approaching by Fourvoyerie, you follow a road
hewn out of the solid rock, with a rushing mountain stream on the left, and
a perpendicular cliff sixty feet high on the right. One inevitably feels an
unfamiliar sensation, a blending of wonder and alarm, at sight of that wild
landscape.
They stopped to examine the peak called L'Aiguille, which towers above
the gate of the Grande Chartreuse. Frédéric was lost in admiration, Dubourg
looked calmly at the rock, and Ménard sighed; but the hospitable welcome
they received at the Chartreuse revived the poor tutor's spirits; while he
agreed that there were many superb views in that region, he felt that he
preferred his little fourth-floor room on Rue Bétisy to the most picturesque
cell in the monastery, where, moreover, fast-days were very numerous. It is
not given to everybody to appreciate the beauties of nature; and it was with
extreme delight that Ménard started to return to Grenoble, although Frédéric
proposed that they should sleep at the Chartreuse to avoid overtiring
themselves. Ménard declared that he was not tired, and that the walk of five
leagues had no terrors for him; so they set out, after dinner.
The sun was just setting and our travellers were still four leagues from
Grenoble, because Frédéric paused every instant to call his friends' attention
to a valley, a windmill, or a lovely view. Every time that Frédéric stopped,
Ménard sat down on the turf, and they had much difficulty in inducing him
to rise again. The worthy man was not a great walker, but he summoned all
his courage and took the liberty of clinging to the arm of monsieur le baron,
who was the most good-natured fellow in the world when he was not
putting on the airs of a palatine.
Frédéric's attention was attracted by strains of rustic music.
"Come," he said, "let us go down in this direction; I see some villagers
dancing below; let us enjoy the picture of their merrymaking."
"Come on," said Dubourg; "there are probably some pretty girls among
the dancers."
"Let us go," said Ménard; "we shall have a chance to rest and refresh
ourselves."
They descended a hill into a valley bordered by oaks and firs, where
there were assembled the people of a small village which could be seen
farther up the valley. It was the local saint's day, and the peasants were
celebrating it by dancing. The orchestra consisted of a bagpipe and
tambourine, but that was quite enough for their purpose. Happiness shone
on every face; the girls wore their best gowns, and the coquettish costume
of the village maidens of that province makes them most attractive, as a
general rule. The older people were seated a little apart, chatting together
and drinking, while their children danced.
Ménard seated himself at a table, and called for refreshments. Dubourg
prowled about the dancers, making sweet speeches to the prettiest peasants;
while Frédéric, after watching the picture for some time, walked away from
the dance, along the bank of a stream which wound in and out among the
willows on the edge of a dense forest.
He had walked so far that the notes of the bagpipe hardly reached his
ears, and was about to return to his companions, when, on turning his head,
he espied, within a few paces, a young girl seated on the bank, looking
toward the valley with a bewitchingly sweet expression, and smiling at the
dance, which she could see in the distance; but there was in her smile a
tinge of melancholy which seemed to be a natural part of it. She was
apparently fifteen or sixteen years of age. Her garments indicated poverty,
but her charms made one overlook them. Beautiful fair hair played in curls
about her innocent brow, her features were refined and delicate, her mouth
graceful and smiling, and her soft blue eyes wore a pathetic expression of
gentle melancholy which harmonized with the pallor of her complexion.
Frédéric stopped and gazed at the young woman; he could not tire of
contemplating her. Why was she there, alone by the brook, while her
companions were making merry and dancing? Why that melancholy
expression? It was only a moment since Frédéric's eyes had fallen upon her,
and his interest was already awakened; he longed to know all about her; it
seemed to him that his heart already shared her sorrows.
At that moment, several couples passed along the path on their way to
the dance. Frédéric accosted a peasant woman, and said, pointing to the girl
sitting by the brook:
"Pray, who is that pretty child, and why doesn't she join in your sports?"
The villagers stopped and replied, with a compassionate glance at the
girl:
"Oh! monsieur, the poor dear don't dance! That's Sister Anne."
Frédéric, surprised, expected some further explanation; but they went on
toward the dance, repeating sadly:
"That's Sister Anne."
IX
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com