Unit 3: Machine Learning

INT428 — Artificial Intelligence Essentials 7 min read

Machine learning (formalised from the 1950s, popularised by Arthur Samuel's 1959 definition of "the ability to learn without being explicitly programmed") is the study of algorithms that improve their performance on a task by extracting patterns from data rather than following hand-coded rules. Every method in this unit rests on the same statistical and algebraic machinery, so this section fixes the vocabulary the rest depends on.

  • Task, experience, performance: the Mitchell framing — a program learns from experience E with respect to task T and measure P if its performance at T, measured by P, improves with E.
  • Data as vectors: each example is a feature vector x = (x₁, …, xₙ) with a target y; a dataset is a matrix X of shape m × n (m examples, n features).
  • Model and parameters: a model is a function f(x; θ) whose parameters θ are fitted by minimising a loss over training data.
  • Generalisation: the goal is low error on unseen data, not memorisation; the gap between training and test error signals overfitting.
  • Inductive bias: every learner assumes some structure (linearity, smoothness, independence) — without it, learning from finite data is impossible.

II. Probability — Quantifying Uncertainty

Probability provides the language for reasoning about noisy data and uncertain predictions.

A. Core definitions

  • Sample space and event: Ω is the set of outcomes; an event A ⊆ Ω has probability P(A) ∈ [0,1].
  • Random variable: a function mapping outcomes to numbers; discrete variables use a probability mass function, continuous ones a density p(x) with ∫ p(x) dx = 1.
  • Conditional probability: P(A|B) = P(A ∩ B) / P(B), the probability of A given B occurred.
  • Independence: A and B are independent iff P(A ∩ B) = P(A)P(B).

B. Distributions used in ML

  • Bernoulli / Binomial: models binary outcomes; P(x=1) = p. Basis of logistic-regression targets.
  • Gaussian (Normal): p(x) = (1/√(2πσ²)) · exp(−(x−μ)²/2σ²); μ = mean, σ² = variance. Assumed noise model in linear regression.
  • Categorical / Multinomial: models one-of-K class labels; output of softmax classifiers.

C. Significance and limitation

  • Why it matters: loss functions like cross-entropy are negative log-likelihoods under these distributions.
  • Limitation: wrong distributional assumptions (e.g. forcing Gaussian on skewed data) bias estimates.

III. Statistics — Estimating from Samples

Statistics turns finite samples into estimates of the process that generated them.

A. Descriptive measures

  • Central tendency: mean μ = (1/m) Σ xᵢ, median, mode.
  • Spread: variance σ² = (1/m) Σ (xᵢ − μ)², standard deviation σ.
  • Covariance and correlation: cov(X,Y) = E[(X−μₓ)(Y−μᵧ)]; correlation normalises it to [−1, 1].

B. Inference

  • Estimator: a rule computing a parameter from data; Maximum Likelihood Estimation picks θ maximising P(data | θ).
  • Bias–variance of estimators: an estimator can be systematically off (bias) or unstable across samples (variance).
  • Hypothesis testing: a p-value measures how surprising the data is under a null hypothesis; e.g. p < 0.05 conventionally flags significance.

C. Bias–variance tradeoff

  • Decomposition: expected test error = bias² + variance + irreducible noise.
    • High bias: underfitting — model too simple (e.g. linear fit to a curve).
    • High variance: overfitting — model tracks noise (e.g. deep tree on small data).
  • Practical lever: regularisation trades a little bias for a large drop in variance.

IV. Linear Algebra (Applied Focus)

Linear algebra is the computational substrate: data, transformations and gradients are all matrix operations.

A. Objects and operations

  • Vectors and matrices: a feature vector lives in ℝⁿ; a weight matrix W maps inputs to outputs via Wx.
  • Dot product: xᵀw = Σ xᵢwᵢ computes a weighted sum — the core of a linear predictor.
  • Matrix multiplication: composes linear maps; a neural layer is a = σ(Wx + b).
  • Norms: ‖x‖₂ = √(Σ xᵢ²) measures magnitude; used in L2 regularisation.

B. Decompositions and their use

  • Eigenvectors / eigenvalues: Av = λv; directions unchanged by A except for scaling λ.
  • Principal Component Analysis: projects data onto top eigenvectors of the covariance matrix to reduce dimensions while keeping maximum variance.
  • Gradient as a vector: ∇f points uphill; gradient descent updates θ ← θ − η∇f(θ), where η is the learning rate.

V. Learning Paradigms — Concepts and Real-World Use

The three paradigms differ in what feedback the learner receives.

A. Supervised learning

  • Definition: learn f: x → y from labelled pairs (xᵢ, yᵢ).
  • Two subtypes:
    1. Regression: continuous y — e.g. predicting house prices; minimises mean squared error.
    2. Classification: discrete y — e.g. spam detection; minimises cross-entropy.
  • Real-world use: medical diagnosis from labelled scans, credit-risk scoring.

B. Unsupervised learning

  • Definition: find structure in unlabelled data {xᵢ}.
  • Clustering: k-means partitions data into k groups minimising within-cluster distance — e.g. customer segmentation.
  • Dimensionality reduction: PCA or autoencoders compress features — e.g. visualising gene-expression data.
  • Real-world use: anomaly detection in network traffic, topic discovery in documents.

C. Reinforcement learning

  • Definition: an agent learns a policy π(a|s) by acting in an environment and receiving rewards r, maximising expected cumulative reward.
  • Key elements: state s, action a, reward r, value function V(s); the Bellman equation relates a state's value to its successors.
  • Real-world use: game-playing (AlphaGo), robotic control, dynamic pricing and recommendation policies.

VI. Feature Engineering and Model Evaluation

Good features and honest evaluation decide whether a model works in practice.

A. Feature engineering

  • Purpose: transform raw data into inputs that expose the target signal.
  • Scaling: standardisation x' = (x − μ)/σ puts features on a common scale so gradient descent converges evenly.
  • Encoding: one-hot encoding turns a K-category variable into K binary columns.
  • Construction: deriving new features (e.g. ratios, date parts) or selecting informative ones to cut noise.

B. Cross-validation

  • Purpose: estimate generalisation without touching the test set.
  • k-fold procedure: split training data into k folds; train on k−1, validate on the held-out fold, rotate, and average the scores.
    • Effect: reduces variance of the estimate versus a single split; k = 5 or 10 is typical.

C. Precision and recall

  • Confusion matrix terms: TP, FP, FN, TN count correct and incorrect predictions per class.
  • The paired metrics:
    1. Precision: TP / (TP + FP) — of predicted positives, how many are right. Matters when false alarms are costly (e.g. spam filters).
    2. Recall: TP / (TP + FN) — of actual positives, how many are caught. Matters when misses are costly (e.g. disease screening).
  • F1 score: harmonic mean 2 · (precision · recall)/(precision + recall), balancing the two.

VII. Bayes Theorem, Bayesian Networks, and Probabilistic Reasoning

Bayesian methods update beliefs as evidence arrives, unifying prior knowledge with data.

A. Bayes theorem

  • Statement:
TEXT
P(H|E) = P(E|H) · P(H) / P(E)
  • Symbols: H = hypothesis, E = evidence, P(H) = prior, P(E|H) = likelihood, P(H|E) = posterior.
  • Worked example: a test is 99% sensitive and 95% specific for a disease with prevalence 1%. For a positive result:
    • P(D|+) = (0.99 · 0.01) / (0.99 · 0.01 + 0.05 · 0.99) ≈ 0.167 — only ~17%, because the base rate is low.
  • Naive Bayes classifier: assumes features are conditionally independent given the class, giving P(class | x) ∝ P(class) Πᵢ P(xᵢ | class); effective for text classification.

B. Bayesian networks

  • Definition: a directed acyclic graph where nodes are random variables and edges encode conditional dependence.
  • Factorisation: the joint distribution factors as P(x₁,…,xₙ) = Πᵢ P(xᵢ | parents(xᵢ)), drastically cutting the number of parameters.
  • Conditional probability tables: each node stores P(node | parents); e.g. a node "WetGrass" depends on "Rain" and "Sprinkler".

C. Probabilistic reasoning

  • Inference: compute a query variable's distribution given observed evidence, e.g. P(Rain | WetGrass = true).
  • Exact vs approximate:
    1. Exact: variable elimination sums out non-query variables; feasible on small networks.
    2. Approximate: sampling methods (e.g. Markov-chain Monte Carlo) estimate posteriors when exact inference is intractable.
  • Significance: supports decision-making under uncertainty — diagnosis, sensor fusion, and risk assessment — by propagating evidence through the dependency structure.