2.1.1 · D2Data Preprocessing & Feature Engineering

Visual walkthrough — Types of data (numerical, categorical, ordinal, text)

1,889 words9 min readBack to topic

This page rebuilds the parent idea — Types of dataentirely in pictures. We start with nothing but a table someone typed, and we watch, step by step, how a machine has to see each column before any algorithm can touch it.


Step 1 — Start with the raw table (what we are given)

WHAT. A dataset is a grid: each row is one thing we measured (a house, a person, a transaction), each column is one attribute of that thing. Before we do anything, every cell is just text a human typed.

WHY. We must look at each column on its own and ask one question: "If I do arithmetic on these cells, does the arithmetic mean anything?" That single question splits every column into one of four families.

PICTURE. Below, four columns of one table are colour-flagged by the family they belong to. Notice we have not touched any number yet — we are only sorting the columns.

Figure — Types of data (numerical, categorical, ordinal, text)

Step 2 — Numerical: it is already a number line

WHAT. For a numerical column (house prices in lakhs), the values live on a number line — a straight ruler where distance means something. "" really is further from "" than "" is.

WHY. Because distance is real here, arithmetic is legal: we may compute a centre and a spread. So the only problem is that different numerical columns use different rulers (price in lakhs vs age in years). We fix that by re-drawing every ruler to the same scale — that is what standardization does.

PICTURE. The top ruler is the raw prices. Below it, the same points after we (1) slide the centre to and (2) squeeze the spread to .

Figure — Types of data (numerical, categorical, ordinal, text)

Worked numbers (matching the parent). With and :


Step 3 — Categorical: labels with NO number line

WHAT. A categorical column like payment method {UPI, Credit Card, Cash} has no ruler. There is no "middle" payment method, no "UPI plus Cash". The labels are just names.

WHY. If we naively number them , we have secretly drawn a ruler that isn't there — the machine now believes is "twice" and sits "between" the other two. That is a lie we must not tell a distance-based model.

PICTURE. Left: the fake straight-line ordering that label encoding invents. Right: the honest picture — each category is its own axis, all mutually perpendicular, so no category is "between" any other.

Figure — Types of data (numerical, categorical, ordinal, text)

Step 4 — Ordinal: a number line with UNEVEN spacing

WHAT. Education High School < Bachelor's < Master's < PhD does have an order — PhD really is "higher" than Master's — but the gaps between levels are not equal. The jump from High School to Bachelor's is not the same "size" as Master's to PhD.

WHY. We want to keep the order, so we map to increasing integers . This is honest about sequence but it quietly claims the gaps are all equal to . That claim is fine for a tree (which only asks "is level ?") and risky for a distance model (which believes every step is one unit).

PICTURE. Top: the true spacing (unequal amber gaps). Bottom: the integer encoding which forces the gaps to look equal — an approximation we accept knowingly.

Figure — Types of data (numerical, categorical, ordinal, text)

Step 5 — Text: a whole paragraph must become a vector

WHAT. A text column ("great fast service", "slow rude staff") is not one value at all — it is a bag of words. To do arithmetic we must turn each document into a fixed-length row of numbers.

WHY. The machine has no ruler and no order here; it has a vocabulary. The natural numeric summary is: for each word in the vocabulary, how important is that word in this document? Counting alone over-rewards common words like "the", so we down-weight words that appear everywhere — the idea behind TF-IDF and Text Vectorization.

PICTURE. One short document becomes a row whose columns are vocabulary words; each cell holds a weight (bright = important, dim = common-and-ignored).

Figure — Types of data (numerical, categorical, ordinal, text)

The one-picture summary

Everything above is one decision tree over columns, and one translation per leaf. Numbers stay on a ruler; categories fan out into perpendicular axes; ordinals keep their order as integers; text collapses into weighted word-vectors.

Figure — Types of data (numerical, categorical, ordinal, text)

yes

no

no, just labels

yes, uneven gaps

no

yes

A column of raw cells

Can I average them meaningfully?

Numerical -- standardize on a ruler

Is there an order?

Are they words in sentences?

Ordinal -- integers 0 1 2 keep order

Categorical -- one-hot perpendicular axes

Text -- TF-IDF weighted word vectors

Recall Feynman retelling — say it like a story

A computer can only do arithmetic, but a spreadsheet is full of words. So for every column I ask one question: does adding these make sense? If yes, it's a number on a ruler — I just re-mark every ruler to the same scale so no single column shouts louder than the rest. If it's a plain label like a colour, there's no ruler at all, so I give each label its own perpendicular axis (one-hot); that way no colour is secretly "between" two others and every pair sits the same apart. If the labels have an order but wobbly gaps, like shirt sizes, I number them so the sequence survives — I just remember the gaps aren't truly equal. And if the cell is a whole sentence, I count its words and down-weight the boring ones that appear everywhere, turning the paragraph into a row of importance numbers. Four columns, four honest translations — the whole job of knowing your data types.

Recall Quick self-test

Why does label-encoding a colour hurt a linear model but not a tree? ::: A linear model measures distance, so invents fake "betweenness" and ratios; a tree only asks "is it equal to X?" and never uses the numeric gaps. What single number check must you run before standardizing a column? ::: Check — a constant column would force division by zero and carries no information, so drop it. Why do all distinct one-hot vectors sit the same distance apart? ::: Each differs in exactly two slots (a turns into and vice versa), giving every time, so no category is closer to another.

Related deep dives: Feature Scaling Impact on Gradient Descent, Feature Engineering from Datetime.