100% found this document useful (4 votes)
23 views66 pages

Complete Download Beginning Anomaly Detection Using Python-Based Deep Learning 2 / Converted Edition Suman Kalyan Adari PDF All Chapters

Deep

Uploaded by

xenyanurra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
23 views66 pages

Complete Download Beginning Anomaly Detection Using Python-Based Deep Learning 2 / Converted Edition Suman Kalyan Adari PDF All Chapters

Deep

Uploaded by

xenyanurra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Download Full Version ebookmass - Visit ebookmass.

com

Beginning Anomaly Detection Using Python-Based


Deep Learning 2 / converted Edition Suman Kalyan
Adari

https://ebookmass.com/product/beginning-anomaly-detection-
using-python-based-deep-learning-2-converted-edition-suman-
kalyan-adari/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Beginning Anomaly Detection Using Python-Based Deep


Learning, 2nd Edition Suman Kalyan Adari

https://ebookmass.com/product/beginning-anomaly-detection-using-
python-based-deep-learning-2nd-edition-suman-kalyan-adari/

ebookmass.com

From Deep Learning to Rational Machines [converted]


Cameron J. Buckner

https://ebookmass.com/product/from-deep-learning-to-rational-machines-
converted-cameron-j-buckner/

ebookmass.com

Machine Learning on Geographical Data Using Python 1st


Edition Joos Korstanje

https://ebookmass.com/product/machine-learning-on-geographical-data-
using-python-1st-edition-joos-korstanje/

ebookmass.com

Risk Factor Michael Brandman

https://ebookmass.com/product/risk-factor-michael-brandman/

ebookmass.com
Neuromechanics of Human Movement 5th Edition, (Ebook PDF)

https://ebookmass.com/product/neuromechanics-of-human-movement-5th-
edition-ebook-pdf/

ebookmass.com

Understanding Crypto Fundamentals: Value Investing in


Cryptoassets and Management of Underlying Risks 1st
Edition Thomas Jeegers
https://ebookmass.com/product/understanding-crypto-fundamentals-value-
investing-in-cryptoassets-and-management-of-underlying-risks-1st-
edition-thomas-jeegers/
ebookmass.com

Biopolymer-Based Metal Nanoparticle Chemistry for


Sustainable Applications Mahmoud Nasrollahzadeh

https://ebookmass.com/product/biopolymer-based-metal-nanoparticle-
chemistry-for-sustainable-applications-mahmoud-nasrollahzadeh/

ebookmass.com

(eTextbook PDF) for Cultural Anthropology A Perspective on


the Human Condition 10th Edition

https://ebookmass.com/product/etextbook-pdf-for-cultural-anthropology-
a-perspective-on-the-human-condition-10th-edition/

ebookmass.com

LIFESPAN NEUROREHABILITATION A Patient Centered Approach


from Examination to Interventions and Outcomes 1st
Edition, (Ebook PDF)
https://ebookmass.com/product/lifespan-neurorehabilitation-a-patient-
centered-approach-from-examination-to-interventions-and-outcomes-1st-
edition-ebook-pdf/
ebookmass.com
A Mary Blair treasury of Golden Books Unknown Various

https://ebookmass.com/product/a-mary-blair-treasury-of-golden-books-
unknown-various/

ebookmass.com
Beginning Anomaly

Detection Using

Python-Based Deep

Learning

Implement Anomaly Detection

Applications with Keras and PyTorch

Second Edition

Suman Kalyan Adari

Sridhar Alla

Beginning Anomaly Detection Using Python-Based Deep Learning:


Implement

Anomaly Detection Applications with Keras and PyTorch, Second Edition

Suman Kalyan Adari

Sridhar Alla

Tampa, FL, USA

Delran, NJ, USA

ISBN-13 (pbk): 979-8-8688-0007-8

ISBN-13 (electronic): 979-8-8688-0008-5

https://doi.org/10.1007/979-8-8688-0008-5

Copyright © 2024 by Suman Kalyan Adari, Sridhar Alla


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: Gryffin Winkler

Cover designed by eStudioCalamar

Cover image by Tony [email protected]

Distributed to the book trade worldwide by Apress Media, LLC, 1 New York
Plaza, New York, NY 10004,

U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail 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.

For information on translations, please e-mail


[email protected]; for reprint,

paperback, or audio rights, please e-mail


[email protected].

Apress titles may be purchased in bulk for academic, corporate, or


promotional use. eBook versions and

licenses are also available for most titles. For more information, reference
our Print and eBook Bulk Sales web page at 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 (https://github.com/Apress). For more detailed


information, please visit

https://www.apress.com/gp/services/source-code.
Paper in this product is recyclable

Table of Contents

About the Authors


������������������������������
������������������������������
������������������������������
���������� ix About the Technical Reviewers
������������������������������
������������������������������
������������������� xi Acknowledgments
������������������������������
������������������������������
������������������������������
������� xiii Introduction
������������������������������
������������������������������
������������������������������
�������������������xv Chapter 1: Introduction
to Anomaly Detection
������������������������������
��������������������������� 1

What Is an Anomaly?
������������������������������
������������������������������
������������������������������
��������������������������� 1

Anomalous Swans
������������������������������
������������������������������
������������������������������
������������������������� 1
Anomalies as Data Points
������������������������������
������������������������������
������������������������������
�������������� 4

Anomalies in a Time Series


������������������������������
������������������������������
������������������������������
����������� 6

Categories of Anomalies
������������������������������
������������������������������
������������������������������
������������������� 12

Data Point–Based Anomalies


������������������������������
������������������������������
������������������������������
������� 12

Context-Based
Anomalies�������������������������
������������������������������
������������������������������
����������������� 13

Pattern-Based Anomalies
������������������������������
������������������������������
������������������������������
������������ 14
Anomaly Detection
������������������������������
������������������������������
������������������������������
���������������������������� 14

Outlier Detection
������������������������������
������������������������������
������������������������������
�������������������������� 15

Noise Removal
������������������������������
������������������������������
������������������������������
�����������������������������
15

Novelty Detection
������������������������������
������������������������������
������������������������������
������������������������ 16

Event Detection
������������������������������
������������������������������
������������������������������
��������������������������� 16

Change Point Detection


������������������������������
������������������������������
������������������������������
��������������� 16
Anomaly Score Calculation
������������������������������
������������������������������
������������������������������
���������� 17

The Three Styles of Anomaly Detection


������������������������������
������������������������������
�������������������������� 17

Where Is Anomaly Detection Used?


������������������������������
������������������������������
������������������������������
�� 18

Data Breaches
������������������������������
������������������������������
������������������������������
�����������������������������
18

Identity Theft
������������������������������
������������������������������
������������������������������
������������������������������
�� 19

Manufacturing
������������������������������
������������������������������
������������������������������
�����������������������������
20
iii

Table of ConTenTs

Networking
������������������������������
������������������������������
������������������������������
������������������������������
���� 21

Medicine
������������������������������
������������������������������
������������������������������
������������������������������
�������� 21

Video Surveillance
������������������������������
������������������������������
������������������������������
����������������������� 22

Environment
������������������������������
������������������������������
������������������������������
������������������������������
�� 22

Summary��������������������������
������������������������������
������������������������������
������������������������������
����������������� 22
Chapter 2: Introduction to Data Science
������������������������������
������������������������������
����� 23

Data Science
������������������������������
������������������������������
������������������������������
������������������������������
������� 24

Dataset
������������������������������
������������������������������
������������������������������
������������������������������
���������� 24

Pandas, Scikit-Learn, and Matplotlib


������������������������������
������������������������������
������������������������� 27

Data I/O
������������������������������
������������������������������
������������������������������
������������������������������
���������� 28

Data Manipulation
������������������������������
������������������������������
������������������������������
����������������������� 33
Data Analysis
������������������������������
������������������������������
������������������������������
������������������������������
� 75

Visualization
������������������������������
������������������������������
������������������������������
������������������������������
�� 79

Data
Processing�������������������������
������������������������������
������������������������������
������������������������������
�� 85

Feature Engineering and Selection


������������������������������
������������������������������
��������������������������� 96

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 103

Chapter 3: Introduction to Machine Learning


������������������������������
������������������������� 105
Machine Learning
������������������������������
������������������������������
������������������������������
��������������������������� 106

Introduction to Machine
Learning��������������������������
������������������������������
������������������������������
�� 106

Data Splitting
������������������������������
������������������������������
������������������������������
�����������������������������
111

Modeling and Evaluation


������������������������������
������������������������������
������������������������������
����������� 112

Overfitting and Bias-Variance Tradeoff


������������������������������
������������������������������
�������������������� 121

Hyperparameter Tuning
������������������������������
������������������������������
������������������������������
������������� 130
Validation
������������������������������
������������������������������
������������������������������
������������������������������
���������� 132

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 134

Chapter 4: Traditional Machine Learning Algorithms


������������������������������
������������� 135

Traditional Machine Learning Algorithms


������������������������������
������������������������������
���������������������� 136

Isolation Forest
������������������������������
������������������������������
������������������������������
�������������������������� 136

One-Class Support Vector Machine


������������������������������
������������������������������
������������������������� 159

Summary��������������������������
������������������������������
������������������������������

������������������������������
������������������������������
��������������� 182

iv

Table of ConTenTs

Chapter 5: Introduction to Deep


Learning��������������������������
������������������������������
����� 183

Introduction to Deep Learning


������������������������������
������������������������������
������������������������������
�������� 185

What Is Deep Learning?


������������������������������
������������������������������
������������������������������
������������ 185

The Neuron
������������������������������
������������������������������
������������������������������
������������������������������
�� 187

Activation Functions
������������������������������
������������������������������
������������������������������
������������������ 189
Neural Networks
������������������������������
������������������������������
������������������������������
������������������������ 203

Loss
Functions��������������������������
������������������������������
������������������������������
������������������������������
� 210

Gradient Descent and Backpropagation


������������������������������
������������������������������
������������������ 213

Loss Curve
������������������������������
������������������������������
������������������������������
������������������������������
��� 224

Regularization������������������������
������������������������������
������������������������������
������������������������������
���� 227

Optimizers
������������������������������
������������������������������
������������������������������
������������������������������
��� 228
Multilayer Perceptron Supervised Anomaly Detection
������������������������������
�������������������������� 238

Simple Neural Network: Keras


������������������������������
������������������������������
������������������������������
��� 243

Simple Neural Network: PyTorch


������������������������������
������������������������������
�����������������������������
251

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 260

Chapter 6: Autoencoders
������������������������������
������������������������������
�������������������������� 261

What Are Autoencoders?


������������������������������
������������������������������
������������������������������
����������������� 262

Simple Autoencoders
������������������������������
������������������������������

������������������������������
������������������������������
���������������������� 264

Sparse Autoencoders
������������������������������
������������������������������
������������������������������
���������������������� 281

Deep Autoencoders
������������������������������
������������������������������
������������������������������
������������������������� 284

Convolutional
Autoencoders������������������������
������������������������������
������������������������������
������������������ 286

Denoising Autoencoders
������������������������������
������������������������������
������������������������������
����������������� 294

Variational Autoencoders
������������������������������
������������������������������
������������������������������
���������������� 304

Summary��������������������������
������������������������������
������������������������������

������������������������������
������������������������������
��������������� 320

Chapter 7: Generative Adversarial Networks


������������������������������
������������������������� 321

What Is a Generative Adversarial Network?


������������������������������
������������������������������
������������������ 322

Generative Adversarial Network Architecture


������������������������������
������������������������������
���������� 325

Wasserstein GAN
������������������������������
������������������������������
������������������������������
����������������������� 327

WGAN-GP
������������������������������
������������������������������
������������������������������
������������������������������
����� 329

Anomaly Detection with a GAN


������������������������������
������������������������������
������������������������������
�� 330

��������������������������
Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 343

Table of ConTenTs

Chapter 8: Long Short-Term Memory Models


������������������������������
������������������������� 345

Sequences and Time Series Analysis


������������������������������
������������������������������
���������������������������� 346

What Is an RNN?
������������������������������
������������������������������
������������������������������
�����������������������������
349

What Is an LSTM?
������������������������������
������������������������������
������������������������������
��������������������������� 350

LSTM for Anomaly Detection


������������������������������
������������������������������
������������������������������
����������� 355
Examples of Time Series
������������������������������
������������������������������
������������������������������
����������������� 377

art_daily_no_noise�csv
������������������������������
������������������������������
������������������������������
������������� 378

art_daily_nojump�csv
������������������������������
������������������������������
������������������������������
���������������� 379

art_daily_jumpsdown�csv
������������������������������
������������������������������
������������������������������
��������� 381

art_daily_perfect_square_wave�csv
������������������������������
������������������������������
����������������������� 384

art_load_balancer_spikes�csv
������������������������������
������������������������������
������������������������������
�� 386

ambient_temperature_system_failure�csv
������������������������������
������������������������������
������������������������������
�������������� 387

ec2_cpu_utilization�csv
������������������������������
������������������������������
������������������������������
������������� 389

rds_cpu_utilization�csv
������������������������������
������������������������������
������������������������������
������������� 390

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 392

Chapter 9: Temporal Convolutional Networks


������������������������������
������������������������ 393

What Is a Temporal Convolutional Network?


������������������������������
������������������������������
����������������� 394

Dilated Temporal Convolutional Network


������������������������������
������������������������������
���������������������� 399

Anomaly Detection with the Dilated TCN


������������������������������

������������������������������
������������������������������
����������������� 404

Encoder-Decoder Temporal Convolutional Network


������������������������������
������������������������������
������ 421

Anomaly Detection with the ED-TCN


������������������������������
������������������������������
����������������������� 424

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 441

Chapter 10: Transformers


������������������������������
������������������������������
������������������������� 443

What Is a Transformer?
������������������������������
������������������������������
������������������������������
������������������� 443

Transformer Architecture
������������������������������
������������������������������
������������������������������
����������� 446
Transformer Encoder
������������������������������
������������������������������
������������������������������
����������������� 447

Transformer Decoder
������������������������������
������������������������������
������������������������������
����������������� 452

Transformer Inference
������������������������������
������������������������������
������������������������������
��������������� 455

Anomaly Detection with the Transformer


������������������������������
������������������������������
���������������� 455

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 480

vi

Table of ConTenTs

Chapter 11: Practical Use Cases and Future Trends of Anomaly Detection
��������� 481

Anomaly Detection
������������������������������
������������������������������
������������������������������
������������������������������
�������������������������� 482

Real-World Use Cases of Anomaly Detection


������������������������������
������������������������������
���������������� 485

Telecom
������������������������������
������������������������������
������������������������������
������������������������������
������� 485

Banking
������������������������������
������������������������������
������������������������������
������������������������������
������� 487

Environmental
������������������������������
������������������������������
������������������������������
��������������������������� 488

Health Care
������������������������������
������������������������������
������������������������������
������������������������������
�� 490
Transportation
������������������������������
������������������������������
������������������������������
��������������������������� 493

Social Media
������������������������������
������������������������������
������������������������������
������������������������������
494

Finance and Insurance


������������������������������
������������������������������
������������������������������
�������������� 495

Cybersecurity������������������������
������������������������������
������������������������������
������������������������������
����� 496

Video Surveillance
������������������������������
������������������������������
������������������������������
��������������������� 499

Manufacturing
������������������������������
������������������������������
������������������������������
��������������������������� 500
Smart Home
������������������������������
������������������������������
������������������������������
������������������������������
� 503

Retail
������������������������������
������������������������������
������������������������������
������������������������������
����������� 504

Implementation of Deep Learning–Based Anomaly Detection


������������������������������
�������������������� 504

Future Trends
������������������������������
������������������������������
������������������������������
������������������������������
���� 506

Summary��������������������������
������������������������������
������������������������������
������������������������������
��������������� 508

Index
������������������������������
������������������������������
������������������������������
��������������������������� 511
vii

About the Authors

Suman Kalyan Adari is currently a machine learning research engineer. He


obtained a

B.S. in computer science at the University of Florida and an M.S. in


computer science,

specializing in machine learning, at Columbia University. He has been


conducting

deep learning research in adversarial machine learning since his freshman


year at the

University of Florida and has presented at the IEEE Dependable Systems


and Networks

workshop on Dependable and Secure Machine Learning held in Portland,


Oregon,

USA in June 2019. Currently, he works on various anomaly detection tasks


spanning

behavioral tracking and geospatial trajectory modeling.

He is quite passionate about deep learning, and specializes in various fields


ranging

from video processing to generative modeling, object tracking, time-series


modeling,

and more.

Sridhar Alla is the co-founder and CTO of Bluewhale, which helps


organizations big
and small in building AI-driven big data solutions and analytics, as well as
SAS2PY, a

powerful tool to automate migration of SAS workloads to Python-based


environments

using Pandas or PySpark. He is a published author of books and an avid


presenter

at numerous Strata, Hadoop World, Spark Summit, and other conferences.


He also

has several patents filed with the US PTO on large-scale computing and
distributed

systems. He has extensive hands-on experience in several technologies,


including Spark,

Flink, Hadoop, AWS, Azure, TensorFlow, Cassandra, and others. He spoke


on anomaly

detection using deep learning at Strata SFO in March 2019 and at Strata
London in

October 2019. He was born in Hyderabad, India, and now lives in New
Jersey with his

wife, Rosie, his daughters, Evelyn and Madelyn, and his son, Jayson. When
he is not busy

writing code, he loves to spend time with his family and also training,
coaching, and

organizing meetups.

ix
About the Technical Reviewers

Puneet Sinha has accumulated more than 12 years of work

experience in developing and deploying end-to-end models

in credit risk, multiple marketing optimization, A/B testing,

demand forecasting and brand evaluation, profit and price

analyses, anomaly and fraud detection, propensity modeling,

recommender systems, upsell/cross-sell models, modeling


response to incentives, price optimization, natural language

processing, and OCR using ML/deep learning algorithms.

Shubho Mohanty is a product thinker and creator, bringing

two decades of experience in the “concept-to- market”

life cycle of some of the unique, innovative, and highly

successful industry-first products and platforms in the data

and security spaces.

Shubho holds 12+ US patents in data, analytics, and

cloud security. He has also been awarded IDG CIO100, 2020

for strategizing and developing a technology innovation

ecosystem.

He currently serves as the Chief Product Officer at Calibo, where he leads


the

product vision, strategy, innovation, and development of Calibo’s enterprise


PaaS. Prior

to Calibo, Shubho was the Global VP of Product & Engineering at CDK


Global (formerly,

ADP Inc). He has also served in various product leadership roles in


organizations like

Symantec and Microsoft. He also co-founded Ganos, a B2B data start-up.

He received his B.Tech. in Electrical Engineering from National Institute of

Technology (NIT), India. He is a mentor to many high-repute start-up


programs where
he guides young entrepreneurs to solve some of the most pressing
challenges. He is also

an influential speaker at leading technology and industry forums.

xi

Acknowledgments

Suman Kalyan Adari

I would like to thank my parents, Krishna and Jyothi, my sister, Niha, and
my loving dog,

Pinky, for supporting me throughout the entire process of writing this book
as well as my

various other endeavors.

Sridhar Alla

I would like to thank my wonderful, loving wife, Rosie Sarkaria, and my


beautiful,

loving children, Evelyn, Madelyn, and Jayson, for all their love and patience
during the

many months I spent writing this book. I would also like to thank my
parents, Ravi and

Lakshmi Alla, for their blessings and all the support and encouragement they
continue

to bestow upon me.

xiii

Introduction
Congratulations on your decision to explore the exciting world of anomaly
detection

using deep learning!

Anomaly detection involves finding patterns that do not adhere to what is

considered as normal or expected behavior. Businesses could lose millions


of dollars

due to abnormal events. Consumers could also lose millions of dollars. In


fact, there are

many situations every day where people’s lives are at risk and where their
property is at

risk. If your bank account gets cleaned out, that’s a problem. If your water
line breaks,

flooding your basement, that’s a problem. If all flights at an airport get


delayed due to a

technical glitch in the traffic control system, that’s a problem. If you have a
health issue

that is misdiagnosed or not diagnosed, that’s a very big problem that directly
impacts

your well-being.

In this book, you will learn how anomaly detection can be used to solve
business

problems. You will explore how anomaly detection techniques can be used
to address

practical use cases and address real-life problems in the business landscape.
Every
business and use case is different, so while we cannot copy and paste code
and build a

successful model to detect anomalies in any dataset, this book will cover
many use cases

with hands-on coding exercises to give you an idea of the possibilities and
concepts

behind the thought process. All the code examples in the book are presented
in Python

3.8. We choose Python because it is truly the best language for data science,
with a

plethora of packages and integrations with scikit-learn, deep learning


libraries, etc.

We will start by introducing anomaly detection, and then we will look at


legacy

methods of detecting anomalies that have been used for decades. Then we
will look

at deep learning to get a taste of it. Then we will explore autoencoders and
variational

autoencoders, which are paving the way for the next generation of generative
models.

Following that, we will explore generative adversarial networks (GANs) as a


way to detect

anomalies, delving directly into generative AI.

Then we’ll look at long short-term memory (LSTM) models to see how
temporal data
can be processed. We will cover temporal convolutional networks (TCNs),
which are

excellent for temporal data anomaly detection. We will also touch upon the
transformer

xv

InTroduCTIon

architecture, which has revolutionized the field of natural language


processing as

another means for temporal anomaly detection. Finally, we will look at


several examples

of anomaly detection in various business use cases.

In addition, all coding examples will be provided in TensorFlow 2/Keras,


with

accompanying PyTorch equivalents, on the GitHub repository for this book.


You will

combine all this extensive knowledge with hands-on coding using Jupyter
notebook-

based exercises to experience the knowledge firsthand and see where you
can use these

algorithms and frameworks. Best of luck, and welcome to the world of deep
learning!

xvi

CHAPTER 1

Introduction to Anomaly
Detection

In this chapter, you will learn about anomalies in general, the categories of
anomalies,

and anomaly detection. You will also learn why anomaly detection is
important, how

anomalies can be detected, and the use case for such a mechanism.

In a nutshell, this chapter covers the following topics:

• What is an anomaly?

• Categories of different anomalies

• What is anomaly detection?

• Where is anomaly detection used?

What Is an Anomaly?

Before you get started with learning about anomaly detection, you must first
understand

what exactly you are targeting. Generally, an anomaly is an outcome or


value that

deviates from what is expected, but the exact criteria for what determines an
anomaly

can vary from situation to situation.

Anomalous Swans

To get a better understanding of what an anomaly is, let’s take a look at some
swans

sitting by a lake (Figure 1-1).


1

© Suman Kalyan Adari, Sridhar Alla 2024

S. K. Adari and S. Alla, Beginning Anomaly Detection Using Python-Based


Deep Learning,

https://doi.org/10.1007/979-8-8688-0008-5_1
Chapter 1 IntroduCtIon to anomaly deteCtIon

Figure 1-1. A couple swans by a lake

Let’s say that we want to observe these swans and make assumptions about
the

color of the swans at this particular lake. Our goal is to determine what the
normal

color of swans is and to see if there are any swans that are of a different
color than this

(Figure 1-2).

Figure 1-2. More swans show up, all of which are white

2
Random documents with unrelated
content Scribd suggests to you:
Debt on more reasonable terms, from which they expect to save
from 60,000l. to 80,000l. pr. ann.
The affair of the Princess is drawing to a public disclosure of the
whole proceedings. The Prince has been advised by Romilly and
Garrow[278] to make application to the King that the charges against
the Princess may be tried in a Court of Common Law; and, on the
other hand, the Princess has been advised by her law counsellors to
publish her defence, which must lead, of course, to a publication of
the charges and evidence against her. It is said that her defence is
printing, and will be published on Wednesday.[279]
The Opposition are a disjointed, incoherent body, dissatisfied with
their situation, and with one another. Canning has made private
overtures to Ld. Grenville to be taken into office when an opportunity
presents itself, declaring himself greatly discontented with his
present associates. His demands are:—a high appointment for
himself, a place for Sturges, and a peerage for Sr. Hy. Mildmay. Ld.
G. seems not entirely disinclined to listen to such overtures. He is
very much out of humour with Whitbread for his speech on the first
day of the session, which, he scrupled not to say to Ld. Howick,
betrayed sentiments and views utterly inconsistent with those on
which Ministers had conducted the negotiation. But if Whitbread is
set aside, and Ld. Grey die, Petty would be left almost alone in the
House of Commons, and though his success there during the
present session has been greater than the most sanguine of his
friends could have hoped for, still he would require an able seconder,
especially if Whitbread went eagerly into Opposition. These
considerations may weigh with Ld. G., and he may also be desirous
of having a speaker of the first rank in the House of Commons, more
connected with himself, and less attached to the Whig party than
Petty. Mr. Grenville is unwilling to be an every day speaker in the
House of Commons. C. Williams has no voice; Ld. Temple is not
listened to; but Canning, if brought into office now, would attach
himself to Ld. Grenville as he did to Pitt, and become his peculiar
organ in the H. of C. Ld. Wellesley has probably been the channel of
communication. Whitbread and Ld. Howick are far from being
cordial, and unfortunately the conduct of the former tends to widen
every day the breach between them, and his pretensions are so
high, that independent of the obstacles which he is himself creating,
it would be difficult for Ministry to satisfy him: nothing will content
him, but to be considered as on a par with Lauderdale for
pretensions.
There is every reason to fear that we shall be
forced into war with Turkey by the violence of EXPEDITION
Russia, though the Turks have made every TO
possible concession.[280] It is feared that we have CONSTANTINO
PLE
already taken possession of the Turkish fleet, and
bombarded Constantinople. Arbuthnot has orders to give the Turks
the alternative of dismissing Sebastiani, or having a war with
England. Windham and T. Grenville have, between them, given
orders without the knowledge of their colleagues, in the event of a
war with Turkey, for 5000 men to be taken from the army of Sicily,
and employed in taking and garrisoning Alexandria. Craufurd has
been overtaken, and stopped from going to Valparaiso.
Monroe has had a conversation with Ld. H. about Spanish
America; he wishes nothing to be attempted without a concert with
the United States, the country to be declared independent, and free
ports to be opened to both the invading powers. His accounts from
Armstrong[281] represent that there are great differences among the
French generals, and that this alone has prevented Bonaparte’s
return to Paris where his presence was also required.
March 8th.—The Princess has not published her defence, but it is
said she has got it printed at a private press belonging to Perceval,
and she threatens to publish it next Friday, if not previously received
at Court on Thursday. It is said that her coarseness of language
disgusts even her partisans.
The overtures of Canning are taken into
consideration, and have been the subject of CABINET
conversation between Lds. Grenville, Howick, and CHANGES
Holland. There is an idea that Lauderdale,
Whitbread, and Canning may be introduced into the Cabinet.
Canning now requires Charles Long,[282] Huskisson, and old G.
Rose[283] to have places. Some of these and Ld. Camden are only
named pro forma, and would be sacrificed if he could be taken in.
How room can be made does not very readily appear. When the
Doctor was told of Canning’s proposals, he said, that in the present
stage of the business, he was not called upon to interfere, but that if
it was proposed to bring Canning into office, his line was taken.[284]
There is no reason whatever for any change at present, except the
alleged necessity of dismissing Windham on account of his great
mismanagement in his office and his conduct as War Secretary, and
the reduction of strength in the H. of Commons, especially should
Windham go with Opposition. But the real cause is said to be Lord
Grenville’s restlessness of disposition, which makes him dissatisfied
at the end of six months with every arrangement he forms. Ld. H. is
averse to these changes on the score of unfairness to Addington,
who must be made the sacrifice, especially as they conducted
themselves (apparently, a cautious saving always necessary,
however, for the Doctor’s conduct) well in the late discussions with
the King, and because he is naturally averse to the return of so many
of the Pitt-ites to power; and also that Canning’s introduction to the
Cabinet is the elevation of a rival to Petty. The latter opinion,
however, is more my own, and has inspired me with great distrust to
the proceedings. Petty, who at my earnest desire has been apprised
of the affair, as the injunction was that it was not to transpire, is, of
course, against it. Therefore if Ld. Howick (over whom Ld. Grenville
has acquired great influence) is of the same mind, there will be little
or no difficulty in counteracting it. Whitbread’s impatience for office,
and Ld. Howick’s extreme desire to have no political difference with
him, makes him lend a readier ear to such a plan than he would
otherwise do.
There is an expedition to be undertaken, which on acct. of
Erskine’s extraordinary imprudence in talking, is to be kept a secret
from the Cabinet, and only known to a few. Bad accounts from
Drummond[285] of the Court of Sicily; strong measures are to be
resorted to without delay to bring them to a more reasonable line of
conduct. All Frenchmen in the service of Sicily to be dismissed; none
but Sicilians to be employed in the service of the State; nominations
of all officers in the army to be left to the British Commander-in-
Chief; grievances to be redressed by the convocation of the Sicilian
Parlt. If these terms are not complied with, we are to declare we
cannot defend the island, and if refused, force employed to
effectuate them. General Fox, Sr. John Moore, and Drummond are
to be associated in a joint Commission for this important object.[286]
Sr. Sidney Smith, who has been gained over by the Queen and is
completely subservient to her, is ordered on a different service. The
fury and violence of the Queen’s character have not abated by age,
and her other passions have as little diminished. Ld. Ellenboro’ said,
in the discussion of this business, that our Sicilian Alliance seemed
to him to cost £600,000 pr. ann., for no other purpose than to
maintain a —— house at Palermo.
Overtures for negotiations between France and Russia. Our
Governt. have expressed through Ld. Douglas[287] our readiness to
become parties to a negotiation for peace, and have expressed our
wish that if a Congress is to be held for that purpose, it should be
appointed at Copenhagen; but it has been distinctly explained to
Russia, that the French Colonies shall not be restored in return for
the restitution of the conquests made from Prussia.
There are hopes that the Irish Catholics may be
induced to postpone their Petition till another THE CATHOLIC
session. Ld. Ponsonby’s letters are favourable to QUESTION
this expectation, and Mr. Butler has expressed the
same hopes to Ld. Holland.
14th March.—Before it is decided whether Ministers are to go out,
or accommodate their present differences with the K., I shall try and
collect as well as I can, all the important particulars which have led
things to the present vexatious state. It was the intention of Ld.
Grenville, not only to extend the provisions of the Irish Act of 1793 to
the whole British Army, but also to open Staff appointments to the
Catholics, but this dispatch to the King was expressed with some
degree of ambiguity, so that it might be construed to mean that he
intended only to extend the provisions of the Irish Act to this country.
It was so understood by the King, Lds. Sidmouth, and Howick; and
when transmitted to Ireland and read by Mr. Elliot to the Catholics, it
appeared so ambiguous, that when they demanded an explanation
of this point, Mr. E. wrote to Ld. Spencer for instructions how to
answer them. This letter was sent to Lord Grenville, and answered
by him without any consultation with his colleagues. In his answer he
expressed surprise that Mr. Elliot should have had any difficulty upon
the subject, and authorised him to inform the Catholics that it was
the intention of Governt. to remove all disabilities whatever in the
army attaching to members of their Church.
When Ld. Sidmouth understood the misconception under which
he had laboured with regard to the meaning of the proposed clause,
he appeared to be extremely distressed, and expressed himself very
doubtful whether he should not enter into an explanation with the
King, in order to explain his own conduct in the whole affair. But at
length he determined that, if no communication was made on the
subject by the Cabinet, he should take no notice whatever of it; as it
was uncertain in what light the dispatch might have been viewed by
the King, and whether he had understood by it that the new clauses
were to be exactly the same as those of the Irish Act in 1793, or to
apply also to the Staff appointments. It was judged proper by the
Cabinet to say nothing of this difficulty and contrariety of opinions to
the King, but to send to him the proposed clauses, which it was
found afterwards more convenient to be made into a separate Bill,
and to leave him to object to them if they were different from what he
was prepared for.
This having been done, and Ld. Howick having waited upon him
on Wednesday, 4th March, he remarked that the clauses went
further than the Irish Mutiny Bill, and when Ld. Howick explained to
him how far they were to be carried, he started, and exclaimed, ‘I’m
sorry for it, I can’t approve of it’; and in the course of their
conversation on the subject, in which Ld. Howick urged all the
arguments for the measure, he appeared not to be more reconciled,
but as Ld. Howick understood, he still gave his consent that the Bill
in its present form should be brought into Parlt. On coming out of the
closet, Lord Howick communicated his conversation to Ld. Grenville
and Ld. Sidmouth, the former of whom remarked, that since Lord
Howick had had this conversation with the King, he should not speak
on the subject to His Majesty, as he knew it to be so disagreeable to
him. Ld. Sidmouth, it appears, did hold some conversation on the
subject to the King, in which he repeated Ld. Howick’s conversation
in a sense which induced the K. to believe that the additional clauses
would not be brought into Parliament till some further
communications were held with him. Ld. Howick, having a different
impression of his conversation, brought the proposed Bill into the
House, which was read the first time, and ordered to be printed.
On Monday, the 9th, or Tuesday, the 10th, Ld.
Grenville received a mysterious letter from Ld. THE CATHOLIC
Sidmouth regretting that he must differ from his QUESTION
colleagues on so important a point as the Catholic
Bill, and requesting to have a conversation with him on the subject.
From this conversation it appeared that he was determined to
oppose the Bill in the House of Lords, and that his friends should
take the same line in the H. of Commons. As it appeared from this
and other circumstances that the King and his friends were resolved
to oppose the Bill, it became a question what course it was proper
for Ministers to pursue. It was proposed by some to bring the Bill
through the Commons, so as to pledge that House on the subject,
and if any placemen voted against it, to turn them out instantly, or
propose doing so to the King; and if this measure should not be
assented to by him, not to insist upon it immediately, nor yet quite
give it up, but bring the Bill into the H. of Lords, and on its rejection in
that House, to resign, and commence an active and vigorous
Opposition. But to this course of proceeding it was objected by Ld.
Grenville that it would lead to a protracted contest between the King
and the Ministry, which, in the present state of affairs, could not but
be prejudicial to the country; and the question was therefore
proposed whether they should resign, or yield the question in
dispute.
This was argued at his house on Wednesday, 11th, in the
evening, at a meeting consisting of Ld. Grenville, Mr. Grenville, Lds.
Howick, Holland, Henry Petty. Both the Grenvilles said they were
ready to go out if their colleagues thought they could not retreat with
honour, but they showed themselves very unwilling to that measure.
Petty said the same, with the same reluctant offer. The great
argument for not breaking with the King on this point was that this
case would appear a bad one to the public, as it might be plausibly
argued that they had deceived the King and committed his Governt.
to more than he had authorised them to grant. Lds. Howick and
Holland, who were the most averse to concession, were induced at
length to give up, seeing that their colleagues, though they offered to
resign upon this point, did it reluctantly and with a grudge; and being
also satisfied that the whole transaction with the King might be
represented in the light that was argued by the others.
On Thursday, the 12th, Ld. Howick had an
audience of the King, in which the K. behaved to THE CATHOLIC
him in the most civil manner, paid him compliments QUESTION
to himself and family, lamented that Ld. Howick
had so far misunderstood him in their last conversation, as to
imagine that he had his consent to propose the Bill to Parlt., but
declared himself satisfied that this was a mere misapprehension on
his own side, in consequence of his understanding the reverse to be
Ld. Howick’s idea of the conversation from Ld. Sidmouth soon after
he parted from Ld. Howick. He assured Ld. Howick that he had
spoken of the affair to no persons out of the Cabinet, except to
persons of his own family; that he had taken no measures to form an
Administration, and that if he must separate from his present
advisers, he trusted that, as he had behaved and should behave
honourably to them, they would not retire from his service till he had
made arrangements to supply their place. He expressed himself in
the most flattering manner to Ld. Howick personally, and remarked
that he had not been aware till lately of his sentiments on the
Catholic question. It seems, when Ld. Sidmouth told him the week
before what were Ld. Howick’s opinions on that subject, he started
with evident surprise, from which it was argued some days ago that
in the end he would yield. Ld. Howick endeavoured to extract from
him what was the most he would concede in the present question to
the Catholics, but found him resolved not to go beyond the Irish Act
of 1793. When Ld. Howick mentioned the extending the same to the
Navy, he started and expressed disapprobation. When Ld. Howick
said, if the clauses were extended to the Catholics in England, they
must also be extended to the Protestant Dissenters (who were not
included in the Irish Act, because the Test Act was abolished in
Ireland in 1774 or 1775), he started again, and exclaimed, ‘But this is
attacking the Establishment.’ In a word, he consents to the extension
of the Act of ’93 to England, but to nothing more.
Rumours are afloat of the resignation of the Doctor, of the whole
Ministry going out, of the Catholic Bill being abandoned, etc.; and
Canning—the worthless Canning!—who was eight days ago actually
in terms with Ld. Grenville, actually treating with Ld. Grenville and
holding with him a private correspondence for the purpose of being
taken into office, is now thick with Perceval, and ready, they say, to
oppose any Bill brought forward to relieve the Catholics. The
behaviour of the Doctor is still problematical. Ld. Grenville is greatly
exasperated with him, but Ld. Holland, with more indulgence than
justice, is disposed to view his conduct more favourably, and to
believe that his misconception of the measure was real, and his
sorrow unfeigned when he discovered what was intended to be
done. But Ld. Sidmouth certainly misrepresented Ld. Howick’s
conversation with him to the King, and it is now said that he has
been intriguing for the last ten days with Perceval. The D. of
Cumberland was very busy in the H. of Lords communicating to his
friends the joyful news of a change of Ministry.
The clauses were sent to Windsor on Tuesday, March 3rd, and
returned by the King the same evening, without any animadversion
or objection; on which they were instantly despatched by a
messenger to Ireland. Very suspicious against the veracity of H.M.
15th March.—(On Friday, the 13th, Ld. Sidmouth did offer to
resign, but it was not accepted by Ld. Grenville.)
There was a Cabinet to-day at which neither Ld. Ellenboro’ or
Sidmouth assisted. It was then determined to withdraw the Bill which
had given His Majesty so much uneasiness, but to reserve to the
members of the Cabinet as individuals to express their opinion on
the Catholic claims if brought before Parlt. by the Catholics, which
measure, however, the members of the Cabinet pledged themselves
not to encourage or recommend the Catholics to adopt.
The reasons for giving up the Bill were as follows:—
1st. The K. considered himself as pledged to no more than ye
Irish Act of ’93, and was determined to resist any further concession
to the Catholics. But the mere extension of the Irish Act of 1793
would not tend in any degree to satisfy the C., nor to allay their
discontent, while it would be unjust and unfair to the English
Dissenters, whom it would place on a worse footing than the Irish
Catholics.
2nd. But if the Bill, modified and reduced as it is
by the King, would be useless and objectionable, THE CATHOLIC
the prosecution of the original Bill could not be QUESTION
persisted in, without incurring the reproach of
having taken advantage of the King; of having deceived him into
acquiescence with a measure not properly explained to him; and
when the mistake was cleared up, of having made use of the
opportunity to commit the House of Commons on a measure so
decidedly contrary to his opinion. If the Bill was dropped on acct. of
those last considerations, the Ministry must either resign, or go on
with the disadvantage of having abandoned a measure of so much
importance, and of having been baffled by the K. and a most
contemptible colleague. In their voluntary resignation there were
many objections. It would preclude them from employing their
present strength in the H. of Commons in addressing the King
against the change of his confidential advisers, because whatever
might be the cause of their resignation, the act, if voluntary,
necessarily compelled the King to look for other advisers; and till
those advisers were tried, it would appear factious to move
addresses against them. Besides this reason for not resigning, the
question of the C. was not popular in the kingdom, and a cry could
be easily raised against it and its friends. It was therefore resolved to
go on for the present, but as the King had now discovered his
strength, and as little confidence or cordiality could longer exist
between him and his present Ministers, it was determined to take the
first popular ground of difference, and to resign upon it; and to take
off the impression of having been baffled by Ld. Sidmouth, it was
determined that he should be instantly turned out. Besides these
reasons for the line taken upon this occasion by the Cabinet, there
were several who persistently indulged the hope that the King would
not be satisfied with this concession, but that he would demand
some further pledge on which they might make a stand on better
ground than they occupied at present. The event proved their
sagacity.
16th March.—On Monday, 16th, Ld. Grenville went down to
Windsor with the Minute which had been agreed to on the day before
in the Cabinet. The K. required 24 hours to consider of his answer,
and on Tuesday morning he sent the following to Ld. Grenville:—
17th March, Windsor Castle.
‘The King having fully considered what is submitted in the Minute of
Cabinet which he received yesterday morning, desires Ld. G. will
communicate to those who were present his sentiments and
observations upon the contents of that Minute as hereafter explained.
‘His Majesty has learned with satisfaction that they have
determined not to press forward any further the discussion of the Bill
depending in Parlt., and he is sensible of the deference shown to his
sentiments and feelings, but he regrets that while they have felt bound
as his Ministers to adopt this line of conduct, they should as
individuals consider it necessary to submit to Parlt. opinions which are
known to be so decidedly contrary to his principles, at a moment too
when it is the declared object of his Governt. not to encourage any
disposition on the part of the R. Catholics of Ireland to prefer a Petition
to Parliament.
‘From the latter part of the Minute the K. must
conclude, that altho’ the Bill which was depending THE
is dropped, they have been unable to make up their CATHOLIC
minds not to press upon him in future measures QUESTION
connected with a question which has already
proved so distressing to him, nor can H.M. conceal from them that this
intimation on their part, unless withdrawn, will leave the matter in a
state most embarrassing and unsatisfactory to him, and in his opinion
not less to them. The K. therefore considers it due to himself and
consistent with fair and upright conduct, which it has and ever will be
his object to observe towards everyone, to declare at once most
unequivocally that upon this subject his sentiments never can change,
that he cannot ever agree to any concession which his confidential
servants may in future propose to him; and that under these
circumstances and after what has passed, his mind cannot be at ease
unless he shall receive a positive assurance from them which shall
effectually relieve him from all future apprehension.
‘(Signed) George R.’

The preceding note was enclosed in the following:—


March 17th, 1807.
‘The King has lost no time in dictating the answer to the Minute of
Cabinet. Ld. Grenville will receive it enclosed, and H.M. desires he will
communicate it to his colleagues, trusting at the same time that Ld.
Grenville will see the propriety, with a view to the prevention of all
future mistakes, that when they shall have duly considered the latter
part of His Majesty’s answer, their determination should be stated on
paper.
‘(Signed) George R.’
When these notes were received by Ld. Grenville the Ministry
were in a very embarrassing situation, in consequence of having
received the night before Ld. Spencer’s resignation, which he sent to
Ld. Grenville the instant he was informed that the Bill in Parlt. was to
be abandoned, thinking himself particularly pledged to it, as being
the person through whom it had been communicated to the Irish
Governt. and to the Catholics that such a Bill was determined upon.
The King’s notes were therefore received with the greatest
satisfaction, as it enabled the whole of the Ministry, Ld. Sidmouth
and his friends excepted, to retire from office upon good and
constitutional grounds, while their offer to abandon the Bill exempted
them from any charge of having deceived or attempted to overreach
the K. A respectful but firm answer was therefore sent, refusing to
give the pledge for their future conduct which the King demanded.
18th.—The answer of the Cabinet was given to the King this
morning. He is to take, as before, 24 hours to think of his reply.
He was to-day (Wednesday) very civil to Ld. Howick, hoped that if
they did part, they should part with a more favourable impression of
each other than they had entertained before they met. Assured him
that he had consulted with no one, not even with his own family,
about forming a new Administration.
The Prince takes part with his father on this the present question,
and he is full of complaints against Ministers for their conduct to him
in his difference with the Princess. Lady Hertford has great influence
with him at present, and she employs it. It is not many weeks since
that he offered to write a letter to Ld. Howick for the purpose of its
being shown to the Catholics, in which he would have pledged
himself to the Catholics, provided they remained quiet at present. Ld.
Holland did not encourage this measure, because as he had once
broken his word to the Catholics, it was supposed that a promise
from him would have little or no effect upon them. Ld. Moira is also
extremely dissatisfied with the greater part of his colleagues; he told
Ld. H. two nights ago that if this rupture had not taken place, he
would have resigned shortly, and that when they went out he should
resign his Staff appointments, and consider himself as no longer
connected in party with his present colleagues. He complained that
since Mr. Fox’s illness no one, except Ld. Holland, had treated him
confidentially.[288]
Ld. H. this morning, through Ld. Granville
Leveson, proposed a Cabinet place immediately to A NEW
Canning if they should remain in office, or return to ADMINISTRATI
it after a victory over the Court. Ld. G. Leveson ON
received the overtures thus made rather coldly. He
seemed to think that Canning would take the opposite side to Ld.
Sidmouth, and in the evening he seemed disturbed by a speech of
Bragge’s,[289] who had said when asked what part Ld. Sidmouth’s
friends meant to take in the present differences, ‘Why, stick by the
King, to be sure.’ It is not known that any person has as yet been
sent for by the K. to consult with about a new Administration.
19th.—Letters from the D. of Bedford and Ld. Ponsonby. It seems
that the Catholics had been induced by the exertions of Ld.
Ponsonby and representations from the Castle, aided by the proof
given by Ministers of their unabated zeal in their cause by the
clauses in the Mutiny Bill, to abandon the intention of petitioning
Parliament this session. But when these letters were written,
rumours had arrived of the difficulties in carrying through the Mutiny
Bill, and that Ministers were suspected of an intention to give way
upon that point.
Early to-day Lds. Eldon and Hawkesbury went to Windsor in
consequence of a message from the King communicated to them by
ye D. of Cumberland. In the course of the morning they called upon
ye D. of Portland, with the King’s commands to form a new
Administration and to consult on that subject with two of Mr. Pitt’s
friends. Reports of the D. of Portland declining to act on acct. of his
infirmities; others again that he declined acting if Ld. Melville was to
be one of the Ministers, or if it was resolved to dissolve Parlt. Ld. C.
Spencer came from Burlington House and reported them as being
greatly alarmed. Ld. Hardwicke[290] called in the evening at Ld.
Grenville’s, and having inquired into the truth of the pledge said to
have been demanded by the King from his Ministers, Ld. G. showed
him the King’s note, on which Ld. Hardwicke expressed himself
perfectly satisfied with the conduct of Ministers and thought they
could not have acted otherwise with honour, and that those who had
advised the King to demand such a pledge were impeachable. He
concluded by assuring Ld. Grenville of his support and of that of his
brother, Mr. Yorke.[291] Wilberforce also called on Ld. Grenville, and
expressed much concern for what had happened, as well as
approbation of the conduct of Ministers.
It is said that with a view to shake the power of Ministers in order
to get rid of Windham, whom he detests, the D. of York had originally
some share in awakening his father’s scruples in the Catholic Bill. It
is also said that he now heartily repents of what he has done, and
would willingly assist to resettle matters. He justly fears a Ministry
formed of the friends of the Pss. of Wales. Both he and the Prince,
who has, but more strongly, the same fears, have offered to go down
to Windsor to endeavour to accommodate matters. The D. of
Cumberland has availed himself of the King’s insanity upon the C.
Question to effect this change. He read to him Perceval’s speech
agst. the Catholics as the sentiments of all good Protestants upon
the subject, by which the K. was exceedingly agitated, as he always
is when the subject is discussed.
When the King returned to Windsor on
Wednesday,[292] he was exceedingly agitated, and CHANGE OF
after retiring for a short time alone, he desired that MINISTRY
Col. Taylor might be sent for immediately, and
upon his coming he dictated letters to Lds. Eldon and Hawkesbury.
When Ld. Howick arrived on Thursday evening, the King told him
that it was but fair to acknowledge that he parted with his present
Ministers with regret, that he had hesitated long before he resolved
upon it, that it was not till after re-perusing their communication and
consulting with his family that he had determined upon it. That he
had never had the slightest difference with them till now, and that it
was only to get rid of a sword constantly suspended over his head
that he now resolved to dismiss them from his service. All this was
studiously told by the King’s friends, and of course the sentiments
are entitled to little or no credit.
20th.—The D. of Portland has consented to waive this objection
founded on the bad state of his health, provided any arrangement
can be devised which promises to last. They find great difficulties in
forming their arrangements. Mr. Yorke has said to Chas. Long that
he would take no part in their Administration, and that he
disapproved of their intention of forming one. Tierney reckons 220
Members in the H. of Commons steady to the late Ministers, without
including Ld. Wellesley’s members, Ld. Carrington’s, Mr. Eden, the
Saints, or the Doctor’s.
21st.—Ld. Hardwicke set off this morning to Windsor, and on his
return went to Burlington House.
Lds. Grenville, Howick, and Holland had a very long conference.
Ld. Grenville, averse to active measures; afraid ‘lest the tail should
get the better of the head.’ Ld. Howick is to write to the King, urging
the necessity of being prepared to explain the situation of Ministry in
the H. of C., if called upon on Monday.
Letters from Ireland yesterday and to-day. It appears that if they
had given up the Bill and remained in office, the D. of Bedford, Elliot,
(and probably) the Chancellor Ponsonby, would have resigned; and
Ld. Ponsonby, who has great influence over the Catholics, would
have been incensed and gone into Opposition. Charles Long told Ld.
Lauderdale that he had called upon him twice three days ago, to
have talked over the state of affairs, but it was now too late. Canning
told Ld. Holland that he doubted whether Ld. H. regretted more this
break up than he did!!! Ld. Spencer told the King on Wednesday last
his determination to resign if the Bill was abandoned.
Windham, in a sudden fit of disgust, told Ld. Grenville that he
desired he might no longer be considered as connected with him, as
he meant to attach himself to Lds. Howick and Holland solely. This
rash declaration was ill-timed, and nothing could be more ill-judged
than to do this at a moment when unanimity is so requisite, and
when all jealousies should be laid aside.
The event most to be feared at present is that the King should
consent to withdraw the pledge he demands of them; and to accept
their offer to give up the Bill with the general reservation which
accompanied that offer. This would change the public ground on
which they stand, and very probably disunite them.
22nd.—The Archbishop of Canterbury[293] is expressing
everywhere the most rapturous joy at what has taken place. He
says, ‘It is the neatest done thing possible. Ministers have given up
enough to forfeit the confidence of the Catholics, and will not
therefore have the consolation of dying martyrs in the cause.’ ‘They
have drawn their own teeth and cannot bite.’
Ld. Hardwicke dined yesterday with Ld.
Grenville. His visit yesterday to Windsor was not in CHANGE OF
consequence of any message from the King, but MINISTRY
originating from himself in order to express to His
Majesty his opinion of the proposed alteration in his Governt. He
arrived at Windsor about the same time as Ld. Eldon, and as the K.
was gone out, both had some time to wait before they had an
audience. The K. answered Ld. Hardwicke’s arguments by saying it
was a matter of conscience, and in urging Ld. Hardwicke to take
office he expressed great personal esteem for him, and added, ‘I
know the Yorkes are not given to cabals.’ Ld. Westmoreland says
this visit might have done some days ago, and served the Ministry,
but that now it is too late. The report in town was that he was sent
down by Ld. Grenville to accommodate matters.
Ld. Aberdeen says Ld. Melville is too infirm to accept offices;
others that he expects to be high in the Administration. Ld. Auckland
has written a very good letter to the King;[294] the worst, however, is
that he did this upon a former change, and his resignation is not that
of any office of emolument. His pension absorbs the salary of any
place he holds.
23rd.—King’s answer to Ld. Howick gives him permission to state
to the House that he is employed in forming a new Administration.
Dickenson, the member for Somersetshire, is to put a question to Ld.
Howick this evening in order to lead to the explanation.
Dickenson did the business very ill, and so clumsily that he did no
good by his query. His questions were whether Ministers were still in
office, and whether the reports were true that they had attempted to
surprise the King’s conscience? Ld. Howick answered the 1st
question, but declined making any reply to the 2nd. A great
attendance in the House, but usual coldness manifested to a falling
Ministry. Great diversity of opinion as to the mode of conducting the
Opposition. Ld. Grenville, of course, hampered in consequence of
the part he took in 1784. All resigned on March the 25th. The Prince
acted shabbily; what he called neutral.
The loss of all interest in public affairs was the natural effect of the
change of Administration to me. The Dissolution took place in May.
The elections turned out full as favourable as had been expected.
Bedfordshire was closely run between Fitzpatrick and Osborne, and
carried by a moderate majority. Yorkshire very triumphant in favour of
Ld. Milton;[295] Wilberforce accused and suspected of coalescing
with Lascelles, lost him greatly his popularity, and his shabby
desertion of the late Ministry.[296] A petition against Milton was ready,
and upon the point of being presented, but he judiciously procured
one also against Wilberforce, which, being held in terrorem, inclined
Wilberforce to exert and pledge himself on behalf of Ministers, who
came forward and promised to drop the petition against Ld. Milton, if
he in return would stipulate that the one against Wilberforce should
be dropped.
On ye 1st of May we went with all our family, excepting Mary,[297]
to Southampton. We lived in the Margravine’s house on the margin
of the water. The weather was remarkably fine, the scenery
agreeable, and the singularity of the arrangement of the houses and
a terrace give it a foreign air, which transported me in imagination to
happier localities.
The Cowpers[298] made us a visit of a week; the
Kinnairds took a house near to us and spent a SOUTHAMPTO
fortnight. Lauderdale, Marsh, B. Frere, and Mr. N
Horner made us a visit for a few days. We went
over to Portsmouth to take leave of Bartholomew, who was going
with Sr. Arthur Paget[299] to Constantinople. He brought with him Mr.
Morier,[300] a sensible, agreeable young man, who went in the
capacity of interpreter; he is a nephew of Ly. Radstock’s, his mother
being a Smyrnese. Made several excursions to Broadlands, the New
Forest, and Titchfield Castle, &c. The latter is remarkable for having
been the birthplace of the celebrated Ly. Russell; the last place in
England where Charles I. took refuge. It is in a ruinous state, but
even in its decay retains strong marks of its former splendour; the
stables are spacious and grand.
Returned home about 17th June, 1807. Parliament very briskly
attended; scandalous retaliation of each party upon the score of
jobbing. Unfortunate Scotch business of Adam about Ld. Cullen.[301]
Ld. Granville Leveson set off upon his Embassy to Petersburg. An
expedition fitted out to the Baltic. Treaty of Tilsit arrived.

After the delay of a fortnight, in consequence of my having a


smart bilious fever, we set off on the 22nd of August for our Scotch
tour. Our party consisted of ourselves, Charles, Mr. Allen, Marsh, Mr.
Knapp, Amelie, Aleck, Baptiste, Wm., Antonio. Being rather weak,
the journeys were to be short. The first night we slept at Dunstable.
On Sunday went through Northampton to Welford. The road
remarkably good and handsome, raised upon a chaussée, like the
public roads in France, Italy, or Spain.
On Monday passed through Leicester and Loughboro’ to
Nottingham, where we dined. It is a considerable town, well situated;
the site of the ancient castle is very striking, tho’ it is greatly
destroyed by the modern mansion which the bad taste of a Duke of
Newcastle allowed to be erected within the old walls.[302] The Trent
is rather a large river; the bridge we crossed was handsome and well
built. Ld. H. called upon the Mayor and Recorder; the Corporation
are chiefly Dissenters, and strongly attached to the Opposition. They
testified their respect for the memory of Mr. Fox by sending a
deputation from the town of Nottingham to walk at his funeral. In the
evening we were overtaken by a storm of thunder and lightning just
upon the outskirts of Sherwood Forest; I was terrified, and sought
shelter in the house of a family of the name of Lowe. We proceeded
on to Mansfield, where we slept. On Tuesday we set off at eleven,
went about two miles out of the direct road to see Hardwicke, the
prison for many years of the unfortunate Mary. The house in which
she was confined is falling into ruins; the present house was built by
the celebrated Elizabeth, Countess of Shrewsbury, after Mary had
been withdrawn from her custody.
The road to Chesterfield is pretty. Sheffield was full as dirty and
offensive as before. Slept at Penistone, a small village and bad inn
quite out of the high road. Got out and looked at the Castle of
Skipton, a valuable estate annexed to which belongs to Thanet. Got
late in the evening to Lowood Inn, by the side of Windermere. I was
not well in the night.
Wednesday.—Sent an invitation to Wordsworth,
one of the Lake poets, to come and dine, or visit us WORDSWORT
in the evening. He came. He is much superior to H
his writings, and his conversation is even beyond
his abilities. I should almost fear he is disposed to apply his talents
more towards making himself a vigorous conversationist in the style
of our friend Sharp,[303] than to improve his style of composition. He
is preparing a manual to guide travellers in their tour amongst the
Lakes. He holds some opinions on picturesque subjects with which I
completely differ, especially as to the effects produced by white
houses on the sides of the hills; to my taste they produce a cheerful
effect. He, on the contrary, would brown, or even black-work them;
he maintained his opinion with a considerable degree of ingenuity.
His objection was chiefly grounded upon the distances being
confounded by the glare of white. He seems well read in his
provincial history.
On Thursday, after stopping to see a very feeble cascade at Sr.
Daniel Le Fleming’s, we reached Keswick to dinner. We found
Southey, who had accepted our invitation. He is full of genius and
poetical enthusiasm. His History of Portugal is suspended in order
that he may publish, by way of prefatory discourse, a Life of the Cid,
which he is translating from an old Chronicle, and unfortunately into
the style and language of the Bible. He has already made that
experiment in his translation of Amadis de Gaul, and of his History of
Portugal; to suit the curiosity of the day, he is going to publish the
colonial part first.[304] This may be profitable, and the spirit of it
obtained him from Whishaw the name of ‘Voulgar Tradesman.’ In the
evening we visited his family; I was curious to see his interior. His
house is excellent and beautifully situated. He seems much beloved
by a numerous domestic circle of connections and friends; he is
surrounded by heaps of old and valuable Spanish books.
On Friday we set off to profit by the hospitality of Ld. Thanet, who
offered us the comfort and repose of Appleby. We passed by
Ullswater, but only saw the upper part of the Lake, which, from all
accounts, is very inferior in beauty to the view a few miles lower.
From Pooley Bridge we drove through a very fine country to Appleby.
On our road we got out to see Brougham Hall, a very beautiful place
belonging to Mr. Brougham’s father. The view from the terrace is
quite magnificent; the family have not inhabited the house for many
years, and it is falling fast into decay.
Appleby is placed in a commanding situation
above the town; a pretty torrent rushes beneath APPLEBY
the walls. The old Keep or Citadel was, till within CASTLE
these few years, used as the prison. Ld. Thanet is
Hereditary Sheriff of the County. The present mansion is built out of
the old Castle, or rather made within its walls. This was done by the
celebrated Ann Clifford, the heiress and representative of the Earls
of Cumberland; her daughter married a Tufton, and thus brought
these immense northern estates into the present family. She wrote
the famous letter, in reply to the solicitation of a Minister of Charles
II. or James, to allow a Court member to stand for Appleby, ‘I have
been threatened by a usurper, neglected by a Court, but will not be
bullied by a subject; your man shall not stand.’
Mr. Wyburgh, a lawyer of eminence, was in the Castle; he was
employed on an election arbitration between Ld. Lowther and
Thanet, upon the number of votes in Appleby.
Visiting Naworth Castle, where ‘Lord Carlisle occasionally comes
for a fortnight in the shooting season,’ the party entered Scotland, and
passing Longtown, Moffat, and Lanark, reached Hamilton. ‘The
Palace is reckoned gloomy. The present Duke has augmented the
collection of pictures, but the Rubens and Vandyke still maintain their
posts as the first....’
8th.—Got to Dumbarton. Slept at Aroquhar; a good inn, well
situated upon a salt loch; it was very beautiful, but we could not
admire it after having spent the day by the side of Loch Lomond, so
in a storm of hail, rain, wind, and sleet, and snow falling upon the
mountains, we reached Inverary. The Duke[305] is in perfect health;
the inmates there, the Bedfords, Ld. John[306] and Mr. Hunt, the T.
Sheridans, E. Bligh, Lewis, Chester, Cornewall, H. Scott. At difft.
times, Ld. Ely, Downshire, Messrs. Reid, Ld. John Campbell, Mr.
Campbell, Col. Callander, McDonald, and Clanronald, and others
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!

ebookmass.com

You might also like