liveBook · Manning

Swamping

As explained in Outlier Detection in Python

Swamping is an outlier effect in which extreme observations cause otherwise typical observations to be incorrectly identified as outliers.

Swamping occurs when an extreme observation distorts an outlier detector so that an otherwise typical observation is incorrectly flagged. With z-scores, the extreme value shifts the mean and standard deviation, making observations on the opposite side of the mean appear unusually distant. Swamping is the opposite of masking, where extreme observations hide other outliers. section 2.1.1

Points A, B, and C

In a swarm plot, extreme point A can swamp point C: C is classified as an outlier only when A remains in the dataset. Point B illustrates masking because A prevents B from being flagged. section 2.1.1

Use swamping as a warning when evaluating outlier detectors:

  • Treat z-score flags cautiously when extreme values influence the mean and standard deviation. section 2.1.1
  • Check whether data preparation removes strong outliers before fitting detectors. section 8.5.5
  • Test robustness explicitly because clustering-based methods can degrade sharply when extreme training values are added. section 8.5.5
Figure 2.2 A swarm plot with at least one outlier, point A. Depending on the presence of A, points B and C may or may not be flagged as outliers, as A can affect the mean and standard deviation.

Inspect how the presence of one extreme point changes which neighboring observations receive outlier flags. section 2.1.1

for i in range(10):
  col_name = np.random.choice(df.columns)
  max_val = clean_df[col_name].max()
  clean_df.loc[i, col_name] = max_val * 100.0

Use the extreme-value injection example to test whether a detector remains reliable after contaminated training data is introduced. section 8.5.5

How Outlier Detection in Python covers it

How deep it goes
Explains the mean-and-standard-deviation mechanism and demonstrates detector sensitivity, but stops short of deriving a general correction.
Examples
Uses swarm-plot points A, B, and C plus injected extreme training values to expose false flags and detector degradation.
What it assumes
Assumes familiarity with outliers, z-scores, means, and standard deviations while distinguishing swamping from masking.
What you can do after
Diagnose/debug with it whether extreme training observations distort z-score or clustering-based detector results.
How it connects
Connects outlier detection with z-scores, masking, mean, standard deviation, clustering, and detector robustness.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.