liveBook · Manning

What you will learn in Outlier Detection in Python

by Brett Kennedy

Chapter by chapter

Chapter 1: Introducing outlier detection

1.1 Why do outlier detection? · 1.1.1 Financial fraud · 1.1.2 Credit card fraud · 1.1.3 Network security · 1.1.4 Detecting bots on social media · 1.1.5 Industrial processes · 1.1.6 Self-driving vehicles · 1.1.7 Healthcare · 1.1.8 Astronomy · 1.1.9 Data quality · 1.1.10 Evaluating segmentation · 1.2 Outlier detection’s place in machine learning · 1.3 Outlier detection in tabular data · 1.4 Definitions of outliers · 1.5 Trends in outlier detection · 1.6 How does this book teach outlier detection? · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Simple outlier detection

2.1 One-dimensional numeric outliers · 2.1.1 z-score · 2.1.2 Interquartile range · 2.1.3 Median absolute deviation · 2.1.4 Modified z-score · 2.1.5 Visualization for numeric outliers · 2.1.6 Internal and external outliers · 2.1.7 Scoring outliers · 2.2 One-dimensional categorical outliers: Rare values · 2.3 Multidimensional outliers · 2.3.1 Types of multidimensional outliers · 2.3.2 Visualization for multidimensional data · 2.4 Rare combinations of categorical values · 2.4.1 Rare combinations using their absolute count · 2.4.2 Combinations that are rare given their marginal probabilities · 2.5 Rare combinations of numeric values · 2.6 Noise vs. inliers and outliers · 2.7 Local and global outliers · 2.8 Combining the scores of univariate tests · 2.9 Summary

What you learn in chapter 2 →

Chapter 3: Machine learning-based outlier detection

3.1 The curse of dimensionality · 3.1.1 Data sparsity · 3.1.2 Data appearing in the margins · 3.1.3 Distance calculations · 3.2 Types of algorithms · 3.2.1 Distance based · 3.2.2 Density based · 3.2.3 Cluster based · 3.2.4 Frequent item set based · 3.2.5 Model based · 3.3 Types of detectors · 3.3.1 Clean vs. contaminated training data · 3.3.2 Numeric vs. categorical · 3.3.3 Local vs. global detectors · 3.3.4 Scores vs. flags · 3.3.5 The time required for training and predicting · 3.3.6 The ability to process many features · 3.3.7 The parameters required · 3.4 Summary

What you learn in chapter 3 →

Chapter 4: The outlier detection process

4.1 Outlier detection workflow · 4.2 Determining the types of outliers we are interested in · 4.2.1 Statistical outliers · 4.2.2 Specific outliers · 4.2.3 Known and unknown outliers · 4.3 Choosing the type of model to be used · 4.3.1 Selecting the category of outlier detector · 4.3.2 Rules-based approaches · 4.3.3 Classifier-based approaches · 4.4 Collecting the data · 4.5 Examining the data · 4.6 Cleaning the data · 4.7 Feature selection · 4.8 Feature engineering · 4.9 Encoding categorical values · 4.10 Scaling numeric values · 4.11 Fitting a set of models and generating predictions · 4.12 Evaluating the models · 4.13 Setting up ongoing outlier detection systems · 4.14 Refitting the models as necessary · 4.15 Summary

What you learn in chapter 4 →

Chapter 5: Outlier detection using scikit-learn

5.1 Introducing scikit-learn · 5.2 Isolation Forest · 5.2.1 The KDD Cup dataset · 5.2.2 Using Isolation Forest on the KDD Cup dataset · 5.3 LocalOutlierFactor (LOF) · 5.4 One-class SVM (OCSVM) · 5.4.1 OneClassSVM class · 5.4.2 SGDOneClassSVM · 5.5 Elliptic Envelope · 5.5.1 Mahalanobis distance · 5.5.2 Example using the EllipticEnvelope class · 5.6 Gaussian mixture models · 5.7 BallTree and KDTree · 5.8 Summary

What you learn in chapter 5 →

Chapter 6: The PyOD library

6.1 The PyOD common API · 6.2 Histogram-based Outlier Score (HBOS) · 6.3 Empirical Cumulative Distribution Function (ECOD) · 6.4 Copula-based outlier detection (COPOD) · 6.5 Angle-based outlier detection (ABOD) · 6.6 Clustering-based local outlier factor (CBLOF) · 6.7 Local correlation integral (LOCI) · 6.8 Connectivity-based outlier factor (COF) · 6.9 Principal component analysis (PCA) · 6.9.1 Univariate tests on the components · 6.9.2 PyODKernelPCA · 6.9.3 The PCA detector · 6.9.4 KPCA · 6.10 Subspace outlier detection · 6.11 FeatureBagging · 6.12 Cook’s Distance · 6.13 Using SUOD for faster model training · 6.14 The PYOD thresholds module · 6.15 Summary

What you learn in chapter 6 →

Chapter 7: Additional libraries and algorithms for outlier detection

7.1 Example synthetic test sets · 7.2 The alibi-detect library · 7.3 The PyCaret library · 7.4 Local outlier probability (LoOP) · 7.5 Local distance-based outlier factor (LDOF) · 7.6 Extended Isolation Forest (EIF) · 7.7 Outlier Detection Using In-degree Number (ODIN) · 7.8 Clustering · 7.8.1 Mahalanobis distance per cluster · 7.8.2 Kernel density estimation per cluster · 7.8.3 Clustering with categorical data · 7.9 Entropy · 7.10 Association Rules · 7.11 Convex Hull · 7.12 Distance metric learning (DML) · 7.13 NearestSample · 7.14 Summary

What you learn in chapter 7 →

Chapter 8: Evaluating detectors and parameters

8.1 The effect of the number of neighbors · 8.1.1 2D plots of results · 8.1.2 1D plots of results · 8.2 Contour plots · 8.2.1 Examining parameter choices with contour plots · 8.2.2 Examining detectors with contour plots · 8.3 Visualizing subspaces in real-world data · 8.3.1 2D plots of results on real-world data · 8.3.2 Contour plots on real-world data · 8.4 Correlation between detectors with full real-world datasets · 8.5 Modifying real-world data · 8.5.1 Adding known anomalies · 8.5.2 Evaluation metrics · 8.5.3 Evaluating detectors using accuracy metrics · 8.5.4 Adjusting the training size used · 8.5.5 Adding extreme values · 8.6 Testing with classification datasets · 8.7 Timing experiments · 8.8 Summary

What you learn in chapter 8 →

Chapter 9: Working with specific data types

9.1 Null values · 9.2 Special data types · 9.2.1 Phone numbers · 9.2.2 Addresses · 9.2.3 Email addresses · 9.2.4 ID/Code values · 9.2.5 Dates · 9.2.6 High-cardinality categorical columns · 9.3 Text features · 9.3.1 Extracting NLP features · 9.3.2 Topic modeling · 9.3.3 Clustering text values · 9.4 Encoding categorical data · 9.4.1 One-hot encoding · 9.4.2 Ordinal encoding · 9.4.3 Count encoding · 9.5 Scaling numeric values · 9.6 Binning numeric data · 9.7 Distance metrics · 9.7.1 Distance metrics for numeric data · 9.7.2 Gower’s distance metric for mixed data · 9.7.3 Distance metrics for categorical data · 9.7.4 Using categorical distance metrics for mixed data · 9.8 Summary

What you learn in chapter 9 →

Chapter 10: Handling very large and very small datasets

10.1 Data with many features · 10.1.1 Dimensionality reduction · 10.1.2 Feature subspaces · 10.2 Data with many rows · 10.2.1 Training and predicting on data samples · 10.2.2 Testing models for stability · 10.2.3 Segmenting data · 10.2.4 Running in parallel vs. in sequence · 10.2.5 Tools for working with large datasets · 10.3 Working with very small datasets · 10.4 Summary

What you learn in chapter 10 →

Chapter 11: Synthetic data for outlier detection

11.1 Creating synthetic data to represent inliers · 11.1.1 Testing with realistic inlier data · 11.1.2 Using realistic synthetic inliers for training · 11.2 Generating new synthetic data · 11.2.1 Libraries to generate new synthetic data · 11.2.2 Using patterns between features · 11.2.3 Using GMMs · 11.3 Doping · 11.4 Simulations · 11.5 Training classifiers to distinguish real from fake data · 11.6 Summary

What you learn in chapter 11 →

Chapter 12: Collective outliers

12.1 Purchases data · 12.2 Preparing the data · 12.3 Testing for duplicates · 12.4 Testing for gaps · 12.5 Testing for missing combinations · 12.6 Creating new tables to capture collective outliers · 12.6.1 Aggregating by entity · 12.6.2 Aggregating by two or more entity types · 12.6.3 Aggregating by time · 12.6.4 Aggregating by entity and time · 12.6.5 Merging in additional information · 12.7 Identifying trends · 12.8 Unusual distributions · 12.9 Rolling windows features · 12.10 Tests for unusual numbers of point anomalies · 12.11 Summary

What you learn in chapter 12 →

Chapter 13: Explainable outlier detection

13.1 Introducing XAI · 13.1.1 Interpretability vs. explainability · 13.1.2 Global vs. local explanations · 13.2 Post hoc explanations · 13.2.1 Feature importances · 13.2.2 Proxy models · 13.2.3 Plotting · 13.2.4 Counterfactuals · 13.2.5 General notes on post hoc explanations · 13.3 Interpretable outlier detectors · 13.3.1 Outlier detection on sets of 2D subspaces · 13.3.2 Bayesian Histogram-based Anomaly Detection · 13.3.3 CountsOutlierDetector · 13.3.4 DataConsistencyChecker · 13.4 Summary

What you learn in chapter 13 →

Chapter 14: Ensembles of outlier detectors

14.1 Overview of ensembling for outlier detection · 14.2 Accuracy metrics with ensembles · 14.3 Methods to create ensembles · 14.3.1 Different model types · 14.3.2 Different preprocessing · 14.3.3 Different hyperparameters · 14.3.4 Sampling the original features · 14.3.5 Different engineered features · 14.3.6 Sampling rows · 14.4 Selecting detectors for an ensemble · 14.4.1 Manually inspecting the superset of many detectors · 14.4.2 Taking the consensus of many detectors · 14.4.3 Testing random subsets of detectors · 14.4.4 Greedy methods to identify a set of detectors · 14.4.5 Selecting detectors to minimize correlation · 14.5 Scaling scores · 14.5.1 Min-max scaling · 14.5.2 z-scores (standard scaling) · 14.5.3 Robust scaling · 14.5.4 MAD scaling · 14.5.5 Ranking · 14.5.6 Box Cox · 14.6 Combining scores · 14.6.1 Mean vs. maximum · 14.6.2 PyOD ensembling methods · 14.6.3 Variations of mean and maximum · 14.6.4 Weighting based on accuracy · 14.6.5 Stacked ensembles · 14.7 Summary

What you learn in chapter 14 →

Chapter 15: Working with outlier detection predictions

15.1 Hand-labeling output · 15.1.1 Hand-labeling specific types of outliers · 15.1.2 Hand-scoring the outliers · 15.2 Examining the flagged outliers · 15.2.1 Manual inspection of the outliers · 15.2.2 Executing interpretable detectors · 15.2.3 Examining subspaces of features · 15.3 Automating the process of sorting outlier detection results · 15.3.1 Rules to sort the output of detectors · 15.3.2 Classifiers to sort the output of detectors · 15.3.3 Executing rules and classifiers on flagged outliers · 15.4 Semisupervised learning · 15.4.1 Using labeled data to create a stacked model · 15.4.2 XGBOD · 15.5 Regression testing · 15.6 Summary

What you learn in chapter 15 →

Chapter 16: Deep learning-based outlier detection

16.1 Introducing neural networks · 16.2 PyOD · 16.2.1 Autoencoders · 16.2.2 Variational autoencoders · 16.2.3 Generative adversarial networks · 16.2.4 SO_GAAL · 16.2.5 MO_GAAL · 16.2.6 DeepSVDD · 16.2.7 Deep IF · 16.3 Image data · 16.3.1 Techniques for outlier detection with image data · 16.3.2 Astronomaly · 16.4 alibi-detect · 16.5 Self-supervised learning for outlier detection with tabular data · 16.5.1 Introducing embeddings · 16.5.2 Embeddings for outlier detection · 16.5.3 Transfer learning · 16.5.4 Self-supervised methods for tabular data · 16.5.5 DeepOD · 16.6 Summary

What you learn in chapter 16 →

Chapter 17: Time-series data

17.1 Cross-sectional, panel, and time-series data · 17.2 Types of time-series outliers · 17.2.1 Extreme values · 17.2.2 Contextual point outliers · 17.2.3 Outliers based on decomposition · 17.2.4 Ruptures · 17.2.5 Outliers based on tabular representations · 17.2.6 Forecasting-based time-series outlier detection · 17.2.7 Unusual shapes of windows in timelines · 17.2.8 Tabular outlier detection on windows of data · 17.2.9 Mulivariate time-series outliers · 17.3 Tools for time-series data · 17.3.1 Anomaly Detection Toolkit · 17.3.2 DeepOD · 17.3.3 Prophet · 17.4 Summary

What you learn in chapter 17 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.