Đại học Kinh tế Quốc dân – National Economics UniversityMICRO4ASIA
🏆 Arena
Sign inSign up
MICRO4ASIAThe six micro-credentials

Courses are delivered on the Limio learning platform. Limio

← Fundamental of Machine Learning

You are viewing a public preview

Sign in to save your progress, do assignments, join discussions and get feedback.

Sign in
Module 1: Data Preparation and Model Foundations

1.5 Feature Types

Print / Save as PDF

1.5 Feature Types

After this unit you will: be able to correctly name the type of a feature — the first step in choosing the right way to handle it.

Key Points

  • Numerical: the feature is a number — discrete (separate values, such as integers) or continuous (any value on the number line).
  • Categorical: the feature is a category — nominal (no order, such as colors), ordinal (ordered, such as cup sizes S < M < L), boolean (only two values, true/false).

Study notes

By the end of this lesson you can:

  • Define a feature and split features into numerical and categorical.
  • Tell discrete numerical features from continuous ones.
  • Tell nominal, ordinal and boolean categorical features apart.
  • Classify every column of a small dataset and explain why the type matters for preprocessing.

Key idea: A feature is one column describing each example. Knowing whether it is numerical (discrete or continuous) or categorical (nominal, ordinal or boolean) is the first step in choosing how to prepare it, especially how to turn categories into numbers.

Two broad families of features

A feature is a column of data that describes something about each example. The lecture illustrates two families: numbers (0, 2, 4, 6, 8) and categories (icons of a shopping bag, a monitor, a shopping cart and a t-shirt).

  • Numerical features are measured quantities: square footage, age, income, temperature.
  • Categorical features are labels or groups rather than measured amounts: product category, city name, customer type.

The difference matters because algorithms and preprocessing steps treat numbers and categories very differently.

Numerical features: discrete and continuous

SubtypeValuesExamples from the lecture
DiscreteSeparate, countable values, usually whole numbers (shown on a number line from -5 to 5 in whole steps)Number of bedrooms, number of children, number of purchases
ContinuousAny value in a range, including decimals (conceptually from minus infinity to plus infinity)Height (172.85 cm), weight, temperature (28.6 degrees), price

You can have 2 or 3 bedrooms, but never 2.7 bedrooms, so bedrooms is discrete. A person can be 172.85 cm tall, so height is continuous. The distinction affects how you visualise a feature, how you preprocess it and sometimes which algorithm suits it best.

Categorical features: nominal, ordinal and boolean

SubtypeMeaningExamples
NominalCategories with no natural order or rankingCities such as Hanoi, Ho Chi Minh City, Hue; colours
OrdinalCategories with a natural order, but no exact numeric distanceSizes S, M, L
BooleanOnly two possible valuesYes or no, true or false (shown as toggle switches)

Hanoi does not come "before" Hue in any natural sense; they are just different labels, so city is nominal. Small is less than medium and medium is less than large, so size is ordinal, even though we never said how much bigger. Boolean features are the simplest case, with exactly two values.

Why the subtype matters

Later in this module you will convert categorical data into numbers that a model can use. Nominal and ordinal features are converted in different ways: ordinal features can keep their order as numbers, while nominal features must not be given a fake order. Getting the type right now prevents a modelling mistake later.

Be careful with the storage format. A column can contain digits and still be categorical. A province code such as 01 for Hanoi or 79 for Ho Chi Minh City is a label, not a quantity: adding or averaging codes means nothing.

Worked example

Classify the columns of a small housing table. pandas can tell you which columns are stored as numbers, but only you can decide what each column really means.

import pandas as pd

houses = pd.DataFrame({
    "square_feet":   [60.5, 45.0, 80.2],
    "num_bedrooms":  [3, 2, 4],
    "province_code": [1, 79, 48],
    "tier":          ["Mid-range", "Affordable", "Luxury"],
    "has_garden":    ["Yes", "No", "Yes"],
})

print(houses.select_dtypes("number").columns.tolist())

feature_types = {
    "square_feet":   "numerical, continuous",
    "num_bedrooms":  "numerical, discrete",
    "province_code": "categorical, nominal (digits are only labels)",
    "tier":          "categorical, ordinal (Affordable < Mid-range < Luxury)",
    "has_garden":    "categorical, boolean",
}
for col, kind in feature_types.items():
    print(f"{col:14} -> {kind}")

Expected output: the first line lists ['square_feet', 'num_bedrooms', 'province_code'] because those columns are stored as numbers. The loop then prints the real type of each column. Notice that province_code is stored as numbers but is actually a nominal category, so the storage type alone is not enough.

Common mistakes

  • Trusting the data type blindly. Codes stored as digits (province codes, postal codes, IDs) are usually nominal categories, not numbers.
  • Treating every category as ordinal. Colours and cities have no natural order; giving them ranked numbers invents a relationship.
  • Calling counts continuous. Number of bedrooms or purchases are whole-number counts, so they are discrete.
  • Forgetting boolean features. Yes/no columns are categorical too and still need converting to numbers.

Summary

  • A feature is a column describing each example.
  • Numerical features are discrete (separate values) or continuous (any value in a range).
  • Categorical features are nominal (no order), ordinal (ordered) or boolean (two values).
  • The subtype guides preprocessing; nominal and ordinal features are encoded differently.
  • Always check what a column means, not only how it is stored.

Flashcards · 1.5 Feature Types

9 words
WordMeaningExample
  • Feature

    A column of data that describes something about each example.

    square_feet in a housing table.

  • Numerical feature

    A feature whose values are measured quantities represented by numbers.

    Age, income, temperature.

  • Categorical feature

    A feature whose values are categories or labels rather than measured amounts.

    City name, product category.

  • Discrete feature

    A numerical feature that takes only separate values, usually whole numbers.

    Number of bedrooms: 1, 2, 3.

  • Continuous feature

    A numerical feature that can take any value within a range, including decimals.

    Height: 172.85 cm.

  • Nominal feature

    A categorical feature whose categories have no natural order.

    Hanoi, Ho Chi Minh City, Hue.

  • Ordinal feature

    A categorical feature whose categories have a natural order or ranking.

    Sizes S < M < L.

  • Boolean feature

    A categorical feature with only two possible values.

    has_garden: Yes or No.

  • df.select_dtypes()

    pandas method that selects columns by storage type; it cannot tell you a column's real meaning.

    df.select_dtypes("number").columns