liveBook · Manning

Indicator variable

As explained in Outlier Detection in Python

A data column whose values indicate membership using two possible states, commonly 0 and 1.

An indicator variable is a binary data column whose two states record whether a condition is true. In tabular work, the states commonly appear as 0 and 1. The condition may be missingness, category membership, format validity, or another testable property. section 9.1 section 9.2.1

For missing data, create one indicator per original column before imputation. The indicator preserves the information that a value was absent, while the original column can be filled with a median, mode, or other detector-compatible value. A row-level count can additionally indicate how many values are missing. section 9.1

Indicator variables also represent categorical membership. One-hot encoding creates a binary column for every distinct category, allowing categorical values to enter many outlier detectors. This representation is useful but can overweight high-cardinality categorical features, especially for random-feature methods and distance calculations. section 9.4.1

Common indicator-variable patterns include:

  • Missingness indicator: records whether an original value is null or not null. section 9.1
  • Category indicator: records membership in one category, such as a department, account, color, or size. section 9.4.1
  • Validity or pattern indicator: records whether a value matches an expected format, such as a phone-number pattern. section 9.2.1

Missingness indicators for a table

Given columns A and B, derive A Null and B Null with isna(), derive Num Null by counting missing cells across each row, and then impute A and B separately. The indicators retain missingness as a signal for later detection. section 9.1

How Outlier Detection in Python covers it

How deep it goes
Explains construction and practical trade-offs, but stops short of formal statistical theory for binary representations.
Examples
Demonstrates null flags, department indicators, color and size encodings, and phone-number format features.
What it assumes
Assumes tabular columns and basic pandas operations while demonstrating binary encoding from ordinary values.
What you can do after
Build it from scratch with pandas to preserve missingness, encode categories, and flag values matching or violating a format.
How it connects
Connects indicator variables to missing values, imputation, one-hot encoding, categorical data, outlier detection, IsolationForest, and distance calculations.

Also explained in

Compare how 4 books explain indicator variable →

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.