Module 2: Looking at data before modelling · Lesson 2.1 · about 15 min
Types of data: numbers, categories, text and time
Continuous and discrete numbers, nominal and ordinal categories, text, and dates and times. The type of a column decides what you can do with it. Sort real values into types in a quick game.
Module 2 · about 15 minutes · read first: 1.2. You’ll be able to name the main types of data, spot the traps, and say how each type is turned into numbers a model can use.
1. Why this matters
Not every number is really a number. You can average the temperatures of a week, but averaging the phone numbers of your friends gives nonsense. Sorting T-shirt sizes alphabetically puts L before M before S. Each type of column allows some operations and forbids others, like tools in a kitchen: a knife cuts, a whisk whisks, and swapping them makes a mess. Getting the type wrong is one of the quickest ways to build a model that learns rubbish.
2. The family tree of data types
| Type | What it is | Examples | You may | Turn into numbers by |
|---|---|---|---|---|
| Continuous number | Any value in a range | Temperature, price, weight | Average, subtract, scale | Use as is (then scale, Lesson 2.4) |
| Discrete number | Counts in whole steps | Children, visits, items in a basket | Average, subtract | Use as is |
| Nominal category | Names with no order | Blood group, city, colour | Count, find the most common | One-hot encoding (Lesson 1.2) |
| Ordinal category | Names with an order | Size S to XL, grades A to D, ratings 1 to 5 | Sort, find the median | Number them in order (S=1, M=2…) |
| Text | Free writing | Reviews, emails, notes | Count words, search | Word counts, TF-IDF or embeddings (Module 10) |
| Date, time, sequence | Points or values in order | Order time, daily rainfall | Order, take differences | Hour, weekday, month, time since, lagged values |
Numbers are also called quantitative or numerical data; categories are qualitative or categorical data.
- Continuous
- Can take any value in a range, like 21.37 °C. You can average and subtract.
- Discrete
- Comes in whole steps, like 3 children. Averages are fine (2.4 children per family is a useful summary).
- Nominal
- Names with no order, like city or blood group. Only "same or different" makes sense.
- Ordinal
- Names with an order, like S, M, L. You can sort, but the gaps may not be equal.
- Physical meaning
- A column's type is a promise about what its numbers mean. Weight in kg promises that 40 is twice 20. A postal code promises nothing of the kind: it is a name that happens to use digits. A model believes every number it is given, so you must keep only the promises that are true.
3. Test yourself
4. The traps
- Digits that are labels. Postal codes, phone numbers, product codes, customer IDs and year groups written as numbers are categories. A spreadsheet will happily average them, and a model will happily learn that customer 90,001 is “bigger” than customer 12. Store them as text.
- Ratings that look like numbers. A 1-to-5 score is ordinal. Averaging it is common and often useful, but remember the steps may not be equal.
- Categories with thousands of values. A “city” column with 4,000 cities makes 4,000 one-hot columns. Group rare ones as “other”, or use the city’s population or region instead.
- IDs that leak the answer. Row numbers or IDs assigned in time order can secretly encode when something happened. Drop IDs before training (Lesson 7.4).
- Times with time zones. “09:00” in Toronto and in Mumbai are different moments. Store times in one zone, then make local-hour features if they matter.
“If it’s made of digits, it’s a number.” Postal codes, phone numbers, product codes and customer IDs are labels written with digits. Customer 90,001 is not “bigger” than customer 12, and the average postal code of your customers is not a place. Store these columns as text so no tool is tempted to do arithmetic on them.
Maths and principle
Principle: the levels of measurement decide which arithmetic is meaningful.
| Level | Meaningful | Example |
|---|---|---|
| Nominal | equal or not equal | ? |
| Ordinal | also and | |
| Interval | also differences | 20 °C − 10 °C = 10 degrees warmer |
| Ratio | also ratios (there is a true zero) | 40 kg is twice 20 kg |
Temperature in °C is interval, not ratio: 20 °C is not “twice as hot” as 10 °C, because 0 °C is not “no heat”. In kelvin (293 K and 283 K) the ratio is only 1.04.
Cyclic features: hour 23 is next to hour 0, but as plain numbers they are 23 apart. Turn a cycle into two numbers on a circle,
so that 23:00 and 00:00 end up close together.
Try it: what are the (sin, cos) values for 06:00? (, : the point (1, 0).)
Watch one bike-share row become model-ready numbers:
5. Worked example
Made-up numbers. A bike-share company wants to predict rentals per hour. Its raw table has: station ID, time stamp, temperature (°C), weather (“clear”, “cloudy”, “rain”, “snow”), and a free-text “notes” column.
- Station ID (e.g. 7031): nominal. One-hot encode it if there are a few dozen stations, or replace it with station facts (near a university? near a station?).
- Time stamp: split into hour (as sine and cosine), weekday, month and a holiday flag. Rentals depend on all four.
- Temperature: continuous; scale it.
- Weather: looks nominal, but there is an order of “badness” for cycling (clear < cloudy < rain < snow), so it can be treated as ordinal: 0, 1, 2, 3.
- Notes: text; ignore it at first, or count a few key words such as “event” or “closed”.
6. Practice
- Is “number of rooms” continuous or discrete?
- A survey asks for income band: under 30k, 30-60k, 60-100k, over 100k. What type is it?
- Why is it a bad idea to one-hot encode a free-text review column?
Answers
- Discrete: rooms come in whole numbers.
- Ordinal: the bands have an order but unequal widths.
- Nearly every review is different, so you’d get one column per review, which teaches nothing. Text needs word counts or embeddings (Module 10).
Try it on your own data: the CSV profiler guesses each column’s type and shows its gaps and most common values.
New words: continuous, discrete, nominal, ordinal, interval and ratio scales, cyclic feature.
- Numbers can be continuous (any value) or discrete (whole steps); categories can be nominal (no order) or ordinal (ordered).
- Digits that name things (postal codes, IDs) are categories, not numbers.
- Nominal categories are one-hot encoded; ordinal ones can be numbered in order.
- Times are split into useful parts, and cycles such as the hour go on a circle with sine and cosine.
Check yourself
Sources
- Stevens, S. S. (1946), On the Theory of Scales of Measurement, Science 103(2684), 677-680 https://doi.org/10.1126/science.103.2684.677
- scikit-learn user guide: Preprocessing data (encoding categorical features) https://scikit-learn.org/stable/modules/preprocessing.html
- James, G., Witten, D., Hastie, T., Tibshirani, R. and Taylor, J. (2023), An Introduction to Statistical Learning with Applications in Python, Springer, Chapters 2 and 3 https://www.statlearning.com/
Your ticks stay in this browser. Save them as a file on the course home.
Updated 2026-11-22. Numbers in the examples are made up to show the idea unless a source is given. Simulations run in your browser; nothing you type is sent anywhere.