liveBook · Manning

Categorical data

As explained in Ensemble Methods for Machine Learning

A categorical variable is an input variable whose values belong to a finite set of discrete categories.

Categorical data describes inputs whose values come from a finite set of discrete categories rather than a continuous numeric range. Examples include gender, race, state, ZIP code, employment type, and weather condition. Categories commonly appear as strings, tags, or formatted codes such as five-digit ZIP codes, so most machine-learning algorithms require them to be converted into numeric representations before training. section 8.0

First ask whether the categories have a meaningful order. Nominal features do not: red, blue, and green can be arranged in any sequence. Ordinal features do: T-shirt sizes naturally follow S < M < L < XL. This distinction matters because an encoding should preserve genuine structure without inventing relationships that the domain does not support. section 8.1.1

Income prediction from demographic data

An income model can combine categorical features such as education, marital status, race, gender, occupation, relationship status, employment type, and native country with continuous features such as age, education years, working hours, and capital gains. One workflow preprocesses the categories with category_encoders before training scikit-learn random forests, LightGBM, or XGBoost. Another uses CatBoost, which handles categorical features during training through ordered target statistics and ordered boosting. High-cardinality fields, such as ZIP code or native country, deserve particular attention because they contain many distinct categories. section 8.3 section 8.3.1

Figure 8.1 T-shirts in this example data set are described using two categorical features: color and size. Categorical features can be either (1) nominal, where there is no ordering between the various categories, or (2) ordinal, where there is an ordering between the categories. The third feature in this data set, cost, is a continuous, numeric variable.
CH08_F01_Kunapuli

Use the T-shirt example to compare nominal color with ordinal size alongside a continuous cost variable. section 8.1.1

How Ensemble Methods for Machine Learning covers it

How deep it goes
Defines nominal and ordinal categories, motivates encoding, and contrasts preprocessing with direct categorical boosting.
Examples
Uses T-shirt color and size, demographic income prediction, ZIP codes, and weather categories as concrete examples.
What it assumes
Assumes basic supervised-learning terminology and teaches the categorical-versus-continuous distinction from the feature level.
What you can do after
Apply it by distinguishing category types and selecting preprocessing or categorical-aware ensemble tooling.
How it connects
Connects categorical data to feature encoding, continuous features, ensemble methods, high-cardinality features, and CatBoost.

Also explained in

Compare how 16 books explain categorical data →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.