The Statistical Learning Framework and Empirical Risk Minimization
In questa pagina 5
Setting (see Introduction to Machine Learning - Learning, Data and TasksMachine learning builds a hypothesis g that approximates an unknown target function f using only a set of historical examples (input, output). The course lecture frames learning as adaptive behaviour, shows through the credit-approval example the components of learning (input x, output y, target f, data, hypothesis g, hypothesis set, learning algorithm) and warns that a model is only as unbiased as its data. Tasks named in the course are classification and regression, supervised and non-supervised problems.Introduction to Machine Learning - Learning, Data and Tasks →): an unknown target function , samples with , a hypothesis set and a learning algorithm that returns with . This note shows how "approximately" is measured, following the lecturer's handwritten pages.
1. Comparing hypotheses with a pointwise error
The first drawing has four sample points , , and compares hypotheses. Take the simplest hypothesis, a constant:
For each sample the vertical distance between the point and the hypothesis is (the arrows in the sketch). Adding the four signed differences,
is not a good measure: a point above the line and a point below it cancel. The notes show the two standard ways to make every term non-negative:
and choose the square, circling
A second hypothesis (a sloped line, in the same drawing) is compared with the constant through the same quantity: the smaller the total, the better the hypothesis on these samples.
Derived here (not on the handwritten page). is a function of the single number ; setting gives , the mean of the four outputs. So among all constants the one with least squared error is the average of the outputs.
2. In-sample error
A later handwritten page generalises the sketch. For one input, the error function (pointwise error) is , comparing the target value with the hypothesis value. Averaging it over the data points gives the in-sample error, also called empirical error:
"How do we define ?" The notes answer with the sum of squared errors (SSE):
This is the quantity that ADALINE and Gradient DescentADALINE is a perceptron whose activation function is the identity: during training the unit outputs w^T x and the in-sample error E_in = (1/N) sum (y_i - w^T x_i)^2 is minimised by gradient descent, w_new = w_old - eta * grad E_in, with partial derivatives dE_in/dw_j = (2/N) sum (y_i - w^T x_i)(-x_i^j) and matrix form grad E_in proportional to -X^T (Y - X w). The prediction is still the sign of w^T x. Learning rate eta sets the step size and a stopping rule ends the iteration.ADALINE and Gradient Descent → minimises by gradient descent and that Linear RegressionIn linear regression the hypothesis is h(x) = w^T x and the in-sample error is E_in(w) = (1/N) sum (w^T x_i - y_i)^2 = (1/N) times the squared norm of (Xw - Y), with X the N-row data matrix. Setting the gradient (2/N) X^T (Xw - Y) to zero gives the normal equations X^T X w = X^T Y and the closed-form solution w = (X^T X)^{-1} X^T Y, where (X^T X)^{-1} X^T is the pseudo-inverse of X; only a small square matrix (number of features) has to be inverted. Polynomial regression is the same formula on a data matrix with columns 1, x, x^2, ...Linear Regression → minimises in closed form. For classification the notebooks mention the zero-one loss (an input counts 1 if it is misclassified, 0 if not): the perceptron code counts the misclassified points of each epoch (see Python Notebooks - Perceptron and ADALINE from ScratchCode of the course notebooks that implement the Perceptron Learning Algorithm first with Python lists, then with plots of the successive lines, then with NumPy arrays (data matrix X with a column of ones, update w + eta * y * x on mistakes, epoch counter), and finally ADALINE: batch gradient descent with delta_w = eta * 2 * X^T (y - X w) / N and the stochastic version that shuffles the data and updates after every example. Differences between the versions (condition for a mistake, learning rate, stopping rule) are pointed out.Python Notebooks - Perceptron and ADALINE from Scratch →), and the logistic-regression notebook assigns an object to class 1 "(remember the zero-one loss function)" when the output exceeds 0.5.
3. Empirical risk minimisation, as it appears in the notes
The term "empirical risk minimisation" appears in the course source only as a chapter pointer (textbook chapter 2). What the handwritten notes and notebooks do is exactly this recipe:
- fix a hypothesis set (constants, lines through , ...);
- define an error and the in-sample error it induces;
- let the algorithm pick, inside the set, the hypothesis with the smallest (a closed formula for regression, an iterative rule for ADALINE, an update rule that drives the number of errors to zero for the perceptron).
4. In-sample is not enough: the input distribution
Two pages draw the point that the error on the samples is only a proxy for the error on the inputs the model will really see.
Where the samples are. The first sketch shows the target (a parabola) and the probability density of the inputs (a bell curve). The sampled inputs (crosses on the axis) crowd where is large, between two vertical red lines; outside these lines (red hatching) there are few or no samples. A hypothesis fitted to the samples (the black segment in the middle) follows there, while on the two sides, where nothing was observed, the sketch hatches the gap between the black dashed continuation and . A second sketch (in the perceptron lecture) does the same with clusters of samples circled on the axis and the regions of without samples circled in red: in the regions without data the hypothesis is not constrained at all.
How flexible the hypothesis is. A drawing with a few points shows a straight line and a curve through the same samples, and next to them a curve that oscillates wildly while passing through every point. The notes do not name it, but this is the situation the program calls overfitting: with a flexible enough hypothesis set the in-sample error can be made tiny without the hypothesis resembling between and beyond the samples.
Separating data for training and checking. The last drawing of the first handwritten lecture plots points with and marks some of them as Train (circles) and the others as Validation (squares), interleaved along the axis: the hypothesis is built on the training points and judged on the validation points, which it has not seen. The organisation of this idea (hold-out, repeated hold-out, k-fold, statistical comparison of models) is in Model Selection and Validation - Hold-Out, k-Fold and Statistical TestsTo decide which of two models is better, fix their hyper-parameters, train each on a training set (this fits the parameters, the vector w or theta) and measure a performance score such as F1 on a separate test set; one split is too fragile, so the hold-out is repeated K times (or K-fold cross-validation is used) and the paired scores of the two models are compared with a statistical test. The null hypothesis H0 is that the two models perform equally; the significance level alpha is fixed before the experiment, and the p-value is the probability of observing the obtained differences under H0. Parametric test: t-test; non-parametric: Wilcoxon.Model Selection and Validation - Hold-Out, k-Fold and Statistical Tests →.
5. The link with probability
The quantity that matters is the error over the whole input distribution, written in the handwritten page on the finite-hypothesis bound. The relation between and when has elements is the content of PAC Learning and Hoeffding's InequalityFor a finite hypothesis set of M hypotheses and N independent samples, the probability that the in-sample error of the chosen hypothesis g differs from its true error by more than epsilon is at most 2 M exp(-2 epsilon^2 N). The bound comes from Hoeffding's inequality for one hypothesis, P(|nu - mu| > epsilon) <= 2 exp(-2 epsilon^2 N), and from the union bound P(E1 or ... or EM) <= P(E1) + ... + P(EM), which is exact only for disjoint events and loose when the bad events overlap.PAC Learning and Hoeffding's Inequality →. For the probability concepts used there see Markov and Chebyshev InequalitiesFor a nonnegative random variable P(X >= a) is at most E(X)/a (Markov), and for any random variable with finite mean and variance P(|X - E(X)| >= eps) is at most var(X)/eps^2 (Chebyshev); both bounds are loose but universal, valid whatever the distribution.Markov and Chebyshev Inequalities → and Central Limit Theoremthe standardized arithmetic mean of iid random variables with finite variance converges in distribution to N(0,1), whatever the distribution of the variables, which justifies the Gaussian approximation of sums.Central Limit Theorem →.
Versione ripasso
- Setting: unknown ; samples ; hypothesis set ; the algorithm returns with .
- Signed differences cancel, so use or ; the course takes the square: for a constant (its minimiser is the mean of the outputs, derived here).
- Error function ; in-sample error .
- Sum of squared errors: . Minimised by ADALINE and Gradient DescentADALINE is a perceptron whose activation function is the identity: during training the unit outputs w^T x and the in-sample error E_in = (1/N) sum (y_i - w^T x_i)^2 is minimised by gradient descent, w_new = w_old - eta * grad E_in, with partial derivatives dE_in/dw_j = (2/N) sum (y_i - w^T x_i)(-x_i^j) and matrix form grad E_in proportional to -X^T (Y - X w). The prediction is still the sign of w^T x. Learning rate eta sets the step size and a stopping rule ends the iteration.ADALINE and Gradient Descent → and in closed form by Linear RegressionIn linear regression the hypothesis is h(x) = w^T x and the in-sample error is E_in(w) = (1/N) sum (w^T x_i - y_i)^2 = (1/N) times the squared norm of (Xw - Y), with X the N-row data matrix. Setting the gradient (2/N) X^T (Xw - Y) to zero gives the normal equations X^T X w = X^T Y and the closed-form solution w = (X^T X)^{-1} X^T Y, where (X^T X)^{-1} X^T is the pseudo-inverse of X; only a small square matrix (number of features) has to be inverted. Polynomial regression is the same formula on a data matrix with columns 1, x, x^2, ...Linear Regression →.
- Classification: zero-one loss (count the misclassified points, as the perceptron does in Halfspaces and the Perceptron AlgorithmA perceptron computes h(x) = sign(w^T x) where x includes a constant coordinate x0 = 1 that absorbs the threshold into the bias weight w0; its decision boundary is the hyperplane w^T x = 0 (a line in the plane, x2 = -(w1/w2) x1 - w0/w2). The Perceptron Learning Algorithm scans the data and, on every misclassified point, replaces w by w + y x. A single perceptron cannot separate the exclusive-or pattern; two perceptrons feeding a third give a multilayer network.Halfspaces and the Perceptron Algorithm →).
- Empirical risk minimisation, as the notes do it: fix ; define the error; pick the with smallest . The name is only a textbook pointer.
- is a proxy: samples cover the region where is large; elsewhere the hypothesis is unconstrained. A flexible curve can pass through every sample and oscillate between them (overfitting, sketched but not named in the notes).
- Keep data aside (validation points never seen in training): Model Selection and Validation - Hold-Out, k-Fold and Statistical TestsTo decide which of two models is better, fix their hyper-parameters, train each on a training set (this fits the parameters, the vector w or theta) and measure a performance score such as F1 on a separate test set; one split is too fragile, so the hold-out is repeated K times (or K-fold cross-validation is used) and the paired scores of the two models are compared with a statistical test. The null hypothesis H0 is that the two models perform equally; the significance level alpha is fixed before the experiment, and the p-value is the probability of observing the obtained differences under H0. Parametric test: t-test; non-parametric: Wilcoxon.Model Selection and Validation - Hold-Out, k-Fold and Statistical Tests →. Finite bound: PAC Learning and Hoeffding's InequalityFor a finite hypothesis set of M hypotheses and N independent samples, the probability that the in-sample error of the chosen hypothesis g differs from its true error by more than epsilon is at most 2 M exp(-2 epsilon^2 N). The bound comes from Hoeffding's inequality for one hypothesis, P(|nu - mu| > epsilon) <= 2 exp(-2 epsilon^2 N), and from the union bound P(E1 or ... or EM) <= P(E1) + ... + P(EM), which is exact only for disjoint events and loose when the bad events overlap.PAC Learning and Hoeffding's Inequality →.
- Typical errors: judging a model on the points it was fitted on; summing signed errors (they cancel); confusing with .
Teoria collegata
- ADALINE and Gradient Descent
- Introduction to Machine Learning - Learning, Data and Tasks
- Introduction to Machine Learning - Program Map
- Linear Regression
- Model Selection and Validation - Hold-Out, k-Fold and Statistical Tests
- PAC Learning and Hoeffding's Inequality
- Python Notebooks - Exercises on Perceptron, Regression and Logistic Regression