100% found this document useful (16 votes)
121 views

Instant download Supervised Learning with Python: Concepts and Practical Implementation Using Python Vaibhav Verdhan pdf all chapter

Python

Uploaded by

orimihirwan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (16 votes)
121 views

Instant download Supervised Learning with Python: Concepts and Practical Implementation Using Python Vaibhav Verdhan pdf all chapter

Python

Uploaded by

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

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Supervised Learning with Python: Concepts and


Practical Implementation Using Python Vaibhav
Verdhan

https://textbookfull.com/product/supervised-learning-with-
python-concepts-and-practical-implementation-using-python-
vaibhav-verdhan/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


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

Supervised Learning with Python Concepts and Practical


Implementation Using Python 1st Edition Vaibhav Verdhan

https://textbookfull.com/product/supervised-learning-with-python-
concepts-and-practical-implementation-using-python-1st-edition-
vaibhav-verdhan/
textboxfull.com

Computer Vision Using Deep Learning Neural Network


Architectures with Python and Keras 1st Edition Vaibhav
Verdhan
https://textbookfull.com/product/computer-vision-using-deep-learning-
neural-network-architectures-with-python-and-keras-1st-edition-
vaibhav-verdhan/
textboxfull.com

Mastering Machine Learning with Python in Six Steps: A


Practical Implementation Guide to Predictive Data
Analytics Using Python 1st Edition Manohar Swamynathan
(Auth.)
https://textbookfull.com/product/mastering-machine-learning-with-
python-in-six-steps-a-practical-implementation-guide-to-predictive-
data-analytics-using-python-1st-edition-manohar-swamynathan-auth/
textboxfull.com

Machine Learning Concepts with Python and the Jupyter


Notebook Environment: Using Tensorflow 2.0 Nikita
Silaparasetty
https://textbookfull.com/product/machine-learning-concepts-with-
python-and-the-jupyter-notebook-environment-using-
tensorflow-2-0-nikita-silaparasetty/
textboxfull.com
Practical Machine Learning for Data Analysis Using Python
1st Edition Abdulhamit Subasi

https://textbookfull.com/product/practical-machine-learning-for-data-
analysis-using-python-1st-edition-abdulhamit-subasi/

textboxfull.com

Advanced Data Analytics Using Python: With Machine


Learning, Deep Learning and NLP Examples Mukhopadhyay

https://textbookfull.com/product/advanced-data-analytics-using-python-
with-machine-learning-deep-learning-and-nlp-examples-mukhopadhyay/

textboxfull.com

Practical Python Data Visualization: A Fast Track Approach


To Learning Data Visualization With Python Ashwin Pajankar

https://textbookfull.com/product/practical-python-data-visualization-
a-fast-track-approach-to-learning-data-visualization-with-python-
ashwin-pajankar/
textboxfull.com

Deep Learning with Python Develop Deep Learning Models on


Theano and TensorFLow Using Keras Jason Brownlee

https://textbookfull.com/product/deep-learning-with-python-develop-
deep-learning-models-on-theano-and-tensorflow-using-keras-jason-
brownlee/
textboxfull.com

Learning Data Mining with Python Layton

https://textbookfull.com/product/learning-data-mining-with-python-
layton/

textboxfull.com
Supervised
Learning with
Python
Concepts and Practical
Implementation Using Python

Vaibhav Verdhan
Foreword by Dr. Eli Yechezkiel Kling (PhD)
Supervised Learning
with Python
Concepts and Practical
Implementation Using Python

Vaibhav Verdhan
Foreword by Dr. Eli Yechezkiel Kling (PhD)
Supervised Learning with Python: Concepts and Practical
Implementation Using Python

Vaibhav Verdhan
Limerick, Ireland

ISBN-13 (pbk): 978-1-4842-6155-2 ISBN-13 (electronic): 978-1-4842-6156-9


https://doi.org/10.1007/978-1-4842-6156-9

Copyright © 2020 by Vaibhav Verdhan


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: Shrikant Vishwakarma
Cover designed by eStudioCalamar
Cover image designed by Pexels
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201)
348-4505, e-mail orders-ny@springer-sbm.com, 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 booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
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 http://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 via the book’s product page, located at www.apress.com/
978-1-4842-6155-2. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
To Yashi, Pakhi and Rudra.
Table of Contents
About the Author���������������������������������������������������������������������������������xi
About the Technical Reviewer�����������������������������������������������������������xiii
Foreword��������������������������������������������������������������������������������������������xv
Acknowledgments����������������������������������������������������������������������������xvii
Introduction���������������������������������������������������������������������������������������xix

Chapter 1: Introduction to Supervised Learning�����������������������������������1


What Is ML?����������������������������������������������������������������������������������������������������������2
Relationship Between Data Analysis, Data Mining, ML, and AI������������������������3
Data, Data Types, and Data Sources����������������������������������������������������������������5
How ML Differs from Software Engineering��������������������������������������������������������10
ML Projects����������������������������������������������������������������������������������������������������12
Statistical and Mathematical Concepts for ML���������������������������������������������������15
Supervised Learning Algorithms�������������������������������������������������������������������������25
Regression vs. Classification Problems���������������������������������������������������������28
Steps in a Supervised Learning Algorithm����������������������������������������������������30
Unsupervised Learning Algorithms���������������������������������������������������������������������34
Cluster Analysis���������������������������������������������������������������������������������������������35
PCA����������������������������������������������������������������������������������������������������������������36
Semi-supervised Learning Algorithms����������������������������������������������������������������37
Technical Stack���������������������������������������������������������������������������������������������������37

v
Table of Contents

ML’s Popularity����������������������������������������������������������������������������������������������������39
Use Cases of ML�������������������������������������������������������������������������������������������������41
Summary������������������������������������������������������������������������������������������������������������44

Chapter 2: Supervised Learning for Regression Analysis������������������47


Technical Toolkit Required����������������������������������������������������������������������������������48
Regression analysis and Use Cases��������������������������������������������������������������������49
What Is Linear Regression����������������������������������������������������������������������������������51
Assumptions of Linear Regression����������������������������������������������������������������56
Measuring the Efficacy of Regression Problem��������������������������������������������������59
Example 1: Creating a Simple Linear Regression������������������������������������������68
Example 2: Simple Linear Regression for Housing Dataset���������������������������71
Example 3: Multiple Linear Regression for Housing Dataset�������������������������78
Nonlinear Regression Analysis����������������������������������������������������������������������������84
Identifying a Nonlinear Relationship�������������������������������������������������������������������88
Assumptions for a Nonlinear Regression������������������������������������������������������89
Challenges with a Regression Model������������������������������������������������������������������91
Tree-Based Methods for Regression�������������������������������������������������������������������94
Case study: Petrol consumption using Decision tree������������������������������������������98
Ensemble Methods for Regression�������������������������������������������������������������������103
Case study: Petrol consumption using Random Forest�������������������������������������106
Feature Selection Using Tree-Based Methods��������������������������������������������������110
Summary����������������������������������������������������������������������������������������������������������113

Chapter 3: Supervised Learning for Classification Problems�����������117


Technical Toolkit Required��������������������������������������������������������������������������������118
Hypothesis Testing and p-Value������������������������������������������������������������������������118
Classification Algorithms����������������������������������������������������������������������������������121
Logistic Regression for Classification���������������������������������������������������������124

vi
Table of Contents

Assessing the Accuracy of the Solution������������������������������������������������������������129


Case Study: Credit Risk�������������������������������������������������������������������������������������136
Additional Notes������������������������������������������������������������������������������������������149
Naïve Bayes for Classification���������������������������������������������������������������������������150
Case Study: Income Prediction on Census Data�����������������������������������������������154
k-Nearest Neighbors for Classification�������������������������������������������������������������163
Case Study: k-Nearest Neighbor�����������������������������������������������������������������������169
The Dataset�������������������������������������������������������������������������������������������������170
Business Objective��������������������������������������������������������������������������������������170
Tree-Based Algorithms for Classification����������������������������������������������������������178
Types of Decision Tree Algorithms��������������������������������������������������������������������182
Summary����������������������������������������������������������������������������������������������������������188

Chapter 4: Advanced Algorithms for Supervised Learning���������������191


Technical Toolkit Required��������������������������������������������������������������������������������192
Boosting Algorithms������������������������������������������������������������������������������������������193
Using Gradient Boosting Algorithm��������������������������������������������������������������198
SVM�������������������������������������������������������������������������������������������������������������������208
SVM in 2-D Space����������������������������������������������������������������������������������������210
KSVM�����������������������������������������������������������������������������������������������������������213
Case Study Using SVM��������������������������������������������������������������������������������215
Supervised Algorithms for Unstructured Data��������������������������������������������������221
Text Data�����������������������������������������������������������������������������������������������������������222
Use Cases of Text Data��������������������������������������������������������������������������������223
Challenges with Text Data���������������������������������������������������������������������������226
Text Analytics Modeling Process�����������������������������������������������������������������228
Text Data Extraction and Management��������������������������������������������������������230

vii
Table of Contents

Preprocessing of Text Data��������������������������������������������������������������������������233


Extracting Features from Text Data�������������������������������������������������������������236
Case study: Customer complaints analysis using NLP��������������������������������������243
Word Embeddings���������������������������������������������������������������������������������������246
Case study: Customer complaints analysis using word embeddings���������������248
Image Data��������������������������������������������������������������������������������������������������������252
Use Cases of Image Data�����������������������������������������������������������������������������253
Challenges with Image Data������������������������������������������������������������������������256
Image Data Management Process���������������������������������������������������������������258
Image Data Modeling Process���������������������������������������������������������������������260
Fundamentals of Deep Learning�����������������������������������������������������������������������261
Artificial Neural Networks���������������������������������������������������������������������������261
Activation Functions������������������������������������������������������������������������������������265
Loss Function in a Neural Network�������������������������������������������������������������268
Optimization in a Neural Network����������������������������������������������������������������268
Neural Network Training Process����������������������������������������������������������������272
Case Study 1: Create a Classification Model on Structured Data����������������������276
Case Study 2: Image Classification Model��������������������������������������������������������281
Summary����������������������������������������������������������������������������������������������������������287

Chapter 5: End-to-End Model Development��������������������������������������291


Technical Toolkit Required��������������������������������������������������������������������������������292
ML Model Development������������������������������������������������������������������������������������292
Step 1: Define the Business Problem����������������������������������������������������������������294
Step 2: Data Discovery Phase���������������������������������������������������������������������������296
Step 3: Data Cleaning and Preparation�������������������������������������������������������������301
Duplicates in the Dataset����������������������������������������������������������������������������302
Categorical Variable Treatment in Dataset���������������������������������������������������304
Missing Values Present in the Dataset��������������������������������������������������������307

viii
Table of Contents

Imbalance in the Dataset����������������������������������������������������������������������������������316


Outliers in the Dataset��������������������������������������������������������������������������������������321
Other Common Problems in the Dataset�����������������������������������������������������������325
Step 4: EDA�������������������������������������������������������������������������������������������������������328
Step 5: ML Model Building��������������������������������������������������������������������������������335
Train/Test Split of Data��������������������������������������������������������������������������������336
Finding the Best Threshold for Classification Algorithms����������������������������342
Overfitting vs. Underfitting Problem������������������������������������������������������������343
Key Stakeholder Discussion and Iterations�������������������������������������������������350
Presenting the Final Model��������������������������������������������������������������������������350
Step 6: Deployment of the Model����������������������������������������������������������������������351
Step 7: Documentation��������������������������������������������������������������������������������������363
Step 8: Model Refresh and Maintenance����������������������������������������������������������363
Summary����������������������������������������������������������������������������������������������������������364

Index�������������������������������������������������������������������������������������������������367

ix
About the Author
Vaibhav Verdhan has 12+ years of experience
in data science, machine learning, and
artificial intelligence. An MBA with
engineering background, he is a hands-on
technical expert with acumen to assimilate
and analyze data. He has led multiple
engagements in ML and AI across geographies
and across retail, telecom, manufacturing,
energy, and utilities domains. Currently
he resides in Ireland with his family and is
working as a Principal Data Scientist.

xi
About the Technical Reviewer
Irfan Elahi is a full stack customer-focused
cloud analytics specialist bearing the unique
and proven combination of diverse consulting
and technical competencies (cloud, big
data, and machine learning) with a growing
portfolio of successful projects delivering
substantial impact and value in multiple
capacities across telecom, retail, energy,
and health-care sectors. Additionally, he is
an analytics evangelist as is evident from
the published book, Udemy courses, blogposts, trainings, lectures, and
presentations with global reach.

xiii
Foreword
How safe is home birthing? That is a good question. Pause a moment and
let yourself contemplate it.
I am sure you can see how the answer to this question can affect
personal decisions and policy choices. The answer could be given as a
probability, a level classification, or an alternative cost. Another natural
reaction is “it depends.” There are many factors that could affect the safety
of home birthing.
I took you through this thought exercise to show you that you naturally
think like a data scientist. You understood the importance of stipulating
clearly the focus of the analysis and what could explain different outcomes.
The reason you are embarking on a journey through this book is that you
are not sure how to express these instinctive notions mathematically and
instruct a computer to “find” the relationship between the “Features” and
the “Target.”
When I started my career 30-odd years ago, this was the domain
of statisticians who crafted a mathematical language to describe
relationships and noise. The purpose of predictive modeling was in its
essence to be a tool for separating a signal or a pattern out of seemingly
chaotic information and reporting how well the partition was done.
Today, machine learning algorithms harnessing computing brute force
add a new paradigm. This has created a new profession: the data scientist.
The data scientist is a practitioner who can think in terms of statistical
methodology, instruct a computer to carry out the required processing,
and interpret the results and reports.

xv
Foreword

Becoming a good data scientist is a journey that starts with learning the
basics and mechanics. Once you are done exploring this book you might
also be able to better see where you will want to deepen your theoretical
knowledge. I would like to suggest you might find it interesting to look into
the theory of statistical modeling in general and the Bayesian paradigm
specifically. Machine learning is computational statistics after all.
Dr. Eli. Y. Kling (BSc. Eng. MSc. PHD) London, UK. June 2020.

xvi
Acknowledgments
I would like to thank Apress publications, Celestin John, Shrikant
Vishwarkarma, and Irfan Elahi for the confidence shown and the support
extended. Many thanks to Dr. Eli Kling for the fantastic forward to the
book. Special words for my family—Yashi, Pakhi, and Rudra—without their
support it would have been impossible to complete this work.

xvii
Introduction
“It is tough to make predictions, especially about the future.”
—Yogi Berra

In 2019, MIT’s Katie Bouman processed five petabytes of data to develop


the first-ever image of a black hole. Data science, machine learning, and
artificial intelligence played a central role in this extraordinary discovery.
Data is the new electricity, and as per HBR, data scientist is the
“sexiest” job of the 21st century. Data is fueling business decisions and
making its impact felt across all sectors and walks of life. It is allowing us
to create intelligent products, improvise marketing strategies, innovate
business strategies, enhance safety mechanisms, arrest fraud, reduce
environmental pollution, and create path-breaking medicines. Our
everyday life is enriched and our social media interactions are more
organized. It is allowing us to reduce costs, increase profits, and optimize
operations. It offers a fantastic growth and career path ahead, but there is a
dearth of talent in the field.
This book attempts to educate the reader in a branch of machine
learning called supervised learning. This book covers a spectrum of
supervised learning algorithms and respective Python implementations.
Throughout the book, we are discussing building blocks of algorithms,
their nuts and bolts, mathematical foundations, and background process.
The learning is complemented by developing actual Python code from
scratch with step-by-step explanation of the code.

xix
Introduction

The book starts with an introduction to machine learning where


machine learning concepts, the difference between supervised, ­
semi-­supervised, and unsupervised learning approaches, and practical
use cases are discussed. In the next chapter, we examine regression
algorithms like linear regression, multinomial regression, decision tree,
random forest, and so on. It is then followed by a chapter on classification
algorithms using logistic regression, naïve Bayes, knn, decision tree, and
random forest. In the next chapter, advanced concepts of GBM, SVM, and
neural network are studied. We are working on structured data as well
as text and image data in the book. Pragmatic Python implementation
complements the understanding. It is then followed by the final chapter on
end-to-end model development. The reader gets Python code, datasets,
best practices, resolution of common issues and pitfalls, and pragmatic
first-hand knowledge on implementing algorithms. The reader will be able
to run the codes and extend them in an innovative manner, as well as will
understand how to approach a supervised learning problem. Your prowess
as a data science enthusiast is going to get a big boost, so get ready for
these fruitful lessons!
The book is suitable for researchers and students who want to
explore supervised learning concepts with Python implementation. It
is recommended for working professionals who yearn to stay on the
edge of technology, clarify advanced concepts, and get best practices
and solutions to common challenges. It is intended for business leaders
who wish to gain first-hand knowledge and develop confidence while
they communicate with their teams and clientele. Above all, it is meant
for a curious person who is trying to explore how supervised learning
algorithms work and who would like to try Python.
Stay blessed, stay healthy!
—Vaibhav Verdhan
Limerick,
Ireland. June 2020

xx
CHAPTER 1

Introduction to
Supervised Learning
“The future belongs to those who prepare for it today.”
— Malcom X

The future is something which always interests us. We want to know


what lies ahead and then we can plan for it. We can mold our business
strategies, minimize our losses, and increase our profits if we can predict
the future. Predicting is traditionally intriguing for us. And you have just
taken the first step to learning about predicting the future. Congratulations
and welcome to this exciting journey!
You may have heard that data is the new oil. Data science and machine
learning (ML) are harnessing this power of data to generate predictions for
us. These capabilities allow us to examine trends and anomalies, gather
actionable insights, and provide direction to our business decisions. This
book assists in developing these capabilities. We are going to study the
concepts of ML and develop pragmatic code using Python. You are going
to use multiple datasets, generate insights from data, and create predictive
models using Python.
By the time you finish this book, you will be well versed in the concepts
of data science and ML with a focus on supervised learning. We will
examine concepts of supervised learning algorithms to solve regression

© Vaibhav Verdhan 2020 1


V. Verdhan, Supervised Learning with Python,
https://doi.org/10.1007/978-1-4842-6156-9_1
Chapter 1 Introduction to Supervised Learning

problems, study classification problems, and solve different real-life case


studies. We will also study advanced supervised learning algorithms and
deep learning concepts. The datasets are structured as well as text and
images. End-to-end model development and deployment process are
studied to complete the entire learning.
In this process, we will be examining supervised learning algorithms,
the nuts and bolts of them, statistical and mathematical equations and the
process, what happens in the background, and how we use data to create
the solutions. All the codes use Python and datasets are uploaded to a
GitHub repository (https://github.com/Apress/supervised-learning-­
w-python) for easy access. You are advised to replicate those codes
yourself.
Let’s start this learning journey.

What Is ML?
When we post a picture on Facebook or shop at Amazon, tweet or watch
videos on YouTube, each of these platforms is collecting data for us. At
each of these interactions, we are leaving behind our digital footprints.
These data points generated are collected and analyzed, and ML allows
these giants to make logical recommendations to us. Based on the genre
of videos we like, Netflix/YouTube can update our playlist, what links we
can click, and status we can react to; Facebook can recommend posts to us,
observing what type of product we frequently purchase; and Amazon can
suggest our next purchase as per our pocket size! Amazing, right?
The short definition for ML is as follows: “In Machine Learning, we
study statistical/mathematical algorithms to learn the patterns from the
data which are then used to make predictions for the future.”
And ML is not limited to the online mediums alone. Its power has been
extended to multiple domains, geographies, and use cases. We will be
describing those use cases in detail in the last section of this chapter.

2
Chapter 1 Introduction to Supervised Learning

So, in ML, we analyze vast amounts of data and uncover the patterns in it.
These patterns are then applied on real-world data to make predictions
for the future. This real-world data is unseen, and the predictions will help
businesses shape their respective strategies. We do not need to explicitly
program computers to do these tasks; rather, the algorithms take the
decisions based on historical data and statistical models.
But how does ML fit into the larger data analysis landscape? Often,
we encounter terms like data analysis, data mining, ML, and artificial
intelligence (AI). Data science is also a loosely used phrase with no
exact definition available. It will be a good idea if these terms are
explored now.

 elationship Between Data Analysis, Data


R
Mining, ML, and AI
Data mining is a buzzword nowadays. It is used to describe the process of
collecting data from large datasets, databases, and data lakes, extracting
information and patterns from that data, and transforming these insights
into usable structure. It involves data management, preprocessing,
visualizations, and so on. But it is most often the very first step in any data
analysis project.
The process of examining the data is termed data analysis. Generally,
we trend the data, identify the anomalies, and generate insights using
tables, plots, histograms, crosstabs, and so on. Data analysis is one of the
most important steps and is very powerful since the intelligence generated
is easy to comprehend, relatable, and straightforward. Often, we use
Microsoft Excel, SQL for EDA. It also serves as an important step before
creating an ML model.
There is a question quite often discussed—what is the relationship
between ML, AI, and deep learning? And how does data science fit in?
Figure 1-1 depicts the intersections between these fields. AI can be

3
Chapter 1 Introduction to Supervised Learning

thought of as automated solutions which replace human-intensive tasks.


AI hence reduces the cost and time consumed as well as improving the
overall efficiency.

$XWRPDWLRQ6ROXWLRQV
$UWLILFLDO
,QWHOOLJHQFH

0DFKLQH
/HDUQLQJ

&ODVVLF 'DWD6FLHQFH
0DFKLQH/HDUQLQJ
'HHS
/HDUQLQJ

1HXUDO1HWZRUNV

Figure 1-1. Relationship between AI, ML, deep learning, and data
science shows how these fields are interrelated with each other and
empower each other

Deep learning is one of the hottest trends now. Neural networks are
the heart and soul of deep learning. Deep learning is a subset of AI and ML
and involves developing complex mathematical models to solve business
problems. Mostly we use neural networks to classify images and analyze
text audio and video data.
Data science lies at the juxtaposition of these various domains. It
involves not only ML but also statistics understanding, coding expertise
and business acumen to solve business problems. A data scientist’s job
is to solve business problems and generate actionable insights for the
business. Refer to Table 1-1 to understand the capabilities of data science
and its limitations.

4
Chapter 1 Introduction to Supervised Learning

Table 1-1. Data Science: How Can It Help Us, Its Usages, and
Limitations
How data science can help Limitations of data science
Assist in making decisions by analyzing multi
dimensional data which is quite difficult for a Data is not an alternative to experience
human being
Use statistical tools & techniques to uncover Data science cannot replace the subject matter
patterns knowledge
Data science depends on data availability and
The algorithms further help in measuring the
data quality. Depending on the input,we will get
accuracy of the patterns & the claims
the output
Data science will not increase the revenue or
The results are reproducible and can be improved sales or output by 50% overnight. Similarly, it will
not decrease the cost by 1/3 immediately
The machine learns, which is a big difference A data science project takes time to be
-from the traditional software engineering implemented

With the preceding discussion, the role of ML and its relationship with
other data-related fields should be clear to you. You would have realized by
now that “data” plays a pivotal role in ML. Let’s explore more about data,
its types and attributes.

Data, Data Types, and Data Sources


You already have some understanding of data for sure. It will be
a good idea to refresh that knowledge and discuss different types
of datasets generated and examples of it. Figure 1-2 illustrates the
differentiation of data.

5
Chapter 1 Introduction to Supervised Learning

Figure 1-2. Data can be divided between structured and unstructured.


Structured data is easier to work upon while generally deep learning
is used for unstructured data

Data is generated in all the interactions and transactions we do.


Online or offline: we generate data every day, every minute. At a bank,
a retail outlet, on social media, making a mobile call: every interaction
generates data.
Data comes in two flavors: structured data and unstructured data.
When you make that mobile call to your friend, the telecom operator
gets the data of the call like call duration, call cost, time of day, and so on.
Similarly, when you make an online transaction using your bank portal,
data is generated around the amount of transaction, recipient, reason
of transaction, date/time, and so on. All such data points which can be
represented in a row-column structure are called structured data. Most of
the data used and analyzed is structured. That data is stored in databases
and servers using Oracle, SQL, AWS, MySQL, and so on.

6
Chapter 1 Introduction to Supervised Learning

Unstructured data is the type which cannot be represented in a row-­


column structure, at least in its basic format. Examples of unstructured
data are text data (Facebook posts, tweets, reviews, comments, etc.),
images and photos (Instagram, product photos), audio files (jingles,
recordings, call center calls), and videos (advertisements, YouTube posts,
etc.). All of the unstructured data can be saved and analyzed though. As
you would imagine, it is more difficult to analyze unstructured data than
structured data. An important point to be noted is that unstructured
data too has to be converted into integers so that the computers can
understand it and can work on it. For example, a colored image has
pixels and each pixel has RGB (red, green, blue) values ranging from 0
to 255. This means that each image can be represented in the form of
matrices having integers. And hence that data can be fed to the computer
for further analysis.

Note We use techniques like natural language processing, image


analysis, and neural networks like convolutional neural networks,
recurrent neural networks, and so on to analyze text and image data.

A vital aspect often ignored and less discussed is data quality. Data
quality determines the quality of the analysis and insights generated.
Remember, garbage in, garbage out.
The attributes of a good dataset are represented in Figure 1-3.
While you are approaching a problem, it is imperative that you spend
a considerable amount of time ascertaining that your data is of the
highest quality.

7
Chapter 1 Introduction to Supervised Learning

Figure 1-3. Data quality plays a vital role in development of an


ML solution; a lot of time and effort are invested in improving
data quality

We should ensure that data available to us conforms to the following


standards:

• Completeness of data refers to the percentage of


available attributes. In real-world business, we find
that many attributes are missing, or have NULL or NA
values. It is advisable to ensure we source the data
properly and ensure its completeness. During the
data preparation phase, we treat these variables and
replace them or drop them as per the requirements. For
example, if you are working on retail transaction data,
we have to ensure that revenue is available for all or
almost all of the months.

8
Chapter 1 Introduction to Supervised Learning

• Data validity is to ensure that all the key performance


indicators (KPI) are captured during the data
identification phase. The inputs from the business
subject matter experts (SMEs) play a vital role in
ensuring this. These KPIs are calculated and are
verified by the SMEs. For example, while calculating the
average call cost of a mobile subscriber, the SME might
suggest adding/deleting few costs like spectrum cost,
acquisition cost, and so on.

• Accuracy of the data is to make sure all the data points


captured are correct and no inconsistent information
is in our data. It is observed that due to human error
or software issues, sometimes wrong information is
captured. For example, while capturing the number of
customers purchasing in a retail store, weekend figures
are mostly higher than weekdays. This is to be ensured
during the exploratory phase.

• Data used has to be consistent and should not vary


between systems and interfaces. Often, different
systems are used to represent a KPI. For example, the
number of clicks on a website page might be recorded
in different ways. The consistency in this KPI will
ensure that correct analysis is done, and consistent
insights are generated.

• While you are saving the data in databases and tables,


often the relationships between various entities and
attributes are not consistent or worse may not exist.
Data integrity of the system ensures that we do not face
such issues. A robust data structure is required for an
efficient, complete, and correct data mining process.

9
Chapter 1 Introduction to Supervised Learning

• The goal of data analytics is to find trends and


patterns in the data. There are seasonal variations,
movements with respect to days/time and events,
and so on. Sometimes it is imperative that we capture
data of the last few years to measure the movement
of KPIs. The timeliness of the data captured has to be
representative enough to capture such variations.

Most common issues encountered in data are missing values,


duplicates, junk values, outliers, and so on. You will study in detail how to
resolve these issues in a logical and mathematical manner.
By now, you have understood what ML is and what the attributes
of good-quality data are to ensure good analysis. But still a question is
unanswered. When we have software engineering available to us, why do
we still need ML? You will find the answer to this question in the following
section.

How ML Differs from Software Engineering


Software engineering and ML both solve business problems. Both
interact with databases, analyze and code modules, and generate outputs
which are used by the business. The business domain understanding is
imperative for both fields and so is the usability. On these parameters,
both software engineering and ML are similar. However, the key
difference lies in the execution and the approach used to solve the
business challenge.
Software writing involves writing precise code which can be executed
by the processor, that is, the computer. On the other hand, ML collects
historical data and understands trends in the data. Based on the trends,
the ML algorithm will predict the desired output. Let us look at it with an
easy example first.

10
Chapter 1 Introduction to Supervised Learning

Consider this: you want to automate the opening of a cola can. Using
software, you would code the exact steps with precise coordinates and
instructions. For that, you should know those precise details. However,
using ML, you would “show” the process of opening a can to the system
many times. The system will learn the process by looking at various steps
or “train” itself. Next time, the system can open the can itself. Now let’s
look at a real-life example.
Imagine you are working for a bank which offers credit cards. You
are in the fraud detection unit and it is your job to classify a transaction
as fraudulent or genuine. Of course, there are acceptance criteria like
transaction amount, time of transaction, mode of transaction, city of
transaction, and so on.
Let us implement a hypothetical solution using software; you might
implement conditions like those depicted in Figure 1-4. Like a decision
tree, a final decision can be made. Step 1: if the transaction amount is
below the threshold X, then move to step 2 or else accept it. In step 2,
the transaction time might be checked and the process will continue
from there.

Figure 1-4. Hyphothetical software engineering process for a fraud


detection system. Software engineering is different from ML.

11
Chapter 1 Introduction to Supervised Learning

However using ML, you will collect the historical data comprising past
transactions. It will contain both fraudulent and genuine transactions.
You will then expose these transactions to the statistical algorithm and
train it. The statistical algorithm will uncover the relationship between
attributes of the transaction with its genuine/fraud nature and will keep
that knowledge safe for further usage.
Next time, when a new transaction is shown to the system, it will
classify it fraudulent or genuine based on the historical knowledge it
has generated from the past transactions and the attributes of this new
unseen transaction. Hence, the set of rules generated by ML algorithms are
dependent on the trends and patterns and offer a higher level of flexibility.
Development of an ML solution is often more iterative than software
engineering. Moreover, it is not exactly accurate like software is. But ML is
a good generalized solution for sure. It is a fantastic solution for complex
business problems and often the only solution for really complicated
problems which we humans are unable to comprehend. Here ML plays a
pivotal role. Its beauty lies in the fact that if the training data changes, one
need not start the development process from scratch. The model can be
retrained and you are good to go!
So ML is undoubtedly quite useful, right! It is time for you to
understand the steps in an ML project. This will prepare you for a deeper
journey into ML.

M
 L Projects
An ML project is like any other project. It has a business objective to be
achieved, some input information, tools and teams, desired accuracy
levels, and a deadline!
However, execution of an ML project is quite different. The very first
step in the ML process is the same, which is defining a business objective
and a measurable parameter for measuring the success criteria. Figure 1-5
shows subsequent steps in an ML project.

12
Chapter 1 Introduction to Supervised Learning

RIWKHWLPHJRHVWR'DWD'LVFRYHU\DQG'DWD3UHSDUDWLRQSKDVHDORQH

   


Figure 1-5. An ML project is like any other project, with various steps
and process. Proper planning and execution are required for an ML
project like any other project.

The subsequent steps are

1. Data discovery is done to explore the various data


sources which are available to us. Dataset might be
available in SQL server, excel files, text or .csv files,
or on a cloud server.

2. In the data mining and calibration stage, we extract


the relevant fields from all the sources. Data is
properly cleaned and processed and is made
ready for the next phase. New derived variables
are created and variables which do not have much
information are discarded.

3. Then comes the exploratory data analysis or EDA


stage. Using analytical tools, general insights are
generated from the data. Trends, patterns, and

13
Another Random Scribd Document
with Unrelated Content
"There's a dash about that fellow that's fine!" remarked Trafford to Von
Hügelweiler, who was standing near him, wrapped during inaction in a big
military ulster.

The Captain of the Guides had already in his own mind ruled
Schmolder out of the competition, exaggerating his faults to himself with
egotistical over-keenness. Einstein, however, was skating so brilliantly that
Von Hügelweiler was beginning to experience the deepest anxiety lest he
should prove the ultimate winner of the coveted trophy. The anxiety indeed
was so deep that he refused to admit it even to himself.

"Wait till we come to the second part of the competition—the free-


skating," he retorted. "Free-skating requires great nerve, great endurance,
and absolute fitness. It is there that Einstein will fail."

When Einstein had finished his compulsory figures amid a round of


applause, Von Hügelweiler slipped off his long ulster. For a moment a bad
attack of stage-fright assailed him,—for there is nothing quite so nerve-
racking as a skating competition before a critical judge and an equally
critical audience,—and his heart was turned to water and his knees trembled
with a veritable ague; but a cheer of encouragement restored him to himself,
and he struck out for glory. With head erect, expanded chest, arms
gracefully disposed, and knee slightly bent, he was about as pretty an
exponent of Continental skating as one could wish to see. He travelled
rapidly and easily on a firm edge, his turns were crispness itself, the
elegance of his methods was patent to the least initiated.

General Meyer following slowly with note-book in hand, smiled


appreciatively, as he jotted down the marks gained from time to time by his
brilliant "counters," "brackets," and "rocking turns." The crowd roared their
applause, and in the music of their cheers, Von Hügelweiler's depression
vanished, and his heart sang an answering pæan of jubilee. Like most
nervous, self-centred men, he most excelled before an audience when once
the initial fear had worn off. And now he was skating as he had never
skated before, with a dash, energy, and precision that drew redoubled cheers
from the spectators and audible applause from the royal box. Even Meyer,
he reflected, with all his malice, could hardly dare to give another the prize
now; to do so would be not merely to violate justice, but to insult the
intelligence of every man and woman on the ice.

At the conclusion of his effort, Trafford congratulated the Captain


warmly on his performance. Von Hügelweiler's dark eyes shone bright with
pleasure. Already he saw himself crowned with the invisible laurels of
undying fame, receiving the massive silver trophy from the royal hands.

"Thanks, my American friend," he said, heartily, "go on and prosper."

With a few bold strokes Trafford started on his attempt to do superbly


what others had done faultlessly. His style instantly arrested attention. Here
was no lithe figure full of lissom vitality and vibrant suppleness; no
graceful athlete whose arms and legs seemed ever ready to adopt fresh and
more elegant poses. But here was an exponent of the ultra-English school, a
rigid, braced figure travelling over the ice like an automaton on skates, an
upright, inflexible form, sailing along on a perfect edge at an amazing
speed, with a look of easy contempt on his face alike for the difficulties of
his art and the opinion of his watchers.

Ever and again there was an almost imperceptible flick of the ankle, a
slight shifting of the angle of the shoulders, and some difficult turn had
been performed, and he was travelling away in a slightly different direction
at a slightly increased rate of speed. The crowd watched intently, but with
little applause. They felt that it was wonderful, but they did not particularly
admire.

To Von Hügelweiler,—trained as he was in the theory and practice of


the "Continental" school,—the performance seemed stiff and ugly.

"Mein Gott," cried Einstein, "at what a speed he travels!"

"He wants a bigger rink than the Rundsee!" exclaimed Schmolder. "A
man like that should have the Arctic Ocean swept for him."

Von Hügelweiler was less complimentary.


"I don't think we need fear the American, my friends," he said. "He
skates his figures fast and big, but with the grace of a dummy. Such
stiffness is an insult to the Rundsee, which is the home of elegant skating.
See with what a frowning face General Meyer follows this American
about!"

"If you can learn anything from Meyer's face," said Captain Einstein
drily, "you should give up the army and go in for diplomacy."

"Wait till he comes to the free-skating!" went on Von Hügelweiler.


"That needs a man with joints and ligaments—not a poker. Our friend will
find himself placed last, I fear; and I am sorry, for he has come a long way
for his skating, and he seems an excellent fellow. I will say a few words of
encouragement to him."

But Trafford had just then momentarily retired from the rink. He was
changing his skates for the pair he had bought at Frau Krabb's the previous
evening.

At the free-skating, which followed, Franz Schmolder broke down


altogether. His knee failed him when he had performed for three minutes
instead of the necessary five. Einstein, who followed, did well up to a point.
But five minutes' free-skating is a fairly severe test of condition, and the
big, burly soldier did not finish with quite the dash and energy he had begun
with. Von Hügelweiler, however, gave another splendid display of effective
elegance, and again drew resounding cheers for his vigorous and attractive
performance. He himself made no doubt now that he was virtually the
winner of the King's Cup. He had worked hard for his success, and was
already beginning to feel the glow that comes from honourable effort
generously rewarded. Meyer would doubtless be sorry to have to place him
first, but in the face of Einstein's and Schmolder's comparative failure, and
the American's stiffness, no other course would be open to him. Von
Hügelweiler, however, watched Trafford's free-skating with interest,
dreading, with an honest and generous dread, lest his amiable rival should
disgrace himself. To his astonishment, Trafford was no longer a petrified
piece of anatomy skating with frozen arms and arthritic legs. He beheld
instead an exponent of the Continental school, who seemed to have in his
repertoire a whole armoury of fanciful figures and astounding tours de
force. Trafford was as free and unrestrained now as he had been severe and
dignified before. Graceful, lissom, filled with an inexhaustible,
superabundant energy, he performed prodigies of whirling intricacy, dainty
pirouettings, sudden bold leaps, swift changes of edge, all with such
masterful daring and complete success that the whole ring of spectators
cheered itself hoarse with enthusiasm.

"Bravo! bravo!" cried Von Hügelweiler, clapping him heartily on the


back at the conclusion of his effort. "It is good to see skating like that! If
you had skated the preliminary figures with the same zeal you have
displayed just now, we Grimlanders would have to deplore the departure of
a national trophy from our native land."

Trafford accepted the left-handed compliment in silence, lighting a


cigarette while General Meyer totted up the amount of marks he had
awarded to the several competitors. After a few minutes' calculation,—and
after his figures had been checked by a secretary,—the General skated back
to the front of the royal box and announced his decision to the King. Then,
at a word from his Majesty, a gentleman in a blue and yellow uniform
placed a gigantic megaphone to his lips, and turning it to the various
sections of the crowd, announced:—

"The King's Prize: the winner is Herr George Trafford; second, Captain
Ulrich Salvator von Hügelweiler."

The American received the announcement with complete outward


calmness. And yet those hoarsely spoken words had touched a chord in his
heart that he had believed snapped and irrevocably broken. For a moment
he lived, for a moment the cheers of his fellow men had galvanised into
healthy activity the dead brain that had lost interest in all things under the
sun. The success itself was a trivial affair, yet in a magic moment he had
become reconciled to life and its burden, vaguely thankful that he had kept
the first barrel of his revolver free from powder and ball.

"Congratulations, Herr Trafford," said General Meyer, who now


approached him with proffered hand. "Escort me, I beg, to his Majesty, who
will present you with the cup. You will also receive a royal command to
dine to-morrow night at the Palace."
"Congratulations, Herr Trafford," said another voice.

Trafford looked round and beheld the competitor who had been placed
second. The tone of the felicitation was one of undisguised bitterness, the
face of the speaker was the ashen face of a cruelly disappointed man. And
Von Hügelweiler, honestly believing himself cheated of his due,—and not
bearing to see another receive the prize which he felt should have been his,
—slunk from the scene with hate and misery and all uncharitableness in his
tortured soul. Then, as he took off his skates, the cheering broke out again,
and told that the American was receiving the trophy from the King's hand.
An ejaculation of bitterness and wrath burst from his lips.

Hardly had he breathed his angry word into the frosty air when a small
hand plucked at his fur-lined coat, and looking round he perceived a
charming little face gazing into his own.

"Why so cross, Captain?'" asked the interrupter of his execration.

Captain von Hügelweiler's hand went up to the salute.

"Your Royal High——"

"Hush! you tactless man," said the Princess Gloria, for it was no other.
"Do you want to have me arrested? For the sake of old times," she went on,
putting her arm in his, "I claim your protection."

But Hügelweiler had not thought of delivering the exiled Princess to the
authorities! For one thing, his mind was too occupied with self-pity to have
room for State interests; secondly, he was still in love with the fascinating
creature who looked up at him so appealingly, that he would sooner have
killed himself than betrayed the appeal of those wondrous eyes.

They were strolling away from the Rundsee in the direction of the town,
and a straggling multitude of the spectators was streaming behind them in
the snowy Thiergarten.

Von Hügelweiler's lips trembled a little.


"It is good to see you again, Princess," he whispered. "It is comforting,
just when I need comfort."

"Comfort!" echoed his companion with a grimace. "You were swearing,


Ulrich! You are a good sportsman, you should take defeat with better
grace."

"I can accept open defeat, Princess, like a man, though I had set my
heart on the prize. But I was not fairly beaten. The American skated his
figures as ungracefully as they could be skated."

"Why, he skated marvellously," declared the Princess enthusiastically. "I


never saw such speed and daring on the ice. The man must have been born
with skates on. I never saw a finer——"

"Nonsense!" broke in the irate Captain, forgetting both manners and


affection in the extremity of his wrath. "He won because General Meyer
had a grudge against me. He asked me last night to do a dirty piece of work.
In the name of loyalty he wished me to murder a civilian; but I am a Von
Hügelweiler, not an assassin, and I refused, though I knew that by so doing
I was ruining my chances of success to-day."

The Princess Gloria pressed his arm sympathetically.

"The King's service frequently involves dirty work," she said, looking at
him out of the corner of her eyes.

"So it appears!"

"Why not embrace a service that calls for deeds of valour, and leads to
high honour?"

Von Hügelweiler looked at the bright young face that now was gazing
into his so hopefully. A thousand memories of a youthful ardour, born
amidst the suns and snows of Weissheim, rushed into his kindling heart. He
had lost the King's Cup; might he not wipe out the bitter memory of defeat
by winning something of incomparably greater value? There was a price, of
course; there always was, it seemed. Last night it was the honour of a clean
man; to-day it was loyalty to his King. But how much greater the present
bribe than that offered by the Commander-in-Chief! The intoxication of
desire tempted him, tempted him all the more shrewdly because of his
recent depression. What had he to do with a career that was tainted with
such a head as the scheming Jew, Meyer? What loyalty did he owe to a man
served by such officers and such method as was Karl? The Princess's eyes
repeated their question, and their silent pleading shook him as no words
could have done.

"What service?" he asked falteringly.

"My service," was the hushed retort.

"And the reward?" he demanded.

"Honour."

"And—love?"

There was silence momentary, but long enough for the forging of a lie.

"Perhaps," she breathed, looking down coquettishly.

A great light shone in the Captain's eyes, and the sombre beauty of his
face was illumined by a mighty joy.

"Princess Gloria," he cried, "I am yours to the death!"

CHAPTER SIXTH

"WEIN, WEIB, UND GESANG"


That evening Mr. and Mrs. Robert Saunders were George Trafford's
guests in a private room of the Hôtel Concordia. In the centre of the dining
table stood a big silver trophy of considerable value and questionable
design. As soon as the soup had been served, Trafford solemnly poured out
the contents of a champagne bottle into its capacious depths. He then
handed it to Mrs. Saunders.

"Felicitations," she said, taking the trophy in both hands, "I drink to St.
Liedwi, the patron saint of skaters, coupled with the name of George
Trafford, winner of the King's Cup."

Saunders was the next to take the prize in his hands.

"I drink a health unto their Majesties, King Edward of England and
King Karl of Grimland, and to the President of the United States," he said;
and then bowing to his host, "Also to another good sportsman, one Nervy
Trafford. God bless 'em all!"

Trafford received the cup from Saunders, his lips muttered something
inaudible, and tossing back his head he drank deep.

"What was your toast, Mr. Trafford?" demanded Mrs. Saunders quietly.

The winner of the cup shook his head sagely.

"That is a secret," he replied.

"A secret! But I insist upon knowing," returned the lady. "Tell me, what
was your toast?"

Trafford hesitated a moment.

"I toasted 'Wein, Weib, und Gesang,'" he announced at length.

"Wine, woman, and song!" repeated Mrs. Saunders. "A mere abstract
toast, which you would have confessed to at once. Please particularise?"

"The 'wine,'" said Trafford, "is the wine of champagne, which we drink
to-night, '89 Cliquot. 'Woman,' is Eve in all her aspects and in all countries
—Venus victrix, sea-born Aphrodite, Astarte of the Assyrians, Kali of the
Hindoos. God bless her! God bless all whom she loves and all who love
her!"

"And the song?" demanded Saunders.

"The song is the one I have heard one hundred and fifty times since I
have been here," replied Trafford. "Its title is unknown to me, but the
waiters hum it in the passages, the cabmen chant it from their box seats, the
street-boys whistle it with variations in the Bahnhofstrasse."

"That sounds like the Rothlied," said Saunders. "It is a revolutionary


air."

"I like it enormously," said Trafford.

"Of course you would," said Saunders. "You have the true Grimlander's
love of anarchy. But if you wish, we will subsequently adjourn to the Eden
Theatre of Varieties in the Karlstrasse. I am told that the Rothlied is being
sung there by a beautiful damsel of the aristocratic name of Schmitt."

"I have seen her posters," said Trafford, "and I should like, I confess, to
see the original. But what of Mrs. Saunders? Is the 'Eden' a respectable
place of entertainment?"

"It is an Eden of more Adams than Eves," said Mrs. Saunders. "No, I do
not propose to follow you into its smoky, beer-laden atmosphere. I am
going to accompany Frau generalin von Bilderbaum to the opera to hear 'La
Bohême.' But before I leave I want further enlightenment on the subject of
your toast. 'Wein' is all right, and 'Gesang' is all right, but what about
'Weib'? I thought you had sworn off the sex."

"Sworn off the sex!—Never! True, I offered to one individual my heart,


and hand, and soul; but the individual deemed the offering unsatisfactory. I
now offer to the whole female race what I once offered to one member of
it."

"Polygamist!" laughed Saunders.


"No," explained Trafford, "it's a case of first come, first served."

"You are offering your heart and hand and soul to the first eligible
maiden who crosses your path?" asked Mrs. Saunders, with upraised brows.

"My heart and hand," corrected Trafford with great dignity.

"Come, come," Saunders broke forth, "it's time we were off!"

* * * * *

The auditorium of the Eden Theatre was a long oblong chamber, with a
crude scheme of decoration, and no scheme of ventilation worth speaking
about. It possessed, however, a good orchestra, an excellent brew of lager
beer, and usually presented a tolerably attractive show to the public of
Weidenbruck. For the sum of four kronen per head Saunders and Trafford
obtained the best seats in the building. For the expenditure of a further
trivial sum they obtained long tumblers of the world-famed tigerbräu.

"A promising show this," said Trafford, lighting a large cigar. An


exceedingly plump lady in magenta tights, was warbling a patriotic ditty to
the tune of "Won't you come home, Bill Bailey?"

"More quantity than quality," commented Saunders cynically.


"Personally,—not being possessed of your all-embracing enthusiasm for
womanhood at large,—I find myself looking forward to the next item on the
programme."

"What's that? The 'Rothlied'?"

"No. Midgets."

Trafford uttered an exclamation of disgust.

"Little things amuse little minds," he said rudely. "Give me a strong


man or a giant, and I will watch with interest."

At this point the curtain descended on the plump warbler, and a


powdered attendant in plush knickerbockers removed the number 7 from
the wings, and substituted the number 9.

"Oh, it isn't the midgets yet, after all," said Saunders, consulting his
programme. "It's the Schöne Fräulein Schmitt—the beautiful Miss Smith. I
wonder if she's as lovely as her posters."

As the curtain drew up again, a young girl tripped lightly on to the


middle of the stage, and it was at once manifest that the epithet "schone"
was no mere advertising euphemism.

Her black skirt was short, her black bodice low, and her black picture
hat exceedingly large, but her limbs were shapely, her eyes marvellously
bright though small, and there was a vivacity and grace in her movements
that put her predecessor to shame. When she sang, her voice proved to be a
singularly pure soprano, and,—what was more remarkable,—gave evidence
of considerable taste and sound training. The song was a dainty one, all
about a young lady called Nanette, who conquered all hearts till she met
someone who conquered hers. And then, of course, Nanette lost her art, as
well as her heart, and could make no impression on the only man who had
really touched the deeps of her poor little soul. The last verse, naturally, was
a tragedy,—the usual tragedy of the smiling face and the aching bosom. The
idea was not exactly a novel one, but the air was pretty, and the singer's
personality won a big success from the commonplace theme. Anyway, the
audience rose to her, and there was much clapping of hands, clinking of
beer glasses, and guttural exclamations of enthusiasm.

"Bravo!" cried Trafford ecstatically, "Bravo! Bravissimo! Behold an


artist among artistes, a fairy of the footlights! Bravo! Well done, beautiful
Miss Schmitt!"

"Charming," agreed Saunders more calmly, "and, strangely enough,


extraordinarily like a young lady I met a few years ago."

"Perhaps it is the young lady," suggested Trafford. "I noticed she fixed
her beady black eyes on you during the last verse."

"I think not," said Saunders drily. "The young lady I was referring to
was a somewhat more exalted personage than Fräulein Schmitt."
The fascinating songstress re-appeared for her encore, and this time the
orchestra struck up a martial air with a good deal of rolling drums in it.

"My 'Gesang,'" whispered Trafford excitedly.

"The 'Rothlied,'" said Saunders.

Again the Fräulein sang, and now the burthen of her song was of
battlefields and war's alarms. The tune was vastly inspiriting, and the
audience knew it well, taking up the chorus with infectious enthusiasm.

"It's great!" muttered Trafford, twirling excitedly at his moustaches. "By


the living Jingo, it's great!"

And of a truth the air was an intoxicating one. There was gunpowder in
it, musketry and cold steel, reckless charges and stern movements of
advance. One caught the thunder of hoofs and the blare of bugles. Its
infection became imperious, maddening even,—for the audience forgot
their pipes and their tigerbräu, and beat time to the insistent rhythm, till the
chorus gave them a chance of imparting their enthusiasm to the roaring
refrain. The girl herself seemed the embodiment of martial ardour. She trod
the stage like a little war-horse, her eye sought the gallery and struck fire
from the beer-loving bourgeoisie. For a second her gaze seemed to fall upon
Saunders mockingly, and with an air of challenge. Then she glanced round
the crowded house, held it spellbound, lifted it up, carried it to high regions
of carnage, self-sacrifice, and glory. The audience roared, clapped,
screamed with exuberant acclaim. Their state was frénétique—no other
word, French, English, or German, well describes it.

"By George, she's a witch!" said Trafford. "She's as dangerous as a time


fuse. I'll be hanged if I don't want to fight someone!"

The encore verse was more pointed, more sinister, less general in its
application. It spoke of wrongs to be righted, tyranny to be overcome,
freedom to be gained. It hinted of an uplifting of the proletariat, of armed
citizens and frenzied women, of tumult in square and street; it breathed of
barricades and civic strife, the vast upheaval of a discontented people
determined to assert their rights. Men looked at each other and stirred
uneasily in their seats, and then glanced round in apprehension,—as if
expecting the entrance of the police. The song was a veritable
"Marseillaise," a trumpet call to revolution, a match in a barrel of
gunpowder; and with the final chorus and the stirring swing of the refrain,
all remnants of prudence and restraint were cast to the winds. The house
rose en masse; men mounted their seats and waved sticks and umbrellas
aloft; a party of young officers drew their swords and brandished them with
wild insurgent cries. Forbidden names were spoken, cheers were raised for
popular outlaws and suspects, groans for unpopular bureaucrats and the
King's favourites. It was an intoxicating moment,—whatever one's
sympathies might be,—and it was obvious enough that the temper of the
people was frankly revolutionary, and that the authorities would be quite
justified,—from their point of view,—in arresting the audience and the
management en bloc.

"We'd better clear out," suggested Saunders; "there's going to be


trouble."

"If there's a row," announced Trafford grimly, "I'm going to be in it.


You've seen stirring times over here before, but I'm a novice at it, and I
want blooding. Shall we raise three cheers for Karl and fight our way out?"

"Not if you want to keep your thick skull weather-proof," was the
sensible retort. "There's always discontent in Grimland, but there's a big sea
running just now, and it isn't wise to fight the elements. Sit tight, my friend,
and you'll live to see more exciting things than a noisy night at the Eden
Music-Hall."

The curtain was down again now, but the audience still roared for the re-
appearance of their favourite, still clamoured for another verse of the
intoxicating song.

"Hullo! what's this?" cried Trafford. An attendant had edged her way up
to Saunders, and was offering him a folded note on a tray. "If you have any
pleasant memories of the winter of 1904, come round to the stage door and
ask for Fräulein Schmitt." That was the purport of the note, and after
reading it, Saunders handed it to Trafford.
"Then it must be your lady friend, after all," maintained the latter,
smiling at his friend.

"It must indeed," acquiesced Saunders with a frown. "Come round with
me now."

"Why not go by yourself?"

"Because I am a married man," replied Saunders, "and I want a


chaperon." And together the two men left the still noisy house and made
their way to the stage door.

Under the guidance of a pale youth in a shabby pony coat, they entered
a gloomy passage, ascended a steep flight of stone steps, and halted before a
door, which had once been painted green.

The pale one knocked, and a clear musical voice gave the necessary
permission to enter.

A naturally bare and ugly room had been rendered attractive by a big
stove, several comfortable chairs, and an abundance of photographs,
unframed sketches and artistic knick-knacks. It had been rendered still more
attractive by the presence of a charming young lady, who was engaged—
with the assistance of her dresser—in removing all traces of "make-up"
from her comely lips and cheeks.

The lady in question came forward with an air of pleasurable


excitement, and smiling a warm welcome to the Englishman, cried:

"So you have come, Herr Saunders! You have not, then, altogether
forgotten the winter of 1904?"

Saunders took the small hand which had been extended to him and
bowed low over it.

"Heaven forbid, my dear Princess—or must I call you Fräulein Schmitt,


now? No, indeed, so long as I have memory cells and the power to consult
them, I shall never forget the winter of 1904. It gave me an angel for a wife,
a king for a friend, and—must I say it—a princess for an enemy. That fierce
enmity! It is by no means my least pleasurable remembrance. There was so
much fun in it, such irresponsible laughter, that it all seems now more like
the struggle of children for a toy castle than anything else."

"Ah, but you forget that I lost a dear father and a loved brother in the
struggle for that toy castle!" There was almost a life-time of sorrow in the
young girl's voice.

Again Saunders bent his head.

"Pardon me, Princess," he said, "I did not forget that, nor the fact that
you nearly lost your life, and I mine. But my memory loves rather to linger
on the bob-sleighing excursions, the tea-fights at Frau Mengler's, the
frivolous disputations and serious frivolities—all with such a delicious
substratum of intrigue."

"You have a convenient memory, mein Herr," she said quietly. "You
remember the bright things, you half remember the grey, the black you
entirely forget."

Saunders' smile faded, for there was still a touch of sadness in the girl's
words. Under the circumstances it was not unnatural, but he thought it more
considerate to keep the interview from developing on serious lines.

"The art of living is to choose one's memories," he said lightly. "He who
has conquered his thoughts, has conquered a more wonderful country than
Grimland."

"And so marriage has made of you a philosopher, Herr Saunders?" she


returned, her soft lips curling a trifle contemptuously. "Well, perhaps you
are right—if we take life as a jest, death, then, is only the peal of laughter
that follows the jest." And then, turning to the American, she chided
Saunders with: "But you have not presented your friend!"

"I must again crave pardon—I had quite forgotten him," apologised
Saunders. "Your Highness, may I present my very good friend, Mr. George
Trafford of New York—the winner of the King's Cup."
The American bowed low before this exquisite creature; then uplifting
his head and shoulders and twirling his moustache—a habit he had when
his emotions were at all stirred—he asked with true American directness:

"Am I speaking to a princess of the blood royal or to a princess of


song?"

The princess and the Englishman quickly exchanged amused glances,


and a moment later there came from the girl a ringing laugh, a delightful
laugh bubbling over with humour, with not a hint of the sorrow or the
bitterness of a few moments before, while Saunders hastened to say:

"Both, my American friend! You are addressing the high-born Princess


Gloria von Schattenberg, cousin to his Majesty King Karl of Grimland!"

"Then I congratulate the high-born princess less on her high birth than
on her inimitable gift of song," said the American gallantly.

The Princess acknowledged the felicitation with a bewitching smile.

"Thank you, Herr Trafford," she said simply. "It is better to be a music-
hall star in the ascendant than a princess in exile—it is far more profitable,
isn't it?" No answer was expected, and in a trice her mood changed again.
"When I fled the country three years ago, Herr Trafford," she continued, "I
was penniless—my father dead, and his estates confiscated. True, an
allowance—a mere pittance—might have been mine had I returned and
bowed the knee to Karl." She stopped, her feelings seemingly too much for
her; in a moment, however, she had mastered them. "But I was a
Schattenberg!" she cried, with a little toss of her head. "And the
Schattenbergs—as Herr Saunders will testify—are a stiff-necked race.
There was nothing to be done," she went on, "but develop the gifts God had
given me. Under an humble nom de guerre I have achieved notoriety and a
large salary. Germany, France, Belgium, I have toured them all—and my
incognito has never been pierced. So when I got hold of a splendid song I
lost no time in hastening to Weidenbruck, for I knew it would go like
wildfire here."
"A most dangerous step." The comment came from the American, but
there was a light of frank admiration in his eye.

"Oh, no!" she protested, a faint touch of colour in her cheek, denoting
that his approving glance had not escaped her. "It is years since I was in this
place." And smiling at the Englishman, now, she added naïvely: "My
features are little likely to be recognised."

"Indeed!" voiced Saunders, a touch of satire in his tone. "Photographs of


the exiled Princess Gloria are in all the shop-windows, her personality is
more than a tolerably popular one. When they are placed in conjunction
with those of the equally popular Fräulein Schmitt, will not people talk?"

"I hope they will do more than that," confessed the Princess, growing
excited.

"You want——?"

"I want Grimland," interrupted the Princess; and added loftily: "nothing
more and nothing less. You will have me arrested?"

"Not yet!" declared Saunders with his brightest smile. "The night is cold
—your dressing-room is cosy. No, my fascinating, and revolutionary young
lady, the truce between us has been so long unbroken that I cannot rush into
hostilities in this way. Besides, we are not now in 1904, and——"

"Oh, for 1904!" cried the Princess, her eyes ablaze with the light of
enthusiasm. "Oh, for the sweets of popularity, the ecstasy of rousing brave
men and turning their blood to wine and their brains to fire! I want to live,
to rule, to be obeyed and loved as a queen!"

In an instant Trafford felt a responsive glow; he started to speak but


Saunders already was speaking.

"Princess," the Englishman was saying coldly, "popularity is champagne


with a dash of brandy in it. It is a splendid pick-me-up. It dispels ennui,
migraine, and all the other troubles of a highly-strung, nervous system.
Only, it is not what medical folk call a 'food.' It does not do for breakfast,
luncheon and dinner. After a time it sickens."

"Popularity—the adulation of my people would never pall on me,"


returned the Princess, gazing off for the moment, absorbed in a realm of
dreams.

"No, but the police might take a hand," intimated Saunders grimly.
"There is a castle at Weidenbruck called the Strafeburg. As its name
implies, it is intended otherwise than as a pleasure residence. It is a
picturesque old pile, but, curiously enough, the architect seems to have
neglected the important requirements of light and air. You would get very
tired of the Strafeburg, my Princess!"

"The people of Paris got very tired of the Bastille," retorted the Princess
hotly and flashing a defiant look at the Englishman. Trafford's hand
clinched in sympathy for her. Never was maid so splendidly daring and
reckless and fascinating! "They got very tired of Louis XVI.," the voice was
still going on, "and the people of Weidenbruck are very tired of the
Strafeburg."

To Trafford's astonishment the Princess's eyes showed danger of filling


upon uttering these last words. Her perfect mouth quivered, and of a
sudden, she seemed to him younger—certainly not more than nineteen.
Again he was tempted to interfere in her behalf, but again Saunders was
before him.

"They got tired of a good many people in Paris," the Englishman said
slowly. "Ultimately, even of Mére Guillotine. But supposing this country
rose, pulled down the Strafeburg and other interesting relics, and
decapitated my excellent friend, the King; supposing after much cutting of
throats, burning of buildings, and shootings against the wall, a certain
young lady became Gloria the First of Grimland, do you imagine she would
be happy? No—in twelve months she would be bored to death with court
etiquette, with conflicting advice, and the servile flattery of interested
intriguers. Believe me, she is far happier enchanting the audiences of
Belgium and Germany than she would be in velvet and ermine and a gold
crown that fell off every time she indulged in one of her irresponsible fits of
merriment."

"I might forget to laugh," said the Princess sadly. "But no, I cannot, will
not, take your advice! Do you not suppose that nature intended me to fill a
loftier position than even the high firmament of the Café Chantant? No, a
thousand times no, Herr Saunders—I am a Schattenberg and I mean to
fight!"

The American could not restrain himself an instant longer.

"Bravo!" burst out Trafford enthusiastically. "There's a ring in that


statement that warms my heart tremendously!"

A swift frown clouded Saunders' brow. It was plain to see that the
Englishman was much annoyed at the American's outspoken approval of the
Princess's purpose; but she broke into the laughter of a mischief-loving
child.

"And you—are not you a friend of King Karl?" she inquired of Trafford,
while a new light shone in her eyes.

The American gave a furious twist to his moustache before answering.

"Mrs. Saunders, I believe, has recommended me as his Commander-in-


Chief," he said with mock gravity, "but the appointment has not yet been
confirmed. 'Till then my services are at the disposal of the highest bidder."

"My American friend's services are of problematic value," put in


Saunders, recovering his temper. "He is an excellent skater, but a
questionable general. He has had an exciting day and a superb dinner. With
your permission I will take him back to his bed at the Hôtel Concordia."

The Princess had not taken her eyes off of the American since he had
last spoken.

"He has energy," she mused, looking into space now, "also the capacity
for inspiring enthusiasm, and I am not at all sure that he has not the instinct
of a born tactician."

"But I am," Saunders broke in bluntly. "Princess, we have the honour of


wishing you good-night!"

The Princess laid a delicate hand on the Englishman's arm.

"Herr Saunders," she said, "I will ask you to see me home."

Saunders shook his head.

"You must excuse me," he said. "To-night, I am neutral, but neutral


only. I am the King's guest and must not aid the King's enemies."

"Good loyal man!" exclaimed the Princess. "Plus royalist que le roi!"
And then turning to the American: "And Herr Trafford? He will not refuse
to perform a small act of courtesy?"

"Trafford accompanies me!" declared Saunders firmly.

"I'm hanged if he does!" spoke up Trafford. "The lady wants to be seen


home—and I'm going to do it if I swing for it!"
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like