liveBook · Manning

Anomaly

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

An extreme value is an observation or value located unusually far toward an edge of an observed distribution.

An outlier is an extreme value near an edge of an observed distribution. It deserves investigation, not automatic deletion: it may be a data-collection error, a unit mismatch created while combining tables, or a legitimate rare case that matters to the analysis. section 2.4.2 section 7.1.5

Start by inspecting descriptive statistics. Compare each numeric feature’s minimum and maximum with its mean, then use charts to see the distribution’s shape. Boxplots make unusually distant observations visible across many features; histograms help distinguish isolated extremes from a skewed distribution. section 2.4.2 section 7.1.5

Choose a response only after identifying why the value is extreme:

  • Correct or remove values caused by errors, such as measures expressed in centimeters in one table and meters in another. section 2.4.2
  • Keep legitimate rare observations when they reflect the question being analyzed; removing them solely because they are unusual can discard meaningful cases. section 2.4.2
  • Cap a feature’s upper tail with winsorization when extreme predictor values need limiting, then inspect the revised boxplot. section 7.1.5
  • For a regression target with problematic tails, use percentiles to define a central range, visualize the selected distribution, and filter predictors and target together. section 7.1.6

Checking an unusually large target value

A target with minimum 1,450, average 36,573, and maximum 1,306,500 signals a possible right-tail problem. Percentiles sharpen the diagnosis: when the 99th percentile remains far below the maximum, select a percentile-bounded range and plot its density before retaining that subset for modeling. section 7.1.6

Listing 7.9 Winsorizing extreme values
from scipy.stats.mstats import winsorize
 
lower_cut_percentile = 0.00                           #1
upper_cut_percentile = 0.001                          #2
 
X['minimum_nights'] = winsorize(X['minimum_nights'].values, 
                                limits=(lower_cut_percentile, 
upper_cut_percentile))
 
X[['minimum_nights']].boxplot()

This listing caps the highest 0.1% of minimum_nights values with scipy’s winsorize, preserving rows while reducing the influence of the most extreme upper-tail values. section 7.1.5

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Explains detection through descriptive statistics, charts, and percentiles, then demonstrates winsorization and percentile-based filtering rather than formal outlier tests.
Examples
Uses Auto MPG numeric features, accommodation predictors capped by winsorization, and an accommodation-price target filtered with percentile bounds.
What it assumes
Assumes familiarity with tabular numeric features and pandas-style descriptive statistics while teaching practical inspection from dataset summaries and charts.
What you can do after
Evaluate/understand whether extreme observations are errors, legitimate cases, or candidates for capping or percentile-based exclusion.
How it connects
Connects outliers with missing data, skewed distributions, descriptive statistics, boxplots, histograms, winsorization, and regression targets.

Also explained in

Compare how 14 books explain anomaly →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.