makautnotes

0.3 Data Basics: Features, Variable Types, Data Splits & Pre-processing★

Asked1/4 recent papersup to 1M⏱ 5 min
PYQs2
  • A feature F1 can take the values A, B, C, D, E and F, and represents the grades of students from a college. Feature F1 is an example of a ______ variable. → Categorical (ordinal) 2022-23 1M recent
  • The ______ is the difference between a sample statistic used to estimate a population parameter and the actual but unknown value of the parameter. → Sampling error 2022-23 1M recent

Garbage In, Garbage Out


Instances, Features and Labels

A dataset is a table:

Age CGPA Attendance Placed? (label)
21 8.1 92% Yes
22 6.4 70% No

Variable Types PYQ 1M

  1. Categorical (qualitative): values are categories.
    • Nominal: no natural order. Examples: blood group, city, colour.
    • Ordinal: a natural order, but gaps aren't equal. Examples: grades A–F, ratings (poor, good, excellent), T-shirt size.
  2. Numerical (quantitative): values are numbers.
    • Discrete: countable whole values. Examples: number of children, number of clicks.
    • Continuous: any value in a range. Examples: height, temperature, salary.

Population, Sample and Sampling Error PYQ 1M


Training, Validation and Test Sets


Data Pre-processing

Techniques

  1. Data cleaning: remove duplicates, fix typos and wrong values.
  2. Handling missing values (data imputation): replacing missing values with estimated ones.
    • Mean or median (numbers), mode (categories).
    • Model-based: predict the missing value from other features (e.g. KNN imputation).
    • Or drop rows/columns with too many gaps.
  3. Outliers: detect extreme values (box plot, z-score) and remove, cap or keep them as appropriate.
  4. Encoding categorical data:
    • Label encoding: each category gets a number (low = 0, medium = 1, high = 2), suited to ordinal data.
    • One-hot encoding: one 0/1 column per category (Kolkata, Delhi, Mumbai), suited to nominal data.
  5. Discretisation: convert numbers into bins (age → child / adult / senior).
  6. Feature scaling: below.
  7. Dimensionality reduction and feature selection:
    • Dimensionality reduction: compress many features into fewer new ones, e.g. PCA (→ 2.4).
    • Feature selection: keep only the most useful original features (→ 2.5).

Feature Scaling

Feature scaling is bringing all numerical features to a similar range.

Why it is needed

Normalisation (min-max scaling): scales to [0, 1].

Standardisation (z-score): mean 0, standard deviation 1.

Worked example: why KNN needs scaling

⚡ Quick recall
  • Feature? → one input property (column) · instance = row · label = output
  • Grades A–F? → categorical (ordinal)
  • Variable types? → categorical (nominal, ordinal) · numerical (discrete, continuous)
  • Sampling error? → sample statistic − true population parameter
  • Splits? → train · validation · test (kept unseen)
  • Pre-processing? → cleaning · imputation · outliers · encoding (label, one-hot) · discretisation · scaling · dimensionality reduction / feature selection
  • Imputation? → filling missing values (mean, median, mode, model-based)
  • Scaling why? → distance and gradient methods · min-max to [0, 1] · z-score to mean 0, σ 1
Unit 0 · 0/4