100% found this document useful (3 votes)
15 views

Download Supervised Learning with Python Concepts and Practical Implementation Using Python 1st Edition Vaibhav Verdhan ebook All Chapters PDF

Vaibhav

Uploaded by

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

Download Supervised Learning with Python Concepts and Practical Implementation Using Python 1st Edition Vaibhav Verdhan ebook All Chapters PDF

Vaibhav

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

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/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at 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

Reinforcement Learning: With Open AI, TensorFlow and Keras


Using Python 1st Edition Abhishek Nandy

https://textbookfull.com/product/reinforcement-learning-with-open-ai-
tensorflow-and-keras-using-python-1st-edition-abhishek-nandy/

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
Vaibhav Verdhan

Supervised Learning with Python


Concepts and Practical Implementation Using
Python
1st ed.

Foreword by Dr. Eli Yechezkiel Kling (PhD)


Vaibhav Verdhan
Limerick, Ireland

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.

ISBN 978-1-4842-6155-2 e-ISBN 978-1-4842-6156-9


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

© Vaibhav Verdhan 2020

Apress Standard

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and
accurate at the date of publication. Neither the publisher nor the
authors or the editors give a warranty, expressed or implied, with
respect to the material contained herein or for any errors or omissions
that may have been made. The publisher remains neutral with regard
to jurisdictional claims in published maps and institutional affiliations.

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-
[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.
To Yashi, Pakhi and Rudra.
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.
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.
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.
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
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.
Table of Contents
Chapter 1:​Introduction to Supervised Learning
What Is ML?​
Relationship Between Data Analysis, Data Mining, ML, and
AI
Data, Data Types, and Data Sources
How ML Differs from Software Engineering
ML Projects
Statistical and Mathematical Concepts for ML
Supervised Learning Algorithms
Regression vs.​Classification Problems
Steps in a Supervised Learning Algorithm
Unsupervised Learning Algorithms
Cluster Analysis
PCA
Semi-supervised Learning Algorithms
Technical Stack
ML’s Popularity
Use Cases of ML
Summary
Chapter 2:​Supervised Learning for Regression Analysis
Technical Toolkit Required
Regression analysis and Use Cases
What Is Linear Regression
Assumptions of Linear Regression
Measuring the Efficacy of Regression Problem
Example 1:​Creating a Simple Linear Regression
Example 2:​Simple Linear Regression for Housing Dataset
Example 3:​Multiple Linear Regression for Housing Dataset
Nonlinear Regression Analysis
Identifying a Nonlinear Relationship
Assumptions for a Nonlinear Regression
Challenges with a Regression Model
Tree-Based Methods for Regression
Case study:​Petrol consumption using Decision tree
Ensemble Methods for Regression
Case study:​Petrol consumption using Random Forest
Feature Selection Using Tree-Based Methods
Summary
Chapter 3:​Supervised Learning for Classification Problems
Technical Toolkit Required
Hypothesis Testing and p-Value
Classification Algorithms
Logistic Regression for Classification
Assessing the Accuracy of the Solution
Case Study:​Credit Risk
Additional Notes
Naïve Bayes for Classification
Case Study:​Income Prediction on Census Data
k-Nearest Neighbors for Classification
Case Study:​k-Nearest Neighbor
The Dataset
Business Objective
Tree-Based Algorithms for Classification
Types of Decision Tree Algorithms
Summary
Chapter 4:​Advanced Algorithms for Supervised Learning
Technical Toolkit Required
Boosting Algorithms
Using Gradient Boosting Algorithm
SVM
SVM in 2-D Space
KSVM
Case Study Using SVM
Supervised Algorithms for Unstructured Data
Text Data
Use Cases of Text Data
Challenges with Text Data
Text Analytics Modeling Process
Text Data Extraction and Management
Preprocessing of Text Data
Extracting Features from Text Data
Case study:​Customer complaints analysis using NLP
Word Embeddings
Case study:​Customer complaints analysis using word
embeddings
Image Data
Use Cases of Image Data
Challenges with Image Data
Image Data Management Process
Image Data Modeling Process
Fundamentals of Deep Learning
Artificial Neural Networks
Activation Functions
Loss Function in a Neural Network
Optimization in a Neural Network
Neural Network Training Process
Case Study 1:​Create a Classification Model on Structured Data
Case Study 2:​Image Classification Model
Summary
Chapter 5:​End-to-End Model Development
Technical Toolkit Required
ML Model Development
Step 1:​Define the Business Problem
Step 2:​Data Discovery Phase
Step 3:​Data Cleaning and Preparation
Duplicates in the Dataset
Categorical Variable Treatment in Dataset
Missing Values Present in the Dataset
Imbalance in the Dataset
Outliers in the Dataset
Other Common Problems in the Dataset
Step 4:​EDA
Step 5:​ML Model Building
Train/​Test Split of Data
Finding the Best Threshold for Classification Algorithms
Overfitting vs.​Underfitting Problem
Key Stakeholder Discussion and Iterations
Presenting the Final Model
Step 6:​Deployment of the Model
Step 7:​Documentation
Step 8:​Model Refresh and Maintenance
Summary
Index
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.
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.
© Vaibhav Verdhan 2020
V. Verdhan, Supervised Learning with Python
https://doi.org/10.1007/978-1-4842-6156-9_1

1. Introduction to Supervised Learning


Vaibhav Verdhan1
(1) Limerick, Ireland

“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 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.
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.

Relationship Between Data Analysis, Data 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
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.
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.
Table 1-1 Data Science: How Can It Help Us, Its Usages, and Limitations
-

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.
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.
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.

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.
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.
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.
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.
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.

ML 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.

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 anomalies are the output of this stage, which
prove to be quite useful for the next stage, which is statistical
modeling.

4. ML modeling or statistical modeling is the actual model


development phase. We will discuss this phase in detail throughout
the book.

5. After modeling, results are shared with the business team and the
statistical model is deployed into the production environment.

Since most of the data available is seldom clean, more than 60%–
70% of the project time is spent in data mining, data discovery,
cleaning, and data preparation phase.
Before starting the project, there are some anticipated challenges.
In Figure 1-6, we discuss a few questions we should ask before starting
an ML project.
Figure 1-6 Preparations to be made before starting an ML project. It is imperative
that all the relevant questions are clear and KPIs are frozen.
We should be able to answer these questions about the data
availability, data quality, data preparation, ML model prediction
measurements, and so on. It is imperative to find the answers to these
questions before kicking off the project; else we are risking stress for
ourselves and missing deadlines at a later stage.
Now you know what is ML and the various phases in an ML project.
It will be useful for you to envisage an ML model and what the various
steps are in the process. Before going deeper, it is imperative that we
brush up on some statistical and mathematical concepts. You will also
agree that statistical and mathematical knowledge is required for you
to appreciate ML.

Statistical and Mathematical Concepts for ML


Statistics and mathematics are of paramount importance for complete
and concrete knowledge of ML. The mathematical and statistical
algorithms used in making the predictions are based on concepts like
linear algebra, matrix multiplications, concepts of geometry, vector-
space diagrams, and so on. Some of these concepts you would have
already studied. While studying the algorithms in subsequent chapters,
Random documents with unrelated
content Scribd suggests to you:
attention to regiments or brigades, so sudden was the affair, formed
two masses, one of which under general Dilke marched hastily
against Ruffin, and the other under colonel Wheately against Laval.
Duncan’s guns ravaged the French ranks; Laval’s artillery replied
vigorously; Ruffin’s batteries took Wheately’s column in flank; and
the infantry on both sides pressed forward eagerly, and with a
pealing musketry; but, when near together, a fierce, rapid, prolonged
charge of the British overthrew the first line of the French, and,
notwithstanding its extreme valour, drove it in confusion, over a
narrow dip of ground upon the second, which was almost
immediately broken in the same manner, and only the chosen
battalion, hitherto posted on the right, remained to cover the retreat.
Meanwhile Brown, on receiving his orders, had marched headlong
against Ruffin. Nearly half of his detachment went down under the
enemy’s first fire; yet he maintained the fight, until Dilke’s column,
which had crossed a deep hollow and never stopt even to re-form
the regiments, came up, with little order indeed, but in a fierce mood,
when the whole run up towards the summit; there was no slackness
on any side, and at the very edge of the ascent their gallant
opponents met them. A dreadful, and for some time a doubtful, fight
ensued, but Ruffin and Chaudron Rousseau, commanding the
chosen grenadiers, both fell mortally wounded; the English bore
strongly onward, and their incessant slaughtering fire forced the
French from the hill with the loss of three guns and many brave
soldiers.
The discomfitted divisions, retiring concentrically, soon met, and
with infinite spirit endeavoured to re-form and renew the action; but
the play of Duncan’s guns, close, rapid, and murderous, rendered
the attempt vain. Victor was soon in full retreat, and the British
having been twenty-four hours under arms, without food, were too
exhausted to pursue.
While these terrible combats of infantry were fighting, La Peña
looked idly on, neither sending his cavalry, nor his horse-artillery, nor
any part of his army, to the assistance of his ally, nor yet menacing
the right of the enemy, which was close to him and weak. The
Spanish Walloon guards, the regiment of Ciudad Real, and some
Guerilla cavalry, indeed turned without orders, coming up just as the
action ceased; and it was expected that colonel Whittingham, an
Englishman commanding a powerful body of horse, would have
done as much; but no stroke in aid of the British was struck by a
Spanish sabre that day, although the French cavalry did not exceed
two hundred and fifty men, and it is evident that the eight hundred
under Whittingham might, by sweeping round the left of Ruffin’s
division, have rendered the defeat ruinous. So certain, indeed, was
this, that colonel Frederick Ponsonby, drawing off the hundred and
eighty German hussars belonging to the English army, reached the
field of battle, charged the French squadrons just as their retreating
divisions met, overthrew them, took two guns, and even attempted,
though vainly, to sabre Rousseau’s chosen battalions.
Such was the fight of Barosa. Short, for it lasted only one hour and
a half, but most violent and bloody; for fifty officers, sixty serjeants,
and above eleven hundred British soldiers, and more than two
thousand Frenchmen were killed and wounded; and from the latter,
six guns, an eagle, and two generals (both mortally wounded) were
taken, together with four hundred other prisoners.
After the action, Graham remained some hours on the height, still
hoping that La Peña would awake to the prospect of success and
glory, which the extreme valour of the British had opened. Four
thousand men and a powerful artillery had come over the Santi Petri;
hence the Spanish general was at the head of twelve thousand
infantry and eight hundred cavalry, all fresh troops; while before him
were only the remains of the French line of battle retreating in the
greatest disorder upon Chiclana. But all military feeling Appendix, No. IX.
being extinct in La Peña, Graham would no longer Section 1.
endure such command. The morning of the 6th saw the British filing
over Zaya’s bridge into the Isla.
Vol. 3, Plate 9.

BATTLE of BAROSA
5th March, 1811.
London Published by T. & W. Boone Novr 1830.
On the French side, Cassagne’s reserve came in from Medina, a
council of war was held in the night of the 5th, and Victor, although of
a disponding nature, proposed another attack; but the suggestion
being ill received, nothing was done; and the 6th, Admiral Keats,
landing his seamen and marines, dismantled, with exception of
Catalina, every fort from Rota to Santa Maria, and even obtained
momentary possession of the latter place. Confusion and alarm then
prevailed in the French camp; the duke of Belluno, leaving garrisons
at the great points of his lines, and a rear guard at Official Abstracts of
Chiclana, retreated behind the San Pedro, where he Military
MSS.
Reports,

expected to be immediately attacked. If La Peña had


even then pushed to Chiclana, Graham and Keats were willing to
make a simultaneous attack upon the Trocadero; but the 6th and 7th
passed, without even a Spanish patrole following the French. On the
8th Victor returned to Chiclana, and La Peña instantly recrossing the
Santi Petri, destroyed the bridge, and his detachment on the side of
Medina being thus cut off from the Isla, was soon afterwards obliged
to retire to Algesiras.
All the passages in this extraordinary battle were so broadly
marked, that observations would be useless. The contemptible
feebleness of La Peña furnished a surprising contrast to the heroic
vigour of Graham, whose attack was an inspiration rather than a
resolution, so wise, so sudden was the decision, so swift, so
conclusive was the execution. The original plan of the enterprise
having however been rather rashly censured, some remarks on that
head may be useful. “Sebastiani, it is said, might, by moving on the
rear of the allies, have crushed them, and they had no right to
calculate upon his inactivity.” This is weak. Graham, weighing the
natural dislike of one general to serve under another, judged, that
Sebastiani, harassed by insurrections in Grenada, would not hastily
abandon his own district to succour Victor, before it was clear where
the blow was to be struck. The distance from Tarifa to Chiclana was
about fifty miles, whereas, from Sebastiani’s nearest post to
Chiclana was above a hundred, and the real object of the allies could
not be known until they had passed the mountains separating Tarifa
from Medina.
Combining these moral and physical considerations, Graham had
reason to expect several days of free action; and thus indeed it
happened, and with a worthy colleague he would have raised the
blockade: more than that could scarcely have been Appendix, No. IX.
hoped, as the French forces would have concentrated Section 5.
either before Cadiz or about Seville or Ecija; and they had still fifty
thousand men in Andalusia.
Victor’s attack on the 5th, was well-judged, well-timed, vigorous;
with a few thousand more troops he alone would have crushed the
allies. The unconquerable spirit of the English prevented this
disaster; but if Graham or his troops had given way, or even
hesitated, the whole army must have been driven like sheep into an
enclosure; the Almanza creek on one side, the sea on the other, the
San Petri to bar their flight, and the enemy hanging on their rear in
all the fierceness of victory. Indeed, such was La Peña’s misconduct,
that the French, although defeated, gained their main point; the
blockade was renewed, and it is remarkable that, during the action, a
French detachment passed near the bridge of Zuazo without
difficulty, and brought back prisoners; thus proving that with a few
more troops Victor might have seized the Isla. Meanwhile
Ballasteros, who had gone against Seville, was chased, in a
miserable condition, to the Aroche hills, by Daricau.
In Cadiz violent disputes arose. La Peña, in an address to the
Cortes, claimed the victory for himself. He affirmed that all the
previous arrangements were made with the knowledge and
approbation of the English general, and the latter’s retreat into the
Isla he indicated as the real cause of failure: Lascy and general
Cruz-Murgeon also published inaccurate accounts of the action, and
even had deceptive plans engraved to uphold their statements.
Graham, stung by these unworthy proceedings, exposed the conduct
of La Peña in a letter to the British envoy; and when Lascy let fall
some expressions personally offensive, he enforced an apology with
his sword; but having thus shewn himself superior to his opponents
at all points, the gallant old man soon afterwards relinquished his
command to general Cooke, and joined lord Wellington’s army.
CHAPTER III.
While discord prevailed at Cadiz, the siege of Badajos continued.
Early in March, the second parallel being completed and the
Pardaleras taken into the works, the approaches were carried by sap
to the covered way, and mines were prepared to blow in the
counterscarp. Nevertheless, Rafael Menacho, the governor, was in
no manner dismayed; his sallies were frequent and vigorous, his
activity and courage inspired his troops with confidence, he had
begun to retrench in the streets behind the part attacked, and as the
fire of the besiegers was also inferior to that of the besieged, every
thing seemed to promise favourably for the latter: but, on the evening
of the 2d, during a sally, in which the nearest French batteries were
carried, the guns spiked, and trenches partly ruined, Menacho was
killed, and the command fell to Imas, a man so unworthy that a
worse could not be found. At once the spirit of the garrison died
away, the besiegers’ works advanced rapidly, the ditch was passed,
a lodgement was made on one of the ravelins, the rampart was
breached, and the fire of the besieged being nearly extinguished, on
the 10th of March the place was summoned in a peremptory manner.
At this time the great crisis of the campaign had passed, and a
strong body of British and Portuguese troops were ready to raise the
siege of Badajos. In three different ways, by telegraph, by a letter,
and by a confidential messenger, the governor was informed, that
Massena was in full retreat and that the relieving army was actually
in march. The breach was still impracticable, provisions were
plentiful, the garrison above eight thousand strong, the French army
reduced, by sickness, by detachments and the Lord Wellington’s
previous operations, to less than fourteen thousand Despatch.
men. Imas read the letter, and instantly surrendered, handing over at
the same moment the intelligence thus obtained to the enemy. But
he also demanded that his grenadiers should march out of the
breach, it was granted, and he was obliged to enlarge the opening
himself ere they could do so! Yet this man so covered with
opprobrium, and who had secured his own liberty while consigning
his fellow soldiers to a prison, and his character to infamy, was never
punished by the Spanish rulers: lord Wellington’s indignant
remonstrances forced them, indeed, to bring him to trial, but they
made the process last during the whole war.
When the place fell, Mortier marched against Campo Mayor, and
Latour Maubourg seizing Albuquerque and Valencia d’Alcantara,
made six hundred prisoners; but Soult, alarmed by the effects of the
battle of Barosa, returned to Andalusia, having, in fifty days,
mastered four fortresses and invested a fifth; having killed or
dispersed ten thousand men, and having taken twenty thousand with
a force which, at no time, exceeded the number of his prisoners: yet
great and daring and successful as his operations had been, the
principal object of his expedition was frustrated, for Massena was in
retreat. Lord Wellington’s combinations had palsied the hand of the
conqueror.
While the siege of Badajos was proceeding, no change took place
in the main positions of either army at Santarem. The English
general, certain that the French, who were greatly reduced by
sickness, must soon quit their ground if he could relieve Badajos,
was only waiting for his reinforcements to send Beresford with
fourteen thousand men against Soult; when the battle of the Gebora
ruined this plan and changed his situation. The arrival of the
reinforcements could not then enable him to detach a sufficient
number of men to relieve Badajos, and it was no longer a question of
starving Massena out, but of beating him, before Soult could take
Badajos and the two armies be joined. In this difficulty, abandoning
the design of raising the siege by a detachment, lord Wellington
prepared to attack Massena’s army in front on the side of Tremes,
while Beresford, crossing at Abrantes, fell upon the rear; he hoped
thus to force back the French right and centre, and to cut off the left
and to drive it into the Tagus. However, nothing could be attempted
until the troops from England arrived, and day after day passed in
vain expectation of their coming. Being embarked in January, they
would have reached Lisbon before the end of that month, had sir
Joseph Yorke, the admiral, charged to conduct the fleet, taken
advantage of a favourable wind, which blew when the troops were
first put on board; but he neglected this opportunity, contrary gales
followed, and a voyage of ten days was thus prolonged for six
weeks.
On the other hand, the French general’s situation was becoming
very perilous. To besiege Abrantes was above his means, and
although that fortress was an important strategic point for the allies
who had a moveable bridge, it would not have been so for the
French. Massena could only choose then, to force the passage of
the Tagus alone, or to wait until Soult appeared on the left bank, or to
retreat. For sometime he seemed inclined to the first, shewing great
jealousy of the works opposite the mouth of the Zezere, and carrying
his boats on wheel-carriages along the banks of the Tagus, as if to
alarm Beresford and oblige him to concentrate to his left: yet that
general relaxed nothing of his vigilance, neither spy nor officer
passed his lines of observation, and Massena knew, generally, that
Soult was before Badajos, but nothing more. However, time wore
away, sickness wasted the army, food became daily scarcer, the
organization of the troops was seriously loosened, the leading
generals were at variance, and the conspiracy to put See Vol. II
St. Cyr at the head of the army in Spain was by no
means relinquished.
Under these accumulating difficulties even Massena’s obstinacy
gave way; he promised to retreat when he had no more provisions
left than would serve his army for the march. A tardy resolution; yet
adopted at the moment, when to maintain his position was more
important than ever, as ten days longer at Santarem would have
insured the co-operation of Soult. General Pelet says, that the latter
marshal, by engaging in the siege of Badajos and Olivenza, instead
of coming directly down upon the Tagus, was the cause of
Massena’s failure; this can hardly be sustained. Before those sieges
and the battle of the Gebora, Mendizabel could have assembled
twenty thousand men on Soult’s rear, and there was a large body of
militia on the Ponçul and the Elga; Beresford had fourteen thousand
British and Portuguese regulars, besides ordenança; while the
infinite number of boats at lord Wellington’s command would have
enabled him to throw troops upon the left bank of the Tagus, with a
celerity that would have baffled any effort of Massena to assist the
duke of Dalmatia. Now, if the latter had been defeated; with what
argument could he have defended his reputation as a general, after
having left three or four garrisoned fortresses and thirty-five
thousand men upon his flank and rear; to say nothing of the results
threatened by the battle of Barosa.
The true cause of Massena’s failure was the insufficiency of his
means to oppose the English general’s combinations. The French
army reduced by sickness to forty thousand fighting men, exclusive
of Drouet’s troops at Leiria, would have been unable to maintain its
extended position against the attack meditated by lord Wellington;
and when Massena, through the means of the fidalgos, knew that
the English reinforcements were come, he prepared to retreat.
Those troops landed the 2d of March, and, the 6th, the French had
evacuated the position of Santarem.
At this time Napoleon directed the armies of Spain Muster-Rolls of the
to be remodelled. The king’s force was diminished; the French Army.
army of the south increased; general Drouet was ordered to march
with eleven thousand men to the fifth corps, which he was appointed
to command, in place of Mortier; the remainder of the ninth corps
was to compose two divisions, under the command of Clausel and
Foy, and to be incorporated with the army of Portugal. Marmont was
appointed to relieve Ney in the command of the sixth corps; Loison
was removed to the second corps; and Bessieres was ordered to
post six thousand men at Ciudad Rodrigo, to watch the frontiers of
Portugal and support Claparede. Of the imperial guards; seven
thousand were to assemble at Zamora, to hold the Gallicians in
check, and the remainder at Valladolid, with strong Appendix, No. VII.
parties of cavalry in the space between those places,
that intelligence of what was passing in Portugal might be daily
received. Thus Massena was enabled to adopt any operation that
might seem good to him, without reference to his original base; but
the order for the execution of these measures did not reach the
armies until a later period.
R E T R E AT O F T H E F R E N C H F R O M S A N TA R E M .

Several lines of operation were open to the prince of Esling. 1º. He


could pass the Tagus, between Punhete and Abrantes, by boats or
by fords, which were always practicable after a week of dry weather.
2º. He could retire, by the Sobreira Formosa, upon Castello Branco,
and open a communication with the king by Placentia, and with the
duke of Dalmatia by Alcantara. 3º. He could march, by the Estrada
Nova and Belmonte, to Sabugal, and afterwards act according to
circumstances. 4º. He could gain the Mondego, and ascend the left
bank of that river towards Guarda and Almeida; or, crossing it, march
upon Oporto through an untouched country. Of these four plans, the
first was perilous, and the weather too unsettled to be sure of the
fords. The second and third were difficult, from the ruggedness of the
Sobreira, and exposed, because the allies could break out by
Abrantes upon the flank of the army while in retreat. Massena
decided on the last, but his actual position being to the left of the line
of retreat, he was necessarily forced to make a flank movement, with
more than ten thousand sick men and all his stores, under the beard
of an adversary before he could begin his retreat. Yet this he
executed, and in a manner bespeaking the great commander.
Commencing his preparations by destroying munition, and all guns
that could not be horsed, he passed his sick and baggage, by
degrees, upon Thomar, keeping only his fighting-men in the front,
and at the same time indicating an intention of passing the Zezere.
But when the impediments of the army had gained two marches,
Ney suddenly assembled the sixth corps and the cavalry on the Lys,
near Leiria, as if with the intention of advancing against Torres
Vedras, a movement that necessarily kept lord Wellington in
suspense. Meanwhile, the second and eighth corps, quitting
Santarem, Tremes, and Alcanhete, in the night of the 5th, fell back,
by Pernes, upon Torres Novas and Thomar, destroying the bridges
on the Alviella behind them. The next morning the boats were burnt
at Punhete, and Loison retreated by the road of Espinal to cover the
flank of the main line of retreat; the remainder of the army, by rapid
concentric marches, made for a position in front of Pombal: the line
of movement to the Mondego was thus secured, and four days
gained; for lord Wellington, although aware that a retreat was in
execution, was quite unable to take any decided step, lest he should
open the Lines to his adversary. Nevertheless he had caused
Beresford to close to his right on the 5th, and at daylight, on the 6th,
discovering the empty camps of Santarem, followed the enemy
closely with his own army.
Thomar seemed to be the French point of concentration; but as
their boats were still maintained at Punhete, general William Stewart
crossed the Tagus, at Abrantes, with the greatest part of Beresford’s
corps, while the first, fourth, and sixth divisions, and two brigades of
cavalry, marched to Golegao; the light division also reached Pernes,
where the bridge was rapidly repaired by captain Tod, of the royal
staff-corps. The 7th, the enemy having burnt his boats on the
Zezere, the Abrantes bridge was brought down to that river, and
Stewart, crossing, moved to Thomar; on which place the divisions at
Golegao were likewise directed. But the retreat being soon decidedly
pronounced for the Mondego, the troops at Thomar were ordered to
halt; and the light division, German hussars, and royal dragoons
followed the eighth corps, taking two hundred prisoners.
This day’s march disclosed a horrible calamity. A large house,
situated in an obscure part of the mountains, was discovered, filled
with starving persons. Above thirty women and children had sunk,
and, sitting by the bodies, were fifteen or sixteen survivors, of whom
one only was a man, but all so enfeebled as to be unable to eat the
little food we had to offer them. The youngest had fallen first; all the
children were dead; none were emaciated in the bodies, but the
muscles of the face were invariably drawn transversely, giving the
appearance of laughing, and presenting the most ghastly sight
imaginable. The man seemed most eager for life; the women
appeared patient and resigned, and, even in this distress, had
arranged the bodies of those who first died, with decency and care.
While one part of the army was thus in pursuit, the third and fifth
divisions moved, from the Lines, upon Leiria; the Abrantes’ boats fell
down the river to Tancos, where a bridge was fixed; and the second
and fourth divisions, and some cavalry, were directed to return from
Thomar to the left bank of the Tagus, to relieve Badajos: Beresford
also, who remained with a part of his corps near Barca, had already
sent a brigade of cavalry to Portalegre for that purpose. This was on
the morning of the 9th; but the enemy, instead of continuing his
retreat, concentrated the sixth and eighth corps and Montbrun’s
cavalry on a table-land, in front of Pombal, where the light division
skirmished with his advanced posts, and the German horse charged
his cavalry with success, taking some prisoners.
Lord Wellington, finding the French disposed to accept battle, was
now compelled to alter his plans. To fight with advantage, it was
necessary to bring up, from Thomar, the troops destined to relieve
Badajos; not to fight, was giving up to the enemy Coimbra, and the
untouched country behind, as far as Oporto: Massena would thus
retire with the advantages of a conqueror. However, intelligence
received that morning, from Badajos, described it as being in a
sufficient state, and capable of holding out yet a month. This decided
the question.
The fourth division and the heavy cavalry, already on the march for
the Alemtejo, were countermanded; general Nightingale, with a
brigade of the first division and some horse, was directed by the road
of Espinal, to observe the second corps; and the rest of the army
was concentrically directed upon Pombal. How dangerous a captain
Massena could be, was here proved. His first movement began the
4th, it was the 11th before a sufficient number of troops could be
assembled to fight him at Pombal, and, during these seven days, he
had executed one of the most difficult operations in war, gained three
or four marches, and completely organized his system of retreat.

S K I R M I S H AT P O M B A L .

Pack’s brigade and the cavalry, the first, third, fourth, fifth, sixth,
and light divisions, and the Portuguese troops, which were attached,
like the ancient Latin auxiliaries of the Roman legion, to each British
division, were assembling in front of the enemy on the 10th; when
Massena, who had sent his baggage over the Soure river in the night
by the bridge of Pombal, suddenly retired through that town. He was
so closely followed by the light division, that the streets being still
encumbered, Ney drew up a rear-guard on a height behind the town,
and threw a detachment into the old castle of Pombal. He had,
however, waited too long. The French army was moving in some
confusion and in a very extended column of march, by a narrow
defile, between the mountains and the Soure river, which was
fordable; and the British divisions were in rapid motion along the left
bank, with the design of crossing lower down, and cutting Massena’s
line of retreat. But darkness came on too fast, and the operation
terminated with a sharp skirmish at Pombal, whence the ninety-fifth
and the third caçadores of the light division, after some changes of
fortune, drove the French from the castle and town with such vigour,
that the latter could not destroy the bridge, although it was mined.
About forty of the allies were hurt, and the loss of the enemy was
somewhat greater.
In the night Massena continued his retreat, which now assumed a
regular and concentrated form. The baggage and sick, protected by
the reserve cavalry, marched first; these were followed by the eighth
corps; and the sixth, with some light cavalry, and the best horsed of
the artillery, were destined to stem the pursuit. Ney had been
ordered to detach Marcognet’s brigade on the 10th, from the Lys, to
seize Coimbra; but some delay having taken place, Montbrun was
now appointed for that service.
Lord Wellington’s immediate object was to save Coimbra, and he
designed, by skilful, rather than daring, operations, to oblige
Massena to quit the Portuguese territory: the moral effect of such an
event, he judged, would be sufficient; but as his reinforcements were
still distant, he was obliged to retain the fourth division and the heavy
cavalry from the relief of Badajos, and was therefore willing to strike
a sudden stroke, if a fair occasion offered. Howbeit the country was
full of strong positions, the roads hollow and confined by mountains
on either hand, every village formed a defile; the weather also, being
moderate, was favourable to the enemy, and Ney, with a wonderfully
happy mixture of courage, readiness, and skill, illustrated every
league of ground by some signal combination of war.
Day-break, on the 12th, saw both armies in movement, and eight
miles of march, and some slight skirmishing, brought the head of the
British into a hollow way, leading to a high table-land on which Ney
had disposed five thousand infantry, a few squadrons of cavalry, and
some light guns. His centre was opposite the hollow road, his wings
were covered by wooded heights, which he occupied with light
troops; his right rested on the ravine of the Soure, his left on the
Redinha, which circling round his rear fell into the Soure. Behind him
the village of Redinha, situated in a hollow, covered a narrow bridge
and a long and dangerous defile; and, beyond the stream, some very
rugged heights, commanding a view of the position in front of the
village, were occupied by a division of infantry, a regiment of cavalry,
and a battery of heavy guns; all so skilfully disposed as to give the
appearance of a very considerable force.

C O M B AT O F R E D I N H A .

After examining the enemy’s position for a short time, lord


Wellington first directed the light division, now commanded by sir
William Erskine, to attack the wooded slopes covering Ney’s right: in
less than an hour these orders were executed. The fifty-second, the
ninety-fifth, and the caçadores, assisted by a company of the forty-
third, carried the ascent and cleared the woods, and their
skirmishers even advanced on to the open plain; but the French
battalions, supported by four guns, immediately opened a heavy
rolling fire, and at the same moment, colonel Ferriere, of the third
French hussars, charged and took fourteen prisoners. This officer,
during the whole campaign, had never failed to break in upon the
skirmishers in the most critical moments; sometimes with a
squadron, sometimes with only a few men; he was, however, sure to
be found in the right place, and was continually proving how much
may be done, even in the most rugged mountains, by a small body
of good cavalry.
Erskine’s line, consisting of five battalions of infantry and six guns,
being now formed in such a manner that it outflanked the French
right, tending towards the ford of the Redinha, was reinforced with
two regiments of dragoons; meanwhile Picton seized the wooded
heights protecting the French left, and thus Ney’s position was laid
bare. Nevertheless, that marshal observing that lord Wellington,
deceived as to his real numbers, was bringing the mass of the allied
troops into line; far from retreating, even charged Picton’s
skirmishers, and continued to hold his ground with an astonishing
confidence if we consider his position; for the third division was
nearer to the village and bridge than his right, and there were
already cavalry and guns enough on the plain to overwhelm him. In
this posture both sides remained for about an hour, when, three
shots were fired from the British centre as a signal for a forward
movement, and a most splendid spectacle of war was exhibited. The
woods seemed alive with troops; and in a few moments thirty
thousand men, forming three gorgeous lines of battle, were stretched
across the plain; but bending on a gentle curve, and moving
majestically onwards, while horsemen and guns, springing forward
simultaneously from the centre and from the left wing, charged under
a general volley from the French battalions: the latter were instantly
hidden by the smoke, and when that cleared away no enemy was to
be seen.
Ney keenly watching the progress of this grand formation, had
opposed Picton’s foremost skirmishers with his left, and, at the same
moment, withdrew the rest of his people with such rapidity, that he
gained the village ere the cavalry could touch him: the utmost efforts
of Picton’s skirmishers and of the horse-artillery scarcely enabled
them to gall the hindmost of the French left with their fire. One
howitzer was, indeed, dismounted close to the bridge, but the village
of Redinha was in flames; and the marshal wishing to confirm the
courage of his soldiers at the commencement of the retreat, in
person superintended the carrying it off: this he effected, yet with the
loss of fifteen or twenty men, and with great danger to himself, for
the British guns were thundering on his rear, and the light troops of
the third division, chasing like heated blood hounds, passed the river
almost at the same time with the French. The reserves of the latter
cannonaded the bridge from the heights beyond, but a fresh
disposition of attack being made by lord Wellington, while the third
division continued to press the left, Ney fell back upon the main
body, then at Condeixa, ten miles in the rear.
The British had twelve officers and two hundred men killed and
wounded in this combat, and the enemy lost as many; but he might
have been utterly destroyed; for there is no doubt, that the duke of
Elchingen remained a quarter of an hour too long upon his first
position, and that, deceived by the skilful arrangement of his reserve,
lord Wellington paid him too much respect. Yet the extraordinary
facility and precision with which the English general handled so large
a force, was a warning to the French commander, and produced a
palpable effect upon the after operations.
On the 13th, the allies renewed the pursuit, and before ten o’clock
discovered the French army, the second corps which was at
Espinhal excepted, in order of battle. The crisis of Massena’s retreat
had arrived, the defiles of Condeixa, leading upon Coimbra, were
behind him; those of Miranda de Corvo, leading to the Puente de
Murcella, were on his left; and in the fork of these two roads Ney was
seated on a strong range of heights covered by a marsh, his position
being only to be approached by the highway leading through a deep
hollow against his right. Trees were felled to obstruct the passage; a
palisado was constructed across the hollow; breast-works were
thrown up on each side, and Massena expected to stop the pursuit,
while Montbrun seized Coimbra: for he designed to pass the
Mondego, and either capture Oporto or maintain a position between
the Douro and the Mondego, until the operations of Soult should
draw the British away; or until the advance of Bessieres with the
army of the north, should enable himself again to act offensively.
Hitherto the French general had appeared the abler tactician, but
now his adversary assumed the superiority.
When at Thomar lord Wellington had sent Baccellar orders to look
to the security of Oporto, and had directed Wilson and Trant also to
abandon the Mondego and the Vouga the moment the fords were
passable, retiring across the Douro; breaking up the roads as they
retreated, and taking care to remove or to destroy all boats and
means of transport. Now, Wilson was in march for the Vouga, but
Trant having destroyed an arch of the Coimbra bridge on the city
side, and placed guards at the fords as far as Figueras, resolved to
oppose the enemy’s passage; for the sound of guns had reached his
outposts, the river was rising, and he felt assured that the allied army
was close upon the heels of the enemy.
As early as the evening of the 11th, the French appeared at the
suburb of Santa Clara, and a small party of their dragoons actually
forded the Mondego at Pereiras that day: on the 12th, some French
officers examined the bridge of Coimbra, but a cannon-shot from the
other side wounded one of them, and a general skirmish took place
along the banks of the river, during which a party attempting to feel
their way along the bridge, were scattered by a round of grape. The
fords were, however, actually practicable for cavalry, and there were
not more than two or three hundred militia and a few guns at the
bridge; for Baccellar had obliged Trant to withdraw the greatest part
of his force on the 11th; nevertheless the latter opposed the enemy
with the remainder, and it would appear that the French imagined the
reinforcement, which reached Lisbon the 2d of March, had been sent
by sea to the Mondego and was in Coimbra. This was Campagne des
an error. Coimbra was saved by the same man and Français Portugal.
en

the same militia that had captured it during the


advance.
Montbrun sent his report to Massena early on the 13th, and the
latter too readily crediting his opinion of Trant’s strength, relinquished
the idea of passing the Mondego, and determined to retire by the
Puente de Murcella: but to ensure the power of changing his front,
and to secure his communication with Reynier and Loison, he had
carried Clausel’s division to Fonte Coberta, a village about five miles
on his left; situated at the point where the Anciao road falls into that
leading to Murcella. There Loison rejoined him, and being thus
pivotted on the Anciao Sierra, and covering the line of
communication with the second corps while Ney held Condeixa, he
considered his position secure. His baggage was, however,
observed filing off by the Murcella road when the allies first came
upon Ney, and lord Wellington instantly comprehending the state of
affairs, as instantly detached the third division by a very difficult path
over the Sierra de Anciao to turn the enemy’s left.
For some time all appeared quiet in the French lines. Massena, in
repairing to Fonte Coberta, had left Ney orders, it is said, to fire
Condeixa at a certain hour when all the divisions were
simultaneously to concentrate at Casal Nova, in a second position,
perpendicular to the first, and covering the road to Puente Murcella.
But towards three o’clock Picton was descried winding round the
bluff end of a mountain, about eight miles distant, and as he was
already beyond the French left, instant confusion pervaded their
camp: a thick smoke arose from Condeixa, the columns were seen
hurrying towards Casal Nova; and the British immediately pushed
forward. The felled trees and other obstacles impeded their advance
at first, and a number of fires, simultaneously kindled, covered the
retreating troops with smoke, while the flames of Condeixa stopped
the artillery, hence the skirmishers and some cavalry only could
close with the rear of the enemy, but so rapidly, as to penetrate
between the division at Fonte Coberta and the rest of the French;
and it is affirmed that the prince of Esling, who was on the road, only
escaped capture by taking the feathers out of his hat and riding
through some of the light troops.
Condeixa being thus evacuated, the British cavalry pushed
towards Coimbra, opened the communication with Trant, and cutting
off Montbrun, captured a part of his horsemen. The rest of the army
kindled their fires, and the light division planted piquets close up to
the enemy; but, about ten at night, the French divisions, whose
presence at Fonte Coberta was unknown to lord Wellington, stole
out, and passing close along the front of the British posts, made for
Miranda de Corvo. The noise of their march was heard, but the night
was dark, it was imagined to be the moving of the French baggage
to the rear, and being so reported to sir William Erskine, that officer,
without any further inquiry, put the light division in march at day-light
on the 14th.

C O M B AT O F C A S A L N O VA .

The morning was so obscured that nothing could be descried at


the distance of a hundred feet, but the sound of a great multitude
was heard on the hills in front; and it being evident that the French
were there in force, many officers represented the rashness of thus
advancing without orders and in such a fog; but Erskine, with an
astounding negligence, sent the fifty-second forward in a simple
column of sections, without a vanguard or other precaution, and
even before the piquets had come in from their posts. The road
dipped suddenly, descending into a valley, and the regiment was
immediately lost in the mist, which was so thick, that the troops
unconsciously passing the enemy’s outposts had like to have
captured Ney himself, whose bivouac was close to the piquets. The
riflemen followed in a few moments, and the rest of the division was
about to plunge into the same gulf; when the rattling of musketry and
the booming of round shot were heard, and the vapour slowly rising,
discovered the fifty-second on the slopes of the opposite mountain,
engaged, without support, in the midst of the enemy’s army.
At this moment lord Wellington arrived. His design had been to
turn the left of the French, for their front position was very strong,
and behind it they occupied the ridges, in succession, to the Deuca
river and the defiles of Miranda de Corvo. There was, however, a
road leading from Condeixa to Espinhal, and the fourth division was
already in march by it for Panella, having orders, to communicate
with Nightingale; to attack Reynier; and to gain the sources of the
Deuca and Ceira rivers: between the fourth division and Casal Nova
the third division was more directly turning the enemy’s left flank; and
meanwhile the main body was coming up to the front, but as it
marched in one column, required time to reach the field. Howbeit
Erskine’s error forced on this action, and the whole of the light
division were pushed forward to succour the fifty-second.
The enemy’s ground was so extensive, and his skirmishers so
thick and so easily supported, that, in a little time, the division was
necessarily stretched out in one thin thread, and closely engaged in
every part, without any reserve; nor could it even thus present an
equal front, until Picton sent the riflemen, of the sixtieth, to prolong
the line. Nevertheless, the fight was vigorously maintained amidst
the numerous stone enclosures on the mountain side; some
advantages were even gained, and the right of the enemy was
partially turned; yet the main position could not be shaken, until
Picton near and Cole further off, had turned it by the left. Then, the
first, fifth, and sixth divisions, the heavy cavalry, and the artillery,
came up on the centre, and Ney commenced his retreat, covering
his rear with guns and light troops, and retiring from ridge to ridge
with admirable precision, and, for a long time, without confusion and
with very little loss. Towards the middle of the day, however, the
British guns and the skirmishers got within range of his masses, and
the retreat became more rapid and less orderly; yet he finally gained
the strong pass of Miranda de Corvo, which had been secured by
the main body of the French.
Montbrun also rejoined the army at Miranda. He had summoned
Coimbra on the 13th at noon, and, without waiting for an answer,
passed over the mountain and gained the right bank of the Deuca by
a very difficult march. The loss of the light division this day was
eleven officers and a hundred and fifty men; that of the enemy was
greater, and about a hundred prisoners were taken.
During the action of the 14th, Reynier, seeing the approach of the
fourth division, hastily abandoned Panella; and Cole having effected
a junction with Nightingale, passed the Deuca; when Massena
fearing lest they should gain his rear, set fire to the town of Miranda,
and passed the Ceira that night. His whole army was now
compressed and crowded in one narrow line, between the higher
sierras and the Mondego; and to lighten the march, he destroyed a
great quantity of ammunition and baggage; yet his encumbrances
were still so heavy, and the confusion in his army so great, that he
directed Ney to cover the passage with a few battalions; yet charged
him not to risk an action. Ney, however, disregarding this order, kept
on the left bank, ten or twelve battalions, a brigade of cavalry, and
some guns.

C O M B AT O F F O Z D ’ A R O N C E .

The 15th, the weather was so obscure that the allies could not
reach the Ceira, before four o’clock in the evening, and the troops,
as they came up, proceeded to kindle fires for the night; thinking that
Ney’s position being strong, nothing would be done. The French right
rested on some thickly wooded and rugged ground, and their left
upon the village of Foz d’Aronce, but lord Wellington, having cast a
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