Table of Contents....5
About the Authors....24
About the Technical Reviewers....25
Acknowledgments....27
Introduction....27
Chapter 1: Introduction to Anomaly Detection....30
What Is an Anomaly?....30
Anomalous Swans....30
Anomalies as Data Points....34
Anomalies in a Time Series....37
Personal Spending Pattern....38
Taxi Cabs....41
Categories of Anomalies....44
Data Point–Based Anomalies....44
Context-Based Anomalies....45
Pattern-Based Anomalies....47
Anomaly Detection....47
Outlier Detection....49
Noise Removal....49
Novelty Detection....50
Event Detection....50
Change Point Detection....50
Anomaly Score Calculation....52
The Three Styles of Anomaly Detection....52
Where Is Anomaly Detection Used?....53
Data Breaches....53
Identity Theft....55
Manufacturing....57
Networking....59
Medicine....59
Video Surveillance....60
Environment....60
Summary....60
Chapter 2: Introduction to Data Science....62
Data Science....63
Dataset....63
Pandas, Scikit-Learn, and Matplotlib....67
Data I/O....68
Data Loading....69
Data Saving....72
DataFrame Creation....72
Data Manipulation....75
Select....75
Filtering....89
Sorting....106
Applying Functions....120
Grouping....130
Combining DataFrames....135
Creating, Renaming, and Dropping Columns....147
Data Analysis....156
Value Counts....156
Pandas .describe() Method....157
Pandas Correlation Matrix....158
Visualization....162
Line Chart....162
Chart Customization....164
Scatter Plot....168
Histogram....169
Bar Graph....169
Data Processing....170
Nulls....171
Categorical Encoding....177
Scaling and Normalizing....186
Feature Engineering and Selection....190
Summary....202
Chapter 3: Introduction to Machine Learning....203
Machine Learning....204
Introduction to Machine Learning....204
Data Splitting....211
Modeling and Evaluation....212
Classification Metrics....217
Regression Metrics....226
Overfitting and Bias-Variance Tradeoff....228
Hyperparameter Tuning....240
Validation....244
Summary....247
Chapter 4: Traditional Machine Learning Algorithms....247
Traditional Machine Learning Algorithms....248
Isolation Forest....248
Example of an Isolation Forest....250
Anomaly Detection with an Isolation Forest....253
Data Preparation....254
Training....261
Hyperparameter Tuning....265
Evaluation and Summary....275
One-Class Support Vector Machine....279
How Does OC-SVM Work?....280
Anomaly Detection with OC-SVM....291
Data Preparation....291
Training....295
Hyperparameter Tuning....300
Evaluation and Summary....303
Summary....307
Chapter 5: Introduction to Deep Learning....308
Introduction to Deep Learning....310
What Is Deep Learning?....310
The Neuron....314
Activation Functions....317
Neural Networks....337
Loss Functions....347
Regression....347
Classification....349
Gradient Descent and Backpropagation....353
Loss Curve....371
Regularization....375
Optimizers....376
Multilayer Perceptron Supervised Anomaly Detection....390
Simple Neural Network: Keras....397
Simple Neural Network: PyTorch....408
Summary....418
Chapter 6: Autoencoders....418
What Are Autoencoders?....419
Simple Autoencoders....422
Sparse Autoencoders....444
Deep Autoencoders....448
Convolutional Autoencoders....450
Denoising Autoencoders....459
Variational Autoencoders....470
Summary....490
Chapter 7: Generative Adversarial Networks....491
What Is a Generative Adversarial Network?....492
Generative Adversarial Network Architecture....496
Wasserstein GAN....499
WGAN-GP....502
Anomaly Detection with a GAN....504
Summary....520
Chapter 8: Long Short-Term Memory Models....520
Sequences and Time Series Analysis....522
What Is an RNN?....525
What Is an LSTM?....526
LSTM for Anomaly Detection....534
Examples of Time Series....563
art_daily_no_noise.csv....564
art_daily_nojump.csv....565
art_daily_jumpsdown.csv....567
art_daily_perfect_square_wave.csv....570
art_load_balancer_spikes.csv....572
ambient_temperature_system_failure.csv....574
ec2_cpu_utilization.csv....576
rds_cpu_utilization.csv....577
Summary....579
Chapter 9: Temporal Convolutional Networks....579
What Is a Temporal Convolutional Network?....580
Dilated Temporal Convolutional Network....587
Anomaly Detection with the Dilated TCN....593
Encoder-Decoder Temporal Convolutional Network....615
Anomaly Detection with the ED-TCN....619
Summary....640
Chapter 10: Transformers....641
What Is a Transformer?....641
Transformer Architecture....646
Transformer Encoder....647
Transformer Decoder....655
Transformer Inference....658
Anomaly Detection with the Transformer....658
Summary....689
Chapter 11: Practical Use Cases and Future Trends of Anomaly Detection....689
Anomaly Detection....690
Real-World Use Cases of Anomaly Detection....694
Telecom....694
Banking....697
Environmental....699
Health Care....702
Transportation....707
Social Media....708
Finance and Insurance....710
Cybersecurity....711
Video Surveillance....716
Manufacturing....718
Smart Home....721
Retail....722
Implementation of Deep Learning–Based Anomaly Detection....722
Future Trends....725
Summary....727
Index....729
Beginning Anomaly Detection Using Python-Based Deep Learning begins with an introduction to anomaly detection, its importance, and its applications. It then covers core data science and machine learning modeling concepts before delving into traditional machine learning algorithms such as OC-SVM and Isolation Forest for anomaly detection using scikit-learn. Following this, the authors explain the essentials of machine learning and deep learning, and how to implement multilayer perceptrons for supervised anomaly detection in both Keras and PyTorch. From here, the focus shifts to the applications of deep learning models for anomaly detection, including various types of autoencoders, recurrent neural networks (via LSTM), temporal convolutional networks, and transformers, with the latter three architectures applied to time-series anomaly detection. This edition has a new chapter on GANs (Generative Adversarial Networks), as well as new material covering transformer architecture in the context of time-series anomaly detection.
After completing this book, you will have a thorough understanding of anomaly detection as well as an assortment of methods to approach it in various contexts, including time-series data. Additionally, you will have gained an introduction to scikit-learn, GANs, transformers, Keras, and PyTorch, empowering you to create your own machine learning- or deep learning-based anomaly detectors.
Data scientists and machine learning engineers of all levels of experience interested in learning the basics of deep learning applications in anomaly detection.