Attribute and data types
Clear definitions and rules for attribute and data types (nominal, ordinal, interval, ratio; categorical vs numerical; discrete vs continuous), what operations and statistics are valid on each, encoding methods, examples and exam guidance.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two or three sentences: In data mining and data warehousing, an engineer must choose correct statistical methods, preprocessing and storage formats based on the kinds of attributes in data. Wrong assumptions about an attribute's type lead to invalid summaries, bad features for mining algorithms, and errors in ETL and OLAP tasks.
Key ideas
Start from first principles and define terms before use.
- Attribute — a measurable property or characteristic of an object (also called a feature or variable). Example: Student.age, Product.color.
- Data type — the formal category that describes what values an attribute can take and what operations make sense on those values.
Measurement scales (Stevens' levels). State them exactly and their assumptions:
Nominal — A scale where values are names or labels only. Definition: categories are mutually exclusive and collectively exhaustive. Assumption: only equality testing (are two values the same?) is valid. Example operations: equality, counting. Diagram to draw: several non-ordered boxes each labelled with a category (e.g., Red, Green, Blue).
Ordinal — A scale giving a ranked order to values. Definition: categories have a meaningful order but distances between adjacent ranks are not necessarily equal. Assumption: comparison (<, >) and median are valid; arithmetic mean is not guaranteed valid. Diagram to draw: a vertical list of ranks (e.g., Low, Medium, High) with arrows showing order.
Interval — A numeric scale where differences are meaningful and equal intervals exist, but there is no true zero point. Definition: for any two values x and y the difference (x−y) is meaningful; ratios are not. Assumption: addition/subtraction and mean are valid; multiplication/division are not (ratio meaningless). Example: temperature in Celsius. Diagram: a number line labelled with equal spacing and an indicated arbitrary zero.
Ratio — A numeric scale with equal intervals and a true zero. Definition: differences and ratios are meaningful. Assumption: all arithmetic operations (including geometric mean, ratios) make sense. Example: weight, height, time durations. Diagram: number line with zero at origin and positive direction.
Formal distinction: nominal < ordinal < interval < ratio in the sense of increasing information. Permissible transformations: nominal — any one-to-one relabeling; ordinal — any strictly monotonic increasing transform; interval — affine transform ax + b with a > 0; ratio — scaling ax with a > 0.
Other definitions used commonly in data engineering:
- Categorical — synonym for non-numeric attributes; categories are discrete labels. Categorical attributes can be nominal or ordinal.
- Numerical — attributes with numeric values. Numerical attributes can be discrete or continuous.
- Discrete — values take countable set (often integers). Example: number of defects. Assumption: gaps between values may be large; some statistical formulas still apply but interpret carefully.
- Continuous — values take any real number in an interval. Example: height in metres.
- Binary — attribute with exactly two categories (e.g., True/False). Binary may be nominal or can be treated numeric (0/1) under assumptions.
- Multi-valued — attribute that can take multiple values for one record (e.g., product.tags). In warehousing this may be stored as a separate relation (one-to-many) or as set/list encoded for mining.
- Missing value — a placeholder for an unknown or inapplicable attribute value. Missingness mechanisms (MCAR, MAR, MNAR) are defined in other topics (Data cleaning and integration) but you should treat missing values explicitly in preprocessing.
Encoding for mining and storage (definitions):
- One-hot encoding — convert a nominal attribute with k categories into k binary attributes each indicating presence (1) or absence (0) of a category. Use when no order is implied and for many machine-learning algorithms.
- Label encoding — map each category to a numeric label (0,1,2,...). Use carefully: label values imply order to algorithms that use numerical comparisons.
Which statistics/operations are valid depends on scale (exact rules students must remember): Also note common distance/similarity choices by scale: nominal/binary — Hamming or Jaccard; ordinal — rank-based measures (Spearman/Kendall); interval/ratio — Euclidean or Manhattan.
- Nominal: only mode, frequency counts, chi-square tests.
- Ordinal: median, percentiles, non-parametric tests (e.g., Mann–Whitney), but not means for strict correctness.
- Interval: mean, variance, addition/subtraction, correlation; but ratios not meaningful.
- Ratio: all arithmetic statistics including geometric means, coefficients of variation.
Draw and label a diagram comparing scales: four horizontal number lines or ordered lists showing increasing structure from nominal to ratio.
Assumptions behind using mean/variance: the attribute must be numeric and measured on an interval or ratio scale; for sample estimates assume independent observations and that variance exists. Normality is not required to compute mean/variance; it is only needed for specific inference procedures.
Practical notes for data warehousing: store attributes with clear metadata indicating measurement scale and allowed operations — this appears in ETL and metadata repository topics.
Formulas
Each formula on its own line and then explanation.
x̄ = (1/n) · Σ_{i=1..n} x_i
- x̄ is the sample mean of numerical attribute, unit = same as x_i. Applies for interval and ratio scales.
s^2 = (1/(n-1)) · Σ_{i=1..n} (x_i − x̄)^2
- s^2 is the sample variance, unit = (unit of x)^2. Applies when data are numeric and interval/ratio; denominator n−1 for unbiased estimator under i.i.d. assumption.
median (sorted data): if n is odd, x_((n+1)/2); if n is even and numeric (interval/ratio), (x_(n/2) + x_(n/2+1))/2; for ordinal with even n, report the lower or upper median (no averaging).
- Median is the middle value; unit = same as x. Valid for ordinal, interval, ratio.
mode = argmax_v frequency(v)
- Mode is the value (or values) with highest frequency. Valid for nominal and above.
(Encoding syntax reminders — not formal formulas)
One-hot encoding for category c_j in {c_1..c_k}: create k binary features b_1..b_k where b_j = 1 if category==c_j else 0. For linear models with an intercept, drop one dummy (k−1 columns) or use regularization to avoid the dummy-variable trap (perfect multicollinearity).
Label encoding: map category c_j -> integer j (or any one-to-one mapping).
Worked examples
Example 1 — Attribute typing and allowed operations (university-exam style) Data: For each student record: {ID, Gender, Year (1–4), GPA (0–10), BirthYear, Hometown}
- Identify type for each attribute and justify briefly.
- ID: Nominal (unique identifier). Only equality and counting make sense.
- Gender: Nominal (binary category). Use frequency counts and chi-square tests.
- Year: Ordinal (1 < 2 < 3 < 4). Order exists but difference between 1 and 2 may not be equal to between 3 and 4 in meaning (treat as ordinal unless domain justifies interval arithmetic).
- GPA: Typically interval (constructed from grades; differences are meaningful but ratios are not). 0 does not establish a true zero of achievement and "twice the GPA" is not meaningful; treat as interval: mean/variance OK, but ratios/CV/geometric mean are not.
- BirthYear: Interval (differences meaningful but year 0 is arbitrary); durations (currentYear − BirthYear) produce ratio measurements (age).
- Hometown: Nominal (name of city).
A full-mark answer states each type, operation examples (e.g., compute mean GPA), and whether one-hot or label encoding is preferred for each categorical field.
Example 2 — Numeric computation on a ratio attribute (age in years) Data: ages (years): 20, 22, 25, 23 Steps:
- n = 4
- Mean: x̄ = (20+22+25+23)/4 = 90/4 = 22.5 years
- Deviations: −2.5, −0.5, 2.5, 0.5 years
- Squared deviations: 6.25, 0.25, 6.25, 0.25
- Sample variance s^2 = (1/(4−1))·(6.25+0.25+6.25+0.25) = (1/3)·13 = 4.333... (years^2)
- Sample standard deviation s = sqrt(4.333...) = 2.0817 years Final answers: mean = 22.5 years, s^2 = 4.333 years^2, s = 2.08 years.
Example 3 — One-hot encoding trace (small nominal attribute) Colors: [Red, Blue, Red, Green] Unique categories = {Red, Blue, Green} → create b_Red, b_Blue, b_Green Transform:
- Red -> [1,0,0]
- Blue -> [0,1,0]
- Red -> [1,0,0]
- Green -> [0,0,1] Show resulting matrix rows. Note: increases dimensionality to k columns.
Common mistakes
- Forgetting that ratios are meaningless for interval data (e.g., saying "twice as hot" for Celsius).
- Storing multi-valued attributes in a single delimited string in a warehouse instead of a normalized relation — leads to hard joins and incorrect aggregations.
- Ignoring missing-value mechanism and imputing incorrectly without noting scale (e.g., imputing mean on nominal attributes without mapping).
For your exam
Kinds of questions you will see and what full-marks answers include:
- Definitions and short notes: give exact definitions (name the scale, state allowed operations, example). If asked for differences, compare nominal vs ordinal vs interval vs ratio in a table or clear sentences.
- Derivations: show how sample variance formula is obtained from sum of squared deviations; state assumptions (i.i.d., finite variance) and show algebraic steps if required.
- Numericals: compute mean/median/mode/variance for small lists, carry units through, show steps and final bolded answer.
- Programs/encoding: write short pseudocode or show one-hot encoding example; explain why used and when not to use label encoding.
- Diagrams: draw four parallel lines or lists representing nominal->ordinal->interval->ratio and label operations valid on each.
A full-marks answer always states the measurement scale, justifies allowed operations, shows steps (for numericals), and comments on practical implications (e.g., encoding choice for algorithms).
Quick check
- Which scale allows meaningful ratios: nominal, ordinal, interval, or ratio?
- Is it safe to compute the mean of Likert-scale responses (Strongly disagree..Strongly agree) without justification? (Yes/No)
- Convert categories {A,B,C} into one-hot and show the vector for B.
Answers: 1) Ratio. 2) No. 3) {A,B,C} one-hot for B = [0,1,0].
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?