Unit 3: Machine Learning
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
Ewith respect to taskTand measurePif its performance atT, measured byP, improves withE. - Data as vectors: each example is a feature vector
x = (x₁, …, xₙ)with a targety; a dataset is a matrixXof shapem × 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 eventA ⊆ Ωhas probabilityP(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 ofAgivenBoccurred. - Independence:
AandBare independent iffP(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
θmaximisingP(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.05conventionally 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 matrixWmaps inputs to outputs viaWx. - 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 byAexcept 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:
∇fpoints 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 → yfrom labelled pairs(xᵢ, yᵢ). - Two subtypes:
- Regression: continuous
y— e.g. predicting house prices; minimises mean squared error. - Classification: discrete
y— e.g. spam detection; minimises cross-entropy.
- Regression: continuous
- 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
kgroups 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 rewardsr, maximising expected cumulative reward. - Key elements: state
s, actiona, rewardr, value functionV(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
kfolds; train onk−1, validate on the held-out fold, rotate, and average the scores.- Effect: reduces variance of the estimate versus a single split;
k = 5or10is typical.
- Effect: reduces variance of the estimate versus a single split;
C. Precision and recall
- Confusion matrix terms: TP, FP, FN, TN count correct and incorrect predictions per class.
- The paired metrics:
- Precision:
TP / (TP + FP)— of predicted positives, how many are right. Matters when false alarms are costly (e.g. spam filters). - Recall:
TP / (TP + FN)— of actual positives, how many are caught. Matters when misses are costly (e.g. disease screening).
- Precision:
- 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:
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:
- Exact: variable elimination sums out non-query variables; feasible on small networks.
- 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.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →