Data organized into discrete, named groups without inherent numerical meaning.
Categorical data refers to variables that represent distinct groups or labels rather than continuous numerical quantities. In machine learning, these variables describe qualitative attributes — such as color, country, product type, or user preference — where the values denote membership in a category rather than a measurable amount. Categorical features are broadly divided into two subtypes: nominal, where categories carry no meaningful order (e.g., dog, cat, bird), and ordinal, where a meaningful ranking exists but the intervals between ranks are undefined (e.g., low, medium, high).
Because most machine learning algorithms operate on numerical inputs, categorical data must be transformed before model training. Common encoding strategies include one-hot encoding, which creates a binary column for each category; label encoding, which assigns an integer to each category; and target encoding, which replaces categories with statistics derived from the target variable. Each approach carries trade-offs: one-hot encoding avoids imposing false ordinal relationships but can dramatically expand feature dimensionality, while label encoding is compact but may mislead algorithms into inferring spurious numerical relationships between categories.
Handling categorical data well is critical to model performance. Poorly encoded categories can introduce bias, inflate dimensionality, or cause models to learn meaningless patterns. High-cardinality categorical features — those with hundreds or thousands of unique values, such as zip codes or product IDs — present particular challenges and often require specialized techniques like embedding layers, frequency-based filtering, or hashing tricks. Tree-based models such as gradient boosted trees can handle categorical splits more naturally, while neural networks often learn rich representations of categories through learned embeddings.
Categorical data is ubiquitous across real-world machine learning applications, appearing in tabular datasets for fraud detection, recommendation systems, natural language processing, and medical diagnosis. As datasets grow richer and more heterogeneous, robust preprocessing and representation of categorical variables has become a foundational skill in applied machine learning, directly influencing the accuracy and generalizability of trained models.