liveBook · Manning

Categorical data

As explained in Deep Learning with PyTorch, Second Edition

A variable type whose values are treated as discrete labels rather than ordered magnitudes.

Categorical data contains values treated as discrete labels rather than ordered magnitudes. Unlike continuous values, differences between categories have no precise mathematical meaning; unlike ordinal values, categories do not imply a meaningful ranking. section 4.3.2

Common representations include:

  • One-hot encoding represents each class with a vector, such as [1, 0] for airplane and [0, 1] for bird. The same pattern extends to larger class sets such as CIFAR-10. section 7.2.3
  • Embeddings represent categories with learned numeric vectors, avoiding the cumbersome representation of large one-hot vectors. section 4.5.5

Classifying birds and airplanes

A classifier should treat airplane and bird as categories, not as numeric class magnitudes. It can output two probabilities corresponding to one-hot targets such as [1, 0] and [0, 1]. For binary classification, a single probability with sigmoid and binary cross-entropy is also possible. section 7.2.3

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Defines categorical values by contrast, then works through one-hot outputs and learned embedding alternatives.
Examples
Uses airplane-versus-bird labels, CIFAR-10 classes, text vocabularies, and recommender-system items.
What it assumes
Builds from numerical values and tensor representations while teaching the categorical-versus-continuous and ordinal distinction.
What you can do after
Apply it via one-hot encoding or embeddings when preparing categorical inputs and classifier targets.
How it connects
Connects categorical data with one-hot encoding, embeddings, classification, probability outputs, and binary cross-entropy.

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 Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.