0% found this document useful (0 votes)
12 views

Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition] Sayan Mukhopadhyay download pdf

The document promotes the ebook 'Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition]' by Sayan Mukhopadhyay, available for download on ebookmeta.com. It includes links to additional recommended digital products and outlines the book's content, which covers various data analytics techniques using Python. The book is aimed at providing a comprehensive understanding of advanced data analytics concepts and practices.

Uploaded by

elvimemel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition] Sayan Mukhopadhyay download pdf

The document promotes the ebook 'Advanced Data Analytics Using Python: With Architectural Patterns, Text and Image Classification, and Optimization Techniques [2nd Edition]' by Sayan Mukhopadhyay, available for download on ebookmeta.com. It includes links to additional recommended digital products and outlines the book's content, which covers various data analytics techniques using Python. The book is aimed at providing a comprehensive understanding of advanced data analytics concepts and practices.

Uploaded by

elvimemel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Advanced Data Analytics Using Python: With


Architectural Patterns, Text and Image
Classification, and Optimization Techniques [2nd
Edition] Sayan Mukhopadhyay
https://ebookmeta.com/product/advanced-data-analytics-using-
python-with-architectural-patterns-text-and-image-
classification-and-optimization-techniques-2nd-edition-
sayan-mukhopadhyay/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Advanced Data Analytics Using Python: With Architectural


Patterns, Text and Image Classification, and Optimization
Techniques [2nd Edition] Sayan Mukhopadhyay
https://ebookmeta.com/product/advanced-data-analytics-using-python-
with-architectural-patterns-text-and-image-classification-and-
optimization-techniques-2nd-edition-sayan-mukhopadhyay/
ebookmeta.com

Advanced Analytics with Transact-SQL: Exploring Hidden


Patterns and Rules in Your Data 1st Edition Dejan Sarka

https://ebookmeta.com/product/advanced-analytics-with-transact-sql-
exploring-hidden-patterns-and-rules-in-your-data-1st-edition-dejan-
sarka/
ebookmeta.com

Advanced Analytics With Transact-SQL: Exploring Hidden


Patterns and Rules in Your Data 1st Edition Dejan Sarka

https://ebookmeta.com/product/advanced-analytics-with-transact-sql-
exploring-hidden-patterns-and-rules-in-your-data-1st-edition-dejan-
sarka-2/
ebookmeta.com

International Business Fourth Edition Yadong Luo

https://ebookmeta.com/product/international-business-fourth-edition-
yadong-luo/

ebookmeta.com
Services Liberalization in ASEAN Foreign Direct Investment
in Logistics 1st Edition Tham Siew Yean

https://ebookmeta.com/product/services-liberalization-in-asean-
foreign-direct-investment-in-logistics-1st-edition-tham-siew-yean/

ebookmeta.com

Entranced Guardian Academy 1 1st Edition Jessica Sorensen

https://ebookmeta.com/product/entranced-guardian-academy-1-1st-
edition-jessica-sorensen/

ebookmeta.com

Chocolate Truffles and Trouble Pacific Cove Cozy Mystery


03 Samantha Silver Et El

https://ebookmeta.com/product/chocolate-truffles-and-trouble-pacific-
cove-cozy-mystery-03-samantha-silver-et-el/

ebookmeta.com

Dividing up the World The true story of our international


borders and why they are where they are 1st Edition Paul
Doe
https://ebookmeta.com/product/dividing-up-the-world-the-true-story-of-
our-international-borders-and-why-they-are-where-they-are-1st-edition-
paul-doe/
ebookmeta.com

Acceptance and Commitment Skills for Perfectionism and


High-Achieving Behaviors: Do Things Your Way, Be Yourself,
and Live a Purposeful Life 1st Edition Patricia E. Zurita
Ona
https://ebookmeta.com/product/acceptance-and-commitment-skills-for-
perfectionism-and-high-achieving-behaviors-do-things-your-way-be-
yourself-and-live-a-purposeful-life-1st-edition-patricia-e-zurita-ona/
ebookmeta.com
Eloquent JavaScript 3rd Edition A Modern Introduction to
Programming Marijn Haverbeke

https://ebookmeta.com/product/eloquent-javascript-3rd-edition-a-
modern-introduction-to-programming-marijn-haverbeke/

ebookmeta.com
Advanced Data
Analytics Using
Python
With Architectural Patterns,
Text and Image Classification,
and Optimization Techniques
Second Edition

Sayan Mukhopadhyay
Pratip Samanta
Advanced Data Analytics Using Python: With Architectural Patterns, Text
and Image Classification, and Optimization Techniques

Sayan Mukhopadhyay Pratip Samanta


Kolkata, West Bengal, India Kolkota, West Bengal, India

ISBN-13 (pbk): 978-1-4842-8004-1 ISBN-13 (electronic): 978-1-4842-8005-8


https://doi.org/10.1007/978-1-4842-8005-8
Copyright © 2023 by Sayan Mukhopadhyay, Pratip Samanta
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: James Markham
Coordinating Editor: Mark Powers
Copyeditor: Kim Wimpsett
Cover designed by eStudioCalamar
Cover image by David Clode on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY
10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected],
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance
Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub (github.com/apress). For more detailed information, please visit
www.apress.com/source-­code.
Printed on acid-free paper
The reason for the success of this book is that it has original
research, so I dedicate it to the person from whom I learned
how to do research: Dr. Debnath Pal, IISc.
—Sayan Mukhopadhyay
Table of Contents
About the Authors��������������������������������������������������������������������������������xi

About the Technical Reviewer�����������������������������������������������������������xiii


Acknowledgments������������������������������������������������������������������������������xv
Introduction��������������������������������������������������������������������������������������xvii

Chapter 1: A Birds Eye View to AI System��������������������������������������������1


OOP in Python�������������������������������������������������������������������������������������������������������1
Calling Other Languages in Python���������������������������������������������������������������������13
Exposing the Python Model as a Microservice���������������������������������������������������14
High-Performance API and Concurrent Programming����������������������������������������17
Choosing the Right Database������������������������������������������������������������������������������21
Summary������������������������������������������������������������������������������������������������������������22

Chapter 2: ETL with Python����������������������������������������������������������������23


MySQL�����������������������������������������������������������������������������������������������������������������24
How to Install MySQLdb?�������������������������������������������������������������������������������24
Database Connection�������������������������������������������������������������������������������������25
INSERT Operation������������������������������������������������������������������������������������������26
READ Operation���������������������������������������������������������������������������������������������26
DELETE Operation������������������������������������������������������������������������������������������27
UPDATE Operation�����������������������������������������������������������������������������������������28
COMMIT Operation�����������������������������������������������������������������������������������������28
ROLL-BACK Operation�����������������������������������������������������������������������������������28

v
Table of Contents

Normal Forms�����������������������������������������������������������������������������������������������������31
First Normal Form�����������������������������������������������������������������������������������������31
Second Normal Form�������������������������������������������������������������������������������������32
Third Normal Form����������������������������������������������������������������������������������������33
Elasticsearch�������������������������������������������������������������������������������������������������������35
Connection Layer API�������������������������������������������������������������������������������������38
Neo4j Python Driver��������������������������������������������������������������������������������������������39
neo4j-rest-client�������������������������������������������������������������������������������������������������39
In-Memory Database������������������������������������������������������������������������������������������40
MongoDB (Python Edition)����������������������������������������������������������������������������������40
Import Data into the Collection����������������������������������������������������������������������41
Create a Connection Using pymongo�������������������������������������������������������������42
Access Database Objects������������������������������������������������������������������������������42
Insert Data�����������������������������������������������������������������������������������������������������43
Update Data���������������������������������������������������������������������������������������������������43
Remove Data�������������������������������������������������������������������������������������������������43
Cloud Databases�������������������������������������������������������������������������������������������������43
Pandas����������������������������������������������������������������������������������������������������������������44
ETL with Python (Unstructured Data)������������������������������������������������������������������45
Email Parsing�������������������������������������������������������������������������������������������������45
Topical Crawling��������������������������������������������������������������������������������������������48
Summary������������������������������������������������������������������������������������������������������������52

Chapter 3: Feature Engineering and Supervised Learning�����������������53


Dimensionality Reduction with Python���������������������������������������������������������������54
Correlation Analysis���������������������������������������������������������������������������������������55
Principal Component Analysis�����������������������������������������������������������������������57
Mutual Information����������������������������������������������������������������������������������������60
Classifications with Python���������������������������������������������������������������������������������64

vi
Table of Contents

Semi-Supervised Learning���������������������������������������������������������������������������������65
Decision Tree�������������������������������������������������������������������������������������������������������66
Which Attribute Comes First?������������������������������������������������������������������������66
Random Forest Classifier������������������������������������������������������������������������������68
Naïve Bayes Classifier�����������������������������������������������������������������������������������������68
Support Vector Machine��������������������������������������������������������������������������������������69
Nearest Neighbor Classifier��������������������������������������������������������������������������������71
Sentiment Analysis���������������������������������������������������������������������������������������������71
Image Recognition����������������������������������������������������������������������������������������������73
Regression with Python���������������������������������������������������������������������������������74
Least Square Estimation��������������������������������������������������������������������������������75
Logistic Regression���������������������������������������������������������������������������������������76
Classification and Regression�����������������������������������������������������������������������������76
Intentionally Bias the Model to Over-Fit or Under-Fit������������������������������������������77
Dealing with Categorical Data�����������������������������������������������������������������������������78
Summary������������������������������������������������������������������������������������������������������������79

Chapter 4: Unsupervised Learning: Clustering�����������������������������������81


K-Means Clustering��������������������������������������������������������������������������������������������82
Choosing K: The Elbow Method���������������������������������������������������������������������������86
Silhouette Analysis����������������������������������������������������������������������������������������������86
Distance or Similarity Measure���������������������������������������������������������������������������88
Properties������������������������������������������������������������������������������������������������������89
General and Euclidean Distance��������������������������������������������������������������������89
Squared Euclidean Distance��������������������������������������������������������������������������91
Distance Between String-Edit Distance��������������������������������������������������������91
Similarity in the Context of a Document�������������������������������������������������������������93
Types of Similarity�����������������������������������������������������������������������������������������94

vii
Table of Contents

Example of K-Means in Images��������������������������������������������������������������������������95


Preparing the Cluster�������������������������������������������������������������������������������������97
Thresholding�������������������������������������������������������������������������������������������������������99
Time to Cluster��������������������������������������������������������������������������������������������100
Revealing the Current Cluster����������������������������������������������������������������������102
Hierarchical Clustering��������������������������������������������������������������������������������������104
Bottom-Up Approach�����������������������������������������������������������������������������������104
Distance Between Clusters�������������������������������������������������������������������������105
Top-Down Approach������������������������������������������������������������������������������������107
Graph Theoretical Approach������������������������������������������������������������������������111
How Do You Know If the Clustering Result Is Good?�����������������������������������112
Summary����������������������������������������������������������������������������������������������������������113

Chapter 5: Deep Learning and Neural Networks�������������������������������115


Backpropagation�����������������������������������������������������������������������������������������������116
Backpropagation Approach�������������������������������������������������������������������������116
Other Algorithms�����������������������������������������������������������������������������������������������119
TensorFlow��������������������������������������������������������������������������������������������������������120
Network Architecture and Regularization Techniques���������������������������������124
Updatable Model and Transfer Learning������������������������������������������������������124
Recurrent Neural Network��������������������������������������������������������������������������������133
LSTM�����������������������������������������������������������������������������������������������������������134
Reinforcement Learning�����������������������������������������������������������������������������������138
TD0��������������������������������������������������������������������������������������������������������������139
TD�������������������������������������������������������������������������������������������������������������145
Example of Dialectic Learning���������������������������������������������������������������������146
Convolution Neural Networks���������������������������������������������������������������������������156
Summary����������������������������������������������������������������������������������������������������������159

viii
Table of Contents

Chapter 6: Time Series���������������������������������������������������������������������161


Classification of Variation����������������������������������������������������������������������������������161
Analyzing a Series Containing a Trend��������������������������������������������������������������161
Curve Fitting������������������������������������������������������������������������������������������������163
Removing Trends from a Time Series����������������������������������������������������������163
Analyzing a Series Containing Seasonality�������������������������������������������������������164
Removing Seasonality from a Time Series��������������������������������������������������������165
By Filtering��������������������������������������������������������������������������������������������������165
By Differencing��������������������������������������������������������������������������������������������166
Transformation��������������������������������������������������������������������������������������������������166
To Stabilize the Variance�����������������������������������������������������������������������������167
To Make the Seasonal Effect Additive���������������������������������������������������������167
To Make the Data Distribution Normal���������������������������������������������������������167
Stationary Time Series��������������������������������������������������������������������������������������168
Stationary Process��������������������������������������������������������������������������������������168
Autocorrelation and the Correlogram����������������������������������������������������������169
Estimating Autocovariance and Autocorrelation Functions�������������������������170
Time-Series Analysis with Python���������������������������������������������������������������������171
Useful Methods��������������������������������������������������������������������������������������������171
Autoregressive Processes���������������������������������������������������������������������������173
Estimating Parameters of an AR Process����������������������������������������������������175
Mixed ARMA Models�����������������������������������������������������������������������������������������177
Integrated ARMA Models�����������������������������������������������������������������������������������179
The Fourier Transform���������������������������������������������������������������������������������������181
An Exceptional Scenario�����������������������������������������������������������������������������������182
Missing Data�����������������������������������������������������������������������������������������������������183
Summary����������������������������������������������������������������������������������������������������������184

ix
Table of Contents

Chapter 7: Analytics at Scale�����������������������������������������������������������185


Hadoop��������������������������������������������������������������������������������������������������������������185
MapReduce Programming���������������������������������������������������������������������������185
Partitioning Function�����������������������������������������������������������������������������������186
Combiner Function��������������������������������������������������������������������������������������187
HDFS File System����������������������������������������������������������������������������������������197
MapReduce Design Pattern�������������������������������������������������������������������������197
A Notes on Functional Programming����������������������������������������������������������������203
Spark�����������������������������������������������������������������������������������������������������������������204
PySpark�������������������������������������������������������������������������������������������������������������207
Updatable Machine Learning and Spark Memory Model����������������������������������209
Analytics in the Cloud���������������������������������������������������������������������������������������221
Internet of Things����������������������������������������������������������������������������������������������231
Essential Architectural Patterns for Data Scientists������������������������������������231
Scenario 1: Hot Potato Anti-Pattern�������������������������������������������������������������232
Scenario 2: Proxy and Layering Patterns�����������������������������������������������������236
Thank You����������������������������������������������������������������������������������������������������������241

Index�������������������������������������������������������������������������������������������������243

x
About the Authors
Sayan Mukhopadhyay has more than 13 years
of industry experience and has been associated
with companies such as Credit Suisse, PayPal,
CA Technologies, CSC, and Mphasis. He has
a deep understanding of applications for
data analysis in domains such as investment
banking, online payments, online advertising,
IT infrastructure, and retail. His area of
expertise is in applying high-performance
computing in distributed and data-driven
environments such as real-time analysis, high-
frequency trading, and so on.
He earned his engineering degree in electronics and instrumentation
from Jadavpur University and his master’s degree in research in
computational and data science from IISc in Bangalore.

Pratip Samanta is a principal AI engineer/


researcher with more than 11 years of
experience. He has worked for several software
companies and research institutions. He has
published conference papers and has been
granted patents in AI and natural language
processing. He is also passionate about
gardening and teaching.

xi
About the Technical Reviewer
Joos Korstanje is a data scientist with more
than five years of industry experience in
developing machine learning tools, of which a
large part is forecasting models. He currently
works at Disneyland Paris where he develops
machine learning for a variety of tools.

xiii
Acknowledgments
Thanks to Labonic Chakraborty (Ripa) and Soumili Chakraborty.

xv
Introduction
We are living in the data science/artificial intelligence era. To thrive in
this environment, where data drives decision-making in everything from
business to government to sports and entertainment, you need the skills
to manage and analyze huge amounts of data. Together we can use this
data to make the world better for everyone. In fact, humans have yet to find
everything we can do using this data. So, let us explore!
Our objective for this book is to empower you to become a leader
in this data-transformed era. With this book you will learn the skills to
develop AI applications and make a difference in the world.
This book is intended for advanced user, because we have incorporated
some advanced analytics topics. Important machine learning models and
deep learning models are explained with coding exercises and real-world
examples.
All the source code used in this book is available for download at
https://github.com/apress/advanced-­data-­analytics-­python-­2e.
Happy reading!

xvii
CHAPTER 1

A Birds Eye View to


AI System
In this book, we assume that you are familiar with Python programming.
In this introductory chapter, we explain why a data scientist should choose
Python as a programming language. Then we highlight some situations
where Python may not be the ideal choice. Finally, we describe some best
practices for application development and give some coding examples that
a data scientist may need in their day-to-day job.

OOP in Python
In this section, we explain some features of object-oriented programming
(OOP) in a Python context.
The most basic element of any modern application is an object. To
a programmer or architect, the world is a collection of objects. Objects
consist of two types of members: attributes and methods. Members can be
private, public, or protected. Classes are data types of objects. Every object
is an instance of a class. A class can be inherited in child classes. Two
classes can be associated using composition.
Python has no keywords for public, private, or protected, so
encapsulation (hiding a member from the outside world) is not implicit in
Python. Like C++, it supports multilevel and multiple inheritance. Like Java,
it has an abstract keyword. Classes and methods both can be abstract.
© Sayan Mukhopadhyay, Pratip Samanta 2023 1
S. Mukhopadhyay and P. Samanta, Advanced Data Analytics Using Python,
https://doi.org/10.1007/978-1-4842-8005-8_1
Another Random Document on
Scribd Without Any Related Topics
Hester work so hard to feed me, maybe I ought not to
stay."

Billy was silent for a moment and stopped throwing sticks to


Stray. When he spoke, he said very thoughtfully, "I'm the
one to go away, not you. I'm a boy and can make my own
living."

"Oh, no, for you see you haven't any relations like my Uncle
Sidney," returned Ruth. "And, besides, who would chop the
wood and do the errands, Billy? Then if you went away, who
would keep store and buy back the big house for Aunt
Hester? It would be foolish for you to go when I have an
uncle to take care of me."

With his duties as man of the house thus brought to his


mind, Billy demurred. Perhaps after all, his place was here.

"If I only wasn't another mouth," Ruth went on, "or if I were
a dog like Stray and could live on scraps, or if I were a cat
and could catch mice."

"Then nobody would want you," said Billy.

"Indeed they would then. There are ever so many people


who like cats if you don't. Aunt Hester does and so do I and
so does Lucia. Oh dear, I should hate to give up Lucia. I
wish I ought not to go instead of oughting to go."

"Maybe you'll like it awful much," said Billy, encouragingly.


"Maybe your uncle has lots of boys and girls and you'll have
fun with them."

"No, he hasn't. He has only one little boy about five years
old. Billy, promise me on your sacred word and honor that
you will come and get me just as soon as you begin to keep
store, or, if Aunt Hester gets the claim, before that."
Billy nodded gravely. He wished it were not right to tell Ruth
that it would be best for her to leave them. He felt that he
would miss her sadly and that one small boy in the house
with a grave elderly woman would not have as agreeable a
time as when a youthful comrade like Ruth was on hand to
take an interest in small matters beneath the notice of their
elders.

Ruth had always a lively imagination and was vastly


amusing at times. To be sure, she was very often absorbed
in her doll or in Lucia Field, but, at other times, she and
Billy had most exciting plays in which she was almost as
good fun as a boy, he told her. He thought of all this now,
but his loyalty to Miss Hester and his practical bent made
him repeat:

"I guess you'll have to go, Ruth."

But Ruth had been thinking, too. "I'll go, but I'm not going
to promise to stay. I'm coming back the first chance I get. If
I find a thousand dollars that nobody wants, or if I do
something like saving a train from running off the track, and
they give me a whole lot of money for it, or if—or if—the
claim comes out all right, I'll come straight back, so I just
won't think that I'm going for good, and I am going in now
to tell Aunt Hester so."

"Don't tell her it's because you know she can't afford to
keep you," charged Billy, bluntly.

"Of course not," returned Ruth. She jumped down from her
seat and went slowly back to the house. Miss Hester was
sitting at the window of her room which looked out upon the
street. She had her lap full of little garments upon which
she was sewing a missing button here, a tape there.

"This isn't Saturday," said Ruth. "What are all these?"


She came nearer and put an arm around Miss Hester's
neck.

"They are some of Henrietta's things. I didn't know but that


you would need them," answered Miss Hester, soberly.

"Won't my uncle buy me any clothes?"

"He will probably buy all you need, but I don't want to have
you go away unprovided for. I suppose you must go, Ruth. I
should be doing you a wrong to encourage you to do
otherwise."

"I'm not going for good," returned Ruth confidently. "I am


going only for a little while till something happens. If you
get the claim, you know, or if I find a whole lot of money, I
will come back. Even if those things don't happen, Billy will
come for me as soon as he is big enough to keep store."

Miss Hester smiled faintly. "I am afraid it will be many a day


before that."

Ruth shook her head. "I'm not going to think I'll be gone
long. I will tell my uncle that I am going to stay only a little
while, that I am coming back to you and that I love you
better than him or anybody."

The feeling that this departure was in the nature of a visit


made her more cheerful. Like all children, she loved
excitement and change, and, since she had decided that
she was to return, there was only left a rather pleasant
anticipation instead of a grief.

It was well for Miss Hester that the time for preparation was
short for Mr. Mayfield could wait only another day, and so
Ruth's belongings were hastily packed. That she might
make a good appearance, the store of clothing in the chest
up-stairs was drawn forth and all of Henrietta's things that
were in good order were packed in a small trunk. Hetty, too,
was given room, and Ruth begged that her box of pieces
might go in.

"It will make me feel like home to see all my doll rugs," she
said.

And Miss Hester stowed away the box just as it was.

At the last moment, Billy, who had been struggling between


his love for Ruth and his love for Stray, came forward,
insisting that Ruth must take the little dog with her, since he
belonged half to her and could not be divided.

But, though Ruth would have liked dearly to have him, Miss
Hester decided otherwise.

"You don't know that your uncle's wife would be willing to


have a dog in the house. Indeed, I think it is quite unlikely
that she would consent to your having him, for there is the
little boy to be considered."

"I think you are awfully good, Billy, to want me to have


him," Ruth declared, "and I'd just love to take him, but, you
see, I have Hetty for company and you won't have anybody
to play with but Stray."

But Billy was determined that she should receive some


token, and, from his little hoard which he was saving up for
Christmas, he took out sufficient to buy a gayly flowered
mug upon which was written in gold letters: "From a
Friend."

Ruth thought it was beautiful and begged Miss Hester to


pack it very carefully.
"I will use it every day at table," she said.

Then, after whispering to Miss Hester, she left the room and
returned with a red silk handkerchief which Dr. Peaslee had
once brought her after a visit to the city.

"I want you to have this to remember me by," she said to


Billy, and he accepted the gift solemnly.

At last the little trunk was packed and stood waiting.

Then Ruth went to make some hurried farewell calls. To all


inquiries, she replied that she was going to her uncle's to
make a visit, but that she expected to be back soon. So
often did she repeat this that she persuaded herself it must
be true until the last moment when the possibility of its not
being merely a visit faced her, and she flung herself into
Miss Hester's arms in a passion of weeping.

"I—don't want to go. I—I don't want to go," she sobbed.

"You needn't, dear, you needn't," whispered Miss Hester


herself feeling very heavy hearted.

But just then Billy came rushing in shouting: "He's come in


a carriage, Ruth, to take you to the station."

And the dignity of such a departure for the moment caused


Ruth to check her tears. It would be a triumphant exit, she
considered. And after one last frantic hug and the
passionate reiteration, "I am coming back soon, I am, I
am," she obeyed her uncle's call and was helped into the
carriage, her trunk being already established by the side of
the driver. She waved her handkerchief from the carriage
window. Her last glimpse of the brown house showed Billy
at the gate holding up Stray for her to see. Miss Hester was
not in sight. She had gone indoors where no one would
observe her tearful eyes.

Soon the carriage turned into the main street. The children
were on their way to school, and to Ruth's satisfaction, they
passed Nora Petty, to whom Ruth gave a condescending
nod. She was riding away into new splendors where Nora
could no longer twit and tease her.

As the train moved out of the station, there came over the
child an overpowering desire to jump out and run back to
Aunt Hester who loved her, to Billy and Stray, to the little
brown house which she might never see again. The big tear
drops rolled down her cheeks. She wiped them furtively
away as she kept her head turned as if looking out the
window. Her handkerchief became a damp little ball in her
hand and the telegraph poles, as they flashed by, were seen
through a watery mist. Her uncle wisely said nothing to her
for a time, but absorbed himself in his newspaper, but,
when the train boy came along, he bought some fine fruit
and a box of chocolates saying cheerfully, "Here, little girl,
don't you want to see what is in the box?"

Her thoughts diverted in such an agreeable way, the worst


was over for Ruth and she turned to the sweets for solace.
After a while her uncle began to talk to her, to tell her of his
home, of his little boy, Bertie, and from this he went back to
his own childhood when he and Ruth's father were
playmates together. So the morning was not very long,
though Ruth was glad when she climbed down from the cars
to take luncheon at a station where they tarried for half an
hour.

It was late in the afternoon when they arrived in front of


her uncle's door. Ruth observed what to her was a very fine
house, and, when she entered the hall, she was quite
overcome, for, to her inexperienced eye, it appeared a
mansion magnificent beyond her highest expectations.

They had hardly entered before a piping voice called out:


"There's papa," and swiftly sliding down the baluster came
the figure of a little boy. He came with such speed that he
nearly fell off when he reached the big newel post, but his
father caught him.

"You rascal," he cried, "what did I tell you about doing


that?"

"It's so much the quickest way to get here, papa," said


Bertie. "What did you bring me?"

"I brought a little new cousin."

Bertie turned and regarded Ruth with anything but an


amiable expression. "I don't want her," he said. "I want
something nice. Didn't you bring me any candy?"

Mr. Mayfield looked rather abashed. "To tell you the truth,
son, I didn't," he began.

But Bertie interrupted him with a loud wail. "Mamma,


mamma," he cried, "he didn't bring me any candy and you
said he would." Then throwing himself down on the floor, he
kicked and screamed violently.

Ruth heard the swish of silken skirts and down the stairs a
lady came swiftly. She was very fair and looked quite
young. Ruth had never seen any one dressed so
wonderfully, and she stared with all her eyes at the vision.

"What is the matter with my darling?" cried the lady. "Oh,


have you come, Sidney?" She gave Ruth's uncle a cheek to
kiss. "What is my precious boy crying about?" she asked
bending over the raging child.

"Papa didn't bring me any candy and you said he would,"


howled Bertie. "You are an old—"

"There, there," began his mother gathering him into her


arms. "How could you be so forgetful of the precious child,
Sidney?" she said reproachfully.

"Well, you see, Lillie, I had so much to think of. Oh, by the
way, Ruth, this is your Aunt Lillie. Did you get my telegram,
dear?"

"Oh, yes, it came all right, of course," replied Mrs. Mayfield


petulantly. "You ought to have given me more notice."

"How could I? My letter explained why."

Ruth stood awkwardly by. She had not received a very


warm welcome, for Mrs. Mayfield only nodded and said
coolly, "How do you do, little girl?"

Bertie's howls continued.

"I wish I had something to give the child to pacify him,"


muttered Mr. Mayfield who saw that no one would receive
much attention until Bertie's fit of rage was over.

He turned apologetically to Ruth. "You don't happen to have


any candy, do you?" he whispered.

Ruth promptly produced the box of chocolates which was


but half empty. She had been so much more abundantly fed
than usual that she had not been able to eat all the candy.
"Just give them to Bertie," whispered Mr. Mayfield, "and I
will get you some more."

Ruth obediently slipped the box into his hand and he gave
her a smile.

"Here, Bertie," he said, "see what Cousin Ruth has for you.
Papa didn't bring you any candy, but Cousin Ruth did."

At this Bertie rushed from his mother's embrace and


grabbed the box from his father's hand.

"'Tain't but, half full," he whined. Then turning, he gave


Ruth a push. "You mean old fing," he cried, "why didn't you
bring me a whole box?"

"Now, Bertie," said his mother, "that's not a pretty way to


talk. I am sure you ought to say, 'Thank you,' to your
cousin. Won't you say, 'Thank you'?"

"No, I won't," returned Bertie, beginning to gobble down


some of the chocolates as fast as he could.

Ruth was shocked. Such an ill-mannered child she had


never seen. She felt mightily ashamed for him.

"I suspect Ruth is rather tired," said Mr. Mayfield. "You'd


better show her to her room, Lillie."

For answer, Mrs. Mayfield touched an electric button and a


neat maid appeared. "Take Miss Ruth to her room," said the
lady, "and help her dress for dinner, Katie."

Ruth followed the girl up three flights of stairs, catching


glimpses on the way of rooms whose elegant furnishings
seemed to her fit for a palace. At the top of the house, she
was ushered into a hall bedroom, comfortably, even prettily,
furnished. It looked out upon the street, but it seemed to
Ruth, accustomed to her little room adjoining Aunt Hester's,
a long way off from any one, and she wondered if she would
not feel afraid up there. She timidly asked Katie who had
the next room.

"Nobody, miss," was the reply. "It's one of the spare rooms,
but it ain't often used except when there's more company
than common. But I sleep just down the hall in one of the
back rooms."

This was comforting and Ruth felt relieved. The trunk


having now arrived, Katie fell to unpacking it. She smiled at
the old-fashioned clothes, but made no remark, being too
well-trained a servant for that. She selected Ruth's very
best frock, a cream-white delaine with small Persian figures
upon it. The frock was trimmed with an old-fashioned gimp,
heading a narrow fringe, but its quaintness suited Ruth and
she looked very presentable, Katie thought, as she led her
down-stairs when a soft-toned Japanese gong announced
that dinner was ready.

CHAPTER X
Homesick

IN spite of such luxuries as Ruth had never before enjoyed,


and the fact that there was little restraint put upon her, she
did not feel in her new home a real content.
After a week it was decided that she should not go to
school, Mrs. Mayfield insisting upon a governess who could
give some attention to Bertie. One was found who suited
the lady but to whom Ruth took a dislike at first sight, and
never thereafter did she feel comfortable when Mlle.
Delarme's sharp eyes were fixed upon her. Lessons in
French and music were those upon which Mademoiselle laid
the most stress, the rest amounted to little.

Mademoiselle was sly and put forth her best efforts to


please Mrs. Mayfield, and, consequently, made much of
Bertie. Ruth, though well clothed and fed, starved for those
things which she craved. She longed for her Aunt Hester's
loving notice and appreciation. She sighed for Billy's bluff
companionship, and she was very, very lonely. Her uncle
was absorbed in business and she saw him seldom. He
always gave her a kind smile when they met, asked if she
were well, and if she needed anything and there the interest
ended.

On several different occasions, he had given her money,


telling her to spend it on whatever she liked, but she, with a
wise frugality, had saved nearly every penny till her hoard
amounted to nearly five dollars. At Christmas she would
perhaps spend it to send home gifts to those she truly
loved.

Mrs. Mayfield was fond of society and was rarely at home


unless to entertain some guest. The children had their
meals in the nursery with Mademoiselle, took their drives
and walks with her, and although Bertie would not be kept
within bounds and frequented any part of the house at will,
Ruth rarely went beyond the confines of the nursery. She
still had her little hall bedroom, and Mademoiselle was now
given a room upon the same floor, though Ruth would have
preferred her to be elsewhere.
"J'ai, tu as, il a," crooned Ruth one afternoon as she sat in
the nursery, studying a lesson.

"Oh dear, I don't want to study French," she sighed. "It


won't be a bit of use to me, for when I grow up I shall go
back to Springdale. I may go sooner than that. None of the
girls there will learn French. Well, perhaps Lucia will if she
goes away to boarding-school, and perhaps Nora might. I
reckon after all I'd better study it, for Nora might get ahead
of me and say things to Lucia that I couldn't understand."

So she bent herself again to her task. "J'ai, tu as, il a. Nous


avons, vous avez, ils ont." Her eyes wandered from her
book.

She looked out of the window to where a pair of sparrows


were fussing and quarreling on a twig near-by. There was
little else to be seen but roofs and chimneys, a church spire
in the distance and a line of fence enclosing back yards. Her
eyes returned to her book.

"J'ai, tu as, il a. I think I know that. Now those horrid


exercises. Why should I care anything about the brother of
his aunt? It doesn't make any difference to me whether she
has a gold shoe or not. French is so silly. We never talk
about such things."

At this moment, she heard Bertie's hurrying step upon the


stair and presently he came dancing into the room crying:
"Ya! Ya! Ya! I've got it."

Ruth looked up quickly to catch sight of Bertie jumping


around the room holding aloft her precious Hetty. She
sprang to her feet in an instant and snatched the doll away.
Bertie flew at her in a transport of rage, but she held the
doll tightly though he kicked and yelled.
The commotion brought Mrs. Mayfield who chanced to be at
home. "What is it, precious?" she cried as she entered the
room.

"Ruth won't let me have that old doll and I'm going to get
it, I am. I'll smash it all to pieces," cried Bertie, dancing up
and down in a fury.

"Why don't you let him have it, Ruth?" said Mrs. Mayfield.
"I'll get you a better one."

"I don't want a better one," replied Ruth, fiercely. "I don't
want any but this. There isn't another like her and you
couldn't get me one that would be half so dear."

"Well, I am sure you are very disobliging," said Mrs.


Mayfield. "Never mind, Bertie, if you want a doll to play with
mother will get you one much prettier than this."

"Don't want it. Want one to smash," cried Bertie.

"Oh, but you don't want to smash Ruth's doll, do you?"


asked his mother in a coaxing tone.

"Yes, I do, I do. It's ugly and I'm going to. Make her give it
to me, mamma."

"Do give it to him, Ruth," continued Mrs. Mayfield. "I will


give you a much handsomer one. You shall go down-town
with Mademoiselle and choose any you want."

But Ruth held steadfastly to her own. "I don't want any
other and I couldn't give this away to be broken up," she
said. "She's the only one of the family I have here to
remind me of my home, and I can't give her up."
Whereupon, Bertie burst into screams of anger and
disappointment, flinging himself upon the floor in one of his
fits of temper.

"After all your uncle has done for you, I think it is a very
little thing to ask," said Mrs. Mayfield in an offended way,
addressing Ruth. Then meeting no response, she took a
different tone. "You must give it to him, Ruth. I wish you to
obey me."

"Oh, Aunt Lillie, I can't." The tears came into Ruth's eyes as
she held Hetty more tightly.

"I command you," returned Mrs. Mayfield, haughtily, and


then all Ruth's defiance was aroused.

"I won't," she said. Then she started for the door. "I reckon
you wouldn't give your child either, to be torn to pieces by a
—by a—wicked Thing," she cried as she reached the door.

She hurried up-stairs feeling that here was an occasion


which did not demand obedience, yet frightened at her
speech. There was not a day when she was not called upon
to give up something to Bertie, to sacrifice her pleasures,
her time, her possessions to his whims.

"He is younger than you," was always the plea, and Ruth,
though not always with a good grace, yielded the point. But
here was an issue which she felt was a different one from
any that she had been called upon to meet.

"It isn't right; it isn't," she said over and over to herself as
she climbed the stairs. "Aunt Hester wouldn't make me do
it. I know she wouldn't. Why Aunt Hester loves Hetty and
Dr. Peaslee does and Billy, and—why they would think it as
bad as throwing a baby to the crocodiles like a heathen
mother. I'll have to hide you, Hetty darling, like Moses in
the bulrushes or like they had to hide the babies from
wicked old Herod. Bertie is just like Herod, so he is. I don't
love him one bit, and I am going to write to Aunt Hester,
and tell her all about it. Oh, where can I hide you, my
darling Hetty, so the wicked evil foe will not seek you?"

Bertie's screams still ascended from the floor below and


Ruth could hear his mother trying to comfort him.

"Did that naughty Ruth tease my baby? Wouldn't she let


him have the ugly old doll? Never mind, mamma will let
Katie take him down-town and get him something nice.
What does baby want?"

"Want Ruth's doll," persisted Bertie.

"Oh, but wouldn't you like some nice candy and a pretty
toy? Let Katie dress you and take you out to get you
something nice? We won't get Ruth anything, will we? She
shall not go with you and Katie."

Ruth's lip curled as she heard this. "Silly talk," she


murmured. She had no great respect for her Aunt Lillie.

At last Bertie was pacified and was led away by the long-
suffering nurse while Ruth remained in her room.

Mademoiselle was out for the afternoon, and when she had
completed the task the governess had set her to do, she
would be free to do as she chose.

Bertie seldom descended upon Ruth, and indeed, she was


careful to have nothing within reach of his mischievous
fingers, but to-day she had left Hetty sitting upon the bed
and Bertie had discovered her. It would never do to leave
her anywhere in sight again, nor could she keep her where
an older person than Bertie might find her. Ruth did not
trust Mademoiselle, and believed if Bertie persisted in
wanting the doll, as he was very likely to do, that
Mademoiselle would not hesitate to find Hetty and give her
into the little boy's ruthless hands.

She closed her door softly and looked around the room for a
hiding-place. None seemed possible at first, but at last Ruth
discovered a safe one. A small window seat had been placed
before the one window. It opened and shut like a box.
Between the back of this box and the wall under the window
there was a space over which a small board had been
placed to cover the space which was caused by a slight
jutting out of the window, making an irregular opening.
Ruth found that she could lift the board, shove it back in
place and cover it again with the cushion of the seat. She
gave Hetty a loving kiss and stowed her away in this
retreat.

"You mustn't be afraid, dearest," she said. "Nothing shall


hurt you. I shall not let anything smite you by day nor by
night. I'll pray that the angels will watch over you just as
much as if they could see you in bed with me. I shall take
you out every day and lock my door so we won't be
disturbed."

And she went back to her French exercises with a cheerful


face. When she had completed them, she heard the clamor
of Bertie's return and ran back to her room.

Her aunt treated her with cold disdain when they next met
and Ruth gave her head a little defiant toss.

"If she 'spises me, I reckon I can 'spise her," she told
herself, and more than ever she kept out of the way.

She had been in her aunt's rooms but seldom, though the
magnificence of them charmed her. On the dressing-table
were such beautiful shining things; the soft couch was piled
high with wonderfully embroidered cushions, and the whole
place was always redolent with some faint sweet odor. The
costumes which Mrs. Mayfield wore, too, were such as Ruth
thought fit for a queen. Once or twice she had seen her
sweeping down the stairway in exquisite evening dress and
she wondered what Nora Petty would say if she knew Ruth
were living in the same house as such a fairylike being.

Although she gave a wondering admiration to all the


beautiful things with which her Aunt Lillie surrounded
herself, Ruth gave her aunt no affection, for she did not
demand it. She treated the child with tolerance but that was
all. Bertie occupied the only place which she had in her
heart for children, and him she spoiled and petted till all
natural good in his nature was smothered by indulgence.

Bertie did not forgot the doll in spite of the candy and the
new toy with which his mother had provided him, and the
very next day he climbed the stairs to the top floor bent on
finding Hetty. It was sufficient for Bertie to be denied a
thing for him to want it beyond anything else. He looked
around the room. No doll was in sight, but on Ruth's
washstand stood the little flowery mug, Billy's parting gift.
Possessing himself of this, he went down to the nursery
where Ruth was reciting her "J'ai, tu as, il a."

"I want Ruth's doll," he said to Mademoiselle.

"He can't have it," returned Ruth quickly.

Mademoiselle looked sharply at her. "Vy not, mees?"

"Because he only wants it to break up and I can't have her


smashed all to pieces."
"I want to play wif her. Mayn't I play wif her?" whined
Bertie.

"You may play wis har, of course. Go get zis doll, zis poupée
but say first what is doll. It is poupée, poupée. Repeat."

"Poupée, poupée," repeated Ruth obediently.

"Say, zen to your cousin, 'I give you my doll—Je vous donne
ma poupée.' Repeat."

But Ruth did not repeat. Instead she stood silent.

Mademoiselle's little eyes snapped. "Repeat, I say. At once;


toute de suite. Je vous donne ma poupée."

"I can't," replied Ruth in a low tone. "I would be telling a


story, because I am not going to give him my doll."

"You are not when I say?" Mademoiselle sprang to her feet.


"You sall, you mees, I make you."

Ruth faced her, very pale. "What will you do?" she asked
slowly.

"I punish you."

"Then I will tell my uncle and I will ask him, too, if I must
give my precious doll to Bertie to break up. I will tell him all
about my Hetty and I know he will not make me give her
up."

"You meeserable leetle mouse, you souris which pretend so


shy and meek and have the viciousness of a rat, you sall
not defy me, Antoinette Delarme."

Just at this moment, Bertie entered, having taken his cause


into his own hands. "You'd better give me your old doll," he
threatened, holding behind him the mug which he had
brought from Ruth's room. "You'd just better or you'll be
sorry."

"I shall not do it," said Ruth steadily.

For answer Bertie dashed out in the hall, held aloft the mug
for a moment and then flung it down over the baluster. It
went crashing into a hundred bits upon the marble tiling in
the hall below. Having thus spent his fury, Bertie dashed
away with an impish look over his shoulder.

Ruth flew down-stairs without a word from Mademoiselle.


The butler was sweeping up the broken pieces.

"Oh, Martin," said Ruth, "it is my dear little mug. Bertie got
it from my room and threw it down here. Can it be mended,
do you think?"

With a grim smile Martin showed the pieces.

The tears came to Ruth's eyes. "And Billy bought it for me


with his own money," she said, her lips quivering at the
remembrance. "Oh, Martin, please let me have one little
flowery piece to keep," she said.

The man held out the dust-pan and Ruth selected a piece
upon which a rose still showed entire. "I'll keep this
forever," she said. "Thank you, Martin."

The man shook his head as he looked after her making her
way to the upper floor. "That spoiled young un," he
muttered. "I'd just like to see him get one good spanking."

Mademoiselle sat up stiff and uncompromising when Ruth


returned to the nursery. "Babee," she said contemptuously,
as she perceived Ruth's tears. "What is it to weep for, a
leetle cheap sumpsin as zat?"

"It wasn't because I thought it was very fine," said Ruth,


"but it was because Billy gave it to me. I was going to drink
my milk from it at the table, but I saw it looked funny with
the other things and so I kept it in my room. Bertie knew I
loved it."

"He is but an infant," returned Mademoiselle, "but because


he have bestowed upon you a punishment, I will not more
punish you for the disobeying me except that I make you a
longer lesson to-morrow. You are repeat all the verb To
Have, all, all."

"Oh, Mademoiselle, it will take me every minute to learn it."

"All, all," repeated Mademoiselle with a wave of her hand as


dismissing the subject.

And Ruth, with a rebellious feeling in her heart, went to her


task.

She listened that evening for her uncle's latchkey, hiding


herself behind the heavy curtains of the library.

As his step rang upon the tiled floor, she went to meet him.

"Well, Ruthie," he said kindly, "are you the only one at


home?"

"Aunt Lillie has gone to a tea," she replied, "and I don't


know where Bertie is. Uncle Sidney, do I have to give him
my doll?"

"Your doll? Bertie doesn't play with dolls, does he?"

You might also like