AI Glossary / Data science and analytics / Advanced

Categorical variable

Definition

A categorical variable records which category an observation belongs to, rather than a measured quantity. Categories may be nominal, with no inherent order, or ordinal, with a meaningful order but no guaranteed equal spacing. Examples include a document's format or its review stage. Numeric codes can represent categories without turning them into quantitative measurements.

What it means

The question is “which kind?” A field coded 1 for article, 2 for video and 3 for audio remains categorical. Adding those codes or averaging them does not produce a meaningful average content format.
Category design is part of measurement. For a single-valued field, categories should not overlap and should cover the intended possibilities. If one item can legitimately have several labels, a single category may be the wrong representation. For example, an article can address both governance and security, even if a publication workflow requires one primary editorial category for routing.

How it works

Define the observation unit, allowed categories and assignment rules. Decide whether order matters and how unknown, not-applicable or new values are handled. Store the labels or a documented coding scheme, then validate values as data enters the system.
Summarize categories with counts, proportions or cross-tabulations. Nominal labels do not imply numerical distance. Ordinal levels convey order, but the difference between beginner and intermediate need not equal the difference between intermediate and advanced.
For machine learning, choose an encoding suited to the model and the variable. An arbitrary integer code can introduce unintended ordering if the model interprets it numerically. One-hot encoding is one possible representation, but the treatment of rare and previously unseen categories also needs planning.

Three practical examples

  • A glossary records a primary topic for each entry. Editors use a shared category definition and allow separate secondary tags so that the primary field remains suitable for counting and assignment.
  • A support system records the contact channel as email, phone or chat. Managers compare counts and resolution rates by channel, retaining the denominator for each rate.
  • A learning platform records difficulty as introductory, intermediate or advanced. The order is meaningful, but the codes do not establish that advanced material is exactly three times as difficult as introductory material.

Think of it this way

A categorical variable resembles a set of labeled drawers. The labels tell you where an item belongs under the filing rule. Numbering the drawers makes them easier to reference, but drawer 3 is not automatically three times drawer 1. If an item belongs in several drawers, the filing scheme must explain whether it gets one primary location or several tags.

Worked example

Suppose ten fictional learning resources have one recorded format each: five articles, three videos and two audio recordings. The proportions are 5 / 10 = 50%, 3 / 10 = 30% and 2 / 10 = 20%. They sum to 100% because the categories are mutually exclusive and cover all ten resources.
Now code article as 1, video as 2 and audio as 3. The mean code is (5 × 1 + 3 × 2 + 2 × 3) / 10 = 1.7. That number has no useful interpretation as an average format. Renaming the codes would change it without changing any resource.
If resources instead receive multiple topic tags, the percentages with each tag may sum above 100%. That is not necessarily an error, but it describes a different arrangement from one mutually exclusive categorical field. State whether the denominator counts resources, tag assignments or something else.

Illustrative case study

In a fictional project, Pine Learning combines topic labels from three editorial teams. One uses “AI ethics,” another “Ethics,” and a third “Responsible AI.” Some labels are synonyms in the local scheme, while others have broader scope. Automatically merging every similar phrase would erase distinctions the editors still need.
The team creates a category dictionary, reviews proposed mappings and retains the original labels for traceability. It also separates the primary category used for workflow assignment from optional tags used for discovery. Entries with unresolved mappings remain visible rather than being forced into the largest category.
Pine can now produce a more interpretable topic summary and identify gaps in its classification rules. The scheme remains revisable as the publication grows. This fictional case illustrates category management.

Common misconceptions and mistakes

Categorical does not mean non-numeric storage. Postal codes and category identifiers can contain digits while functioning as labels. Conversely, a count of visits is quantitative even though it takes discrete values.
Ordered categories are not automatically equally spaced. Reporting the average of an ordinal coding requires additional justification about what that summary means. Missingness also needs explicit handling; an “Unknown” label may be useful operationally, but it should not be confused with a substantive category such as a genuine content type.
Changing labels or combining categories over time can affect comparisons. Preserve mappings and definitions so a trend is not mistaken for a real change when only the classification scheme changed.

Business use

Categorical variables support reporting, segmentation, routing and model development. Their usefulness depends on consistent, relevant definitions. Too many poorly maintained labels can fragment reporting; overly broad categories can conceal meaningful differences.
Assign responsibility for category changes and document how old values map to new ones. Report denominators and unknown counts where they matter. When using categories in predictions, check whether their collection is consistent across training and deployment and whether future records can introduce new values. A clean encoding cannot repair an unclear underlying classification.

People also ask

Is a binary variable categorical?

A two-category variable is a special case, even when represented with 0 and 1.

Are all categorical variables unordered?

No. The broad usage includes ordinal categories as well as nominal ones; some glossaries use the term more narrowly for nominal variables.

Can one record have several categories?

It can have multiple labels, but that requires a representation and counting rule that distinguishes it from a single-valued field.

Check your understanding

Why is the average format code of 1.7 uninformative?

Answer: The codes are arbitrary labels, not measured quantities.

Why can topic percentages exceed 100%?

Answer: Resources may receive multiple tags.

What does an ordinal scale establish?

Answer: A meaningful order, without automatically establishing equal distances between levels.

Related terms

  • Ordinal variable
  • Binary variable
  • Factor
  • One-hot encoding
  • Taxonomy
  • Nominal variable
  • category
  • label encoding
  • frequency table
  • data dictionary

Learn next

Design a category dictionary for a small resource collection. Check overlap, coverage, ordering and unknown values, then compare counts from a primary-category field with counts from multiple tags.

More in Data science and analytics

  • Bernoulli trial - A Bernoulli trial is a random experiment whose recorded outcome has two possibilities, conventionally called success and failure.
  • Boolean - Boolean refers to a logical value or expression with the two truth values true and false.
  • Box plot - A box plot summarizes the distribution of numerical data using a median, quartiles and whiskers.
  • Causal analysis - Causal analysis investigates whether and how changing one factor would change an outcome.
  • Cherry-Picking - Cherry-picking is the selective use or presentation of evidence that favors a desired conclusion while leaving out relevant evidence that would weaken...
  • Cluster Sampling - Cluster sampling is a probability-sampling approach that selects groups of population units, such as branches, schools, or geographic areas.

Sources

Australian Bureau of Statistics, Variables: broad distinction between categorical, nominal and ordinal variables. https://www.abs.gov.au/statistics/understanding-statistics/statistical-terms-and-concepts/variables Frank Harrell, Glossary of Statistical Terms: supplied source uses categorical variable in a narrower nominal sense. https://hbiostat.org/glossary/ This entry follows the broader ABS usage and makes that scope explicit. The resource counts and Pine Learning case are original illustrations.

Previous: Categorical Naive Bayes Next: Category utility

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer