Module 0 — Foundations of Machine Learning

Source: Lec 2 — Introduction to Machine Learning.

Notation used throughout the course. A data point is ( features). There are training instances. A class label is . Test point: .


C1. What Is Machine Learning? (Samuel, Mitchell, the three paradigms)

Intuition

A normal program = rules written by a human. A learning program = rules extracted from examples. Think of a child learning to recognise dogs: nobody gives the child a definition; the child sees many dogs and “just gets it”. Machine learning is that, with performance you can measure.

Formal definitions

  • Samuel (1959): ML is the field of study that gives computers the ability to learn without being explicitly programmed.
  • Mitchell (1997): A program learns from experience with respect to a task and performance measure if its performance on , measured by , improves with experience .
  • Paradigms: Supervised (labelled data), Unsupervised (no labels), Reinforcement (reward signal; mentioned, not studied in the course).

Mathematical formulation

Let denote performance after seeing experience . Learning with respect to means: for experiences ,

Derivation / reasoning

Why must be measured on unseen data? If is measured on the training set, a lookup table achieves perfect with zero “understanding”. Mitchell’s definition is only meaningful when reflects performance on the task in general, i.e. on new instances. This is the seed of the whole generalisation / overfitting theme (C7, C13).

Key insights

  1. Always identify the triple before choosing an algorithm.
  2. determines the paradigm: labelled → supervised; unlabelled → unsupervised.
  3. “Improves with experience” is a testable, quantitative statement.

Worked examples

Example 1 — Very Easy

  • Problem: An email program learns to flag spam by watching which emails the user marks as spam. Identify , , .
  • Asked: The three components.
  • Concept: Mitchell’s definition.
  • Approach: Task = what the program does; experience = what it watches; performance = how success is scored.
  • Solution: = classify incoming emails as spam / not spam. = a database of emails with the user’s spam/not-spam labels. = fraction of new emails classified correctly.
  • Final answer: : spam classification; : labelled emails; : classification accuracy on new emails.
  • Key lesson: The three parts are three different objects; don’t merge them.

Example 2 — Easy

  • Problem: Label each as supervised, unsupervised or reinforcement: (a) predicting house prices from past sales with prices; (b) grouping customers by purchase behaviour with no labels; (c) a robot learning to walk by receiving when it moves forward and when it falls.
  • Asked: Paradigm for each.
  • Concept: Paradigms are defined by the type of feedback.
  • Approach: Ask “what feedback does the learner receive?”
  • Solution: (a) Each training house has its price (the target) → supervised (regression). (b) No target → unsupervised (clustering). (c) Feedback is a delayed scalar reward, not a correct answer → reinforcement.
  • Final answer: (a) supervised, (b) unsupervised, (c) reinforcement.
  • Key lesson: Supervision = a correct answer per example; reward is weaker.

Example 3 — Moderate

  • Problem: A program for recognising handwritten digits is evaluated on a fixed test set of 1000 images. After training on =500 images its test accuracy is 71 %; after =2000 images it is 88 %; after =8000 images it is 87.5 %. Does the program “learn” per Mitchell? Over which range?
  • Asked: Whether improves with .
  • Concept: Mitchell’s definition (improvement, not necessarily monotone forever).
  • Approach: Compare at successive experience levels.
  • Solution: , , . : improvement. : tiny decline, within the statistical noise of a 1000-image test set (one standard error is about , bigger than 0.005).
  • Final answer: Yes, it learns from 500→2000 images; from 2000→8000 the change is statistically indistinguishable from zero (performance has plateaued).
  • Key lesson: Learning curves saturate; compare differences with sampling noise.

Example 4 — Hard

  • Problem: Two programs are trained on the same 1000 labelled digit images. Program A stores every training image and its label and answers a test image with the label of an identical stored image if one exists, otherwise guesses “0”. Program B fits a smooth classifier. Results: A: training accuracy 100 %, test accuracy 10 %. B: training 94 %, test 92 %. Which has learned in Mitchell’s sense, and what should be?
  • Asked: Which program learned; what must measure.
  • Concept: must be measured on unseen instances of .
  • Approach: Evaluate the two programs under both choices of .
  • Solution: (i) If = training accuracy: A scores 100 %, B 94 % → A looks better — absurd, since A does not generalise. (ii) If = test accuracy: A = 10 % (equal to a random guess among 10 digits), B = 92 %. Now, does A’s test accuracy improve with experience? Only if a test image happens to equal a stored one; for new handwriting, no. B improves with experience.
  • Final answer: B has learned; the correct is accuracy on unseen instances.
  • Key lesson: Memorisation is not learning; generalisation is the point.

Example 5 — Very Hard

  • Problem: A learner is given experience sets of size and is evaluated by = accuracy on a fixed test set of 200 points. Three programs give for : Program X: . Program Y: . Program Z: . Z’s test set accidentally contains 20 points that also appear in the training sets once . (a) Which programs learn? (b) What is Z’s accuracy on the non-leaked 180 test points at , assuming Z gets all 20 leaked points right?
  • Asked: Learning judgement and corrected accuracy.
  • Concept: Mitchell’s definition + leakage invalidates .
  • Approach: (a) look at trend; (b) remove leaked points from numerator and denominator.
  • Solution: (a) X: strictly increasing → learns. Y: constant → does not improve → not learning (a fixed rule). Z: noisy; ignore leakage for now: , non-monotone. (b) Correct answers at : . Subtract the 20 leaked (all correct): correct among clean points . At no leakage: . So the clean accuracy goes : practically no improvement; Z’s apparent gain was leakage.
  • Final answer: X learns; Y and Z do not (Z’s clean accuracy vs ).
  • Key lesson: A test set contaminated by training data silently inflates — always check train/test disjointness.

Common mistakes

  • Treating training accuracy as performance.
  • Saying “learning requires labels” (unsupervised learning has none).

Exam traps

  • “Define ML” questions: give both Samuel and Mitchell; Mitchell is the formal one.
  • The definition says improves; a constant program does not learn.

Connections

Evaluation (C11–C13), overfitting (C7), supervised/unsupervised split (C2–C3).

Mastery checklist

  • State Samuel’s and Mitchell’s definitions.
  • Identify for any story.
  • Explain why must be on unseen data.

C2. Supervised Learning: Classification vs Regression

Intuition

Supervised learning = learning with an answer key. You get pairs and must predict for new . If the answer is a category (spam / not spam) it is classification; if it is a number (price) it is regression.

Formal definition

Given training data , , learn a function (the inferred function) so that estimates the target of a new .

  • Classification: (discrete).
  • Regression: (continuous).

Mathematical formulation

Empirical risk for loss : with for classification and for regression.

Derivation

Why not just minimise to zero? A lookup table does it. We want small true risk ; is only an estimate, so we evaluate on held-out data.

Key insights

  • Same input, different target type → different algorithm family.
  • Every classifier in this course (trees, Bayes, kNN, logistic, SVM, perceptron, NN) fits this template.

Worked examples

Example 1 — Very Easy

  • Problem: Classify as classification or regression: (a) predict a patient’s blood sugar level; (b) predict whether a tumour is malignant.
  • Asked: Task type.
  • Concept: Target type.
  • Approach: Discrete vs continuous target.
  • Solution: (a) blood sugar is a real number → regression. (b) malignant/benign is two categories → classification.
  • Final answer: (a) regression; (b) classification.
  • Key lesson: Look at , not .

Example 2 — Easy

  • Problem: The data table below has features (age, income) and target “buys” ∈ {yes,no}: no, yes, yes. State , , , .
  • Asked: Notation.
  • Concept: Training-set notation.
  • Approach: Count rows and columns.
  • Solution: Rows = 3 → . Feature columns = 2 → . , .
  • Final answer: .
  • Key lesson: counts features, not including the target.

Example 3 — Moderate

  • Problem: Data : . Hypothesis . Compute the empirical squared loss and the number of points a rounding classifier ” rounded equals ” gets right.
  • Asked: .
  • Concept: Empirical risk.
  • Approach: Compute predictions and residuals.
  • Solution: . Residuals : . Squared: . . Rounding matches: first three equal, fourth → 3 correct of 4.
  • Final answer: ; 3/4 correct.
  • Key lesson: The same predictions can be scored by different losses.

Example 4 — Hard

  • Problem: House prices (in lakhs): sizes ; prices . A manager wants “cheap” () vs “expensive”. Option 1: regress price, then threshold at 40. Option 2: train a classifier directly. The regressor is . Compute the threshold classifier’s accuracy and decide which size is the decision boundary.
  • Asked: Accuracy and boundary.
  • Concept: A regressor induces a classifier.
  • Approach: Predict, threshold, compare with true labels.
  • Solution: Predictions: ; ; ; ; . True labels (price → cheap): C, C, E, E, E. Predicted labels with rule “predicted is cheap”: C, C, E (not ), E, E → all five match → accuracy . Boundary: (ties at 70 go to expensive).
  • Final answer: Accuracy 100 %, boundary .
  • Key lesson: A regression model contains classification information, but the tie-breaking at the boundary must be fixed.

Example 5 — Very Hard

  • Problem: A “lookup” learner stores training pairs; for a test already stored it returns the stored , otherwise it returns the majority training label. Training set: . Test set: . Compute training 0-1 risk, test 0-1 risk, and compare to the constant predictor “A”.
  • Asked: Three error rates.
  • Concept: Generalisation gap.
  • Approach: Majority label first, then evaluate each point.
  • Solution: Majority label = A (3 vs 1). Training: every stored point is returned exactly → 0 errors → risk 0. Test: stored → A, correct. : unseen → A, true B → error. : A, true B → error. : A, true A → correct. Test risk . Constant “A” predictor: test predictions all A: correct on and → 2 correct, risk 0.5. Training risk of constant A: 1 error of 4 → 0.25.
  • Final answer: Lookup: train 0, test 0.5. Constant A: train 0.25, test 0.5. The lookup learner shows a gap of 0.5 and no test advantage.
  • Key lesson: Zero training error can coexist with no generalisation; the gap is what matters.

Common mistakes

  • Using the wrong loss (squared error on categorical labels).
  • Counting the target as a feature.

Exam traps

  • Binary labels coded vs change formulas (logistic uses ; SVM and perceptron use ).
  • “Logistic regression” is a classifier.

Connections

Every later module. Regression → C26; classification → C4–C25, C27–C34, C49+.

Mastery checklist

  • Define classification and regression.
  • Write the empirical risk for 0-1 and squared loss.
  • Explain train vs test risk.

C3. Unsupervised Learning & Feature Engineering

Intuition

No answer key. Two things you can still do: group similar items (clustering) or describe how the data is spread (density estimation). Separately, you can clean up the features: keep the useful ones (selection) or build new better ones (extraction).

Formal definitions

  • Clustering: partition data into groups; high similarity within, low across.
  • Density estimation: estimate the distribution .
  • Feature selection (supervised): score each feature using class labels (e.g. statistic, information gain), keep top-scoring ones.
  • Feature extraction (unsupervised): build new features from old ones without labels (e.g. PCA, entropy-based methods).

Mathematical formulation

for a feature-vs-class contingency table with observed and expected : Information gain of a feature is defined in C4.

Derivation

Expected counts are what we would see if feature and class were independent: . Large deviation from independence → feature carries information about class → high score.

Key insights

  • Selection keeps original features (interpretable); extraction creates new ones.
  • Supervised ⇒ selection (uses labels); unsupervised ⇒ extraction (does not).
  • Variance is not relevance (see Example 5).

Worked examples

Example 1 — Very Easy

  • Problem: Is PCA feature selection or feature extraction? Is it supervised?
  • Asked: Category.
  • Concept: Taxonomy.
  • Approach: PCA builds new axes and ignores labels.
  • Solution: New features → extraction; no labels → unsupervised.
  • Final answer: Unsupervised feature extraction.
  • Key lesson: Selection = keep; extraction = build.

Example 2 — Easy

  • Problem: Information-gain scores: outlook 0.247, temperature 0.029, humidity 0.152, wind 0.048. Select the top 2 features.
  • Asked: Top-2.
  • Concept: Score-based selection.
  • Approach: Sort descending.
  • Solution: . Top two: outlook, humidity.
  • Final answer: {outlook, humidity}.
  • Key lesson: Selection is just ranking by a score.

Example 3 — Moderate

  • Problem: Word “free” present/absent vs spam/ham: present&spam=30, present&ham=10, absent&spam=20, absent&ham=40. Compute .
  • Asked: .
  • Concept: feature score.
  • Approach: Row/column totals → expected counts → sum.
  • Solution: Row totals: present , absent . Column totals: spam , ham ; . , , , . Deviations: . .
  • Final answer: (strongly dependent on class; high score).
  • Key lesson: Expected counts come from independence.

Example 4 — Hard

  • Problem: Features and are exact duplicates and both perfectly predict the class; is pure noise. A selector picks the top-2 by information gain. A PCA extractor keeps 1 component. Compare what each keeps. Four points: = class 0; class 0; class 1; class 1.
  • Asked: Which representation is better and why.
  • Concept: Redundancy.
  • Approach: Compute IG per feature; compute covariance.
  • Solution: Class entropy bit. Split on : both class 0 (entropy 0); both class 1 (entropy 0). IG; same for . For : one class 0, one class 1 (entropy 1); same for ; IG. Selector keeps — redundant, same information twice. PCA: centred data with variance each and covariance ; has variance and zero covariance with the others. The largest variance direction is (variance 25) — pure noise! PCA with one component keeps noise and discards the class information.
  • Final answer: Selection keeps two redundant but relevant features; one-component PCA keeps only the noise axis. Here selection wins.
  • Key lesson: Unsupervised extraction maximises variance, not relevance.

Example 5 — Very Hard

  • Problem: Points (class): −, −, +, +. (a) Compute PCA’s first direction and the 1-D projected class separation. (b) Compute the information gain of splitting on sign of and on sign of . (c) Which is better and what is the lesson?
  • Asked: PCA direction, IGs, conclusion.
  • Concept: Variance ≠ discriminability.
  • Approach: Covariance matrix, eigen, project.
  • Solution: (a) Means: . ; ; . , eigenvalues ; first PC . Projection onto it gives coordinates for classes : both classes occupy both values → total overlap. (b) Splitting on : groups and , each entropy 1 → IG. Splitting on : groups all − and all + → entropy 0 → IG. (c) PCA direction has IG 0; the low-variance axis has IG 1.
  • Final answer: PCA’s direction is (no class information); separates perfectly.
  • Key lesson: Use supervised selection (or supervised projection such as Fisher’s discriminant, C48) when classification is the goal.

Common mistakes

  • Believing the highest-variance feature is the most useful.
  • Mixing up “selection” and “extraction”.

Exam traps

  • and IG both need labels → supervised.
  • Feature extraction may be applied before a supervised learner but is itself unsupervised.

Connections

IG (C4), PCA (C43–C48), clustering (C35–C42).

Mastery checklist

  • Distinguish selection vs extraction and supervised vs unsupervised.
  • Compute from a table.
  • Explain why PCA can discard class-relevant directions.