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.
Use the T-shirt example to compare nominal color with ordinal size alongside a continuous cost variable. section 8.1.1















