Introduction to Machine Learning - Mock Exam 2
Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.
In questa pagina 14
The written tests of this course are not public. This mock exam is therefore built only on the notes of the course (learning and data, statistical learning framework, Hoeffding bound, perceptron and its convergence bound, ADALINE, logistic regression, linear regression, Bernoulli likelihood, classification metrics, model selection, and the Python notebooks). The questions and the data are new: it is not a copy of any real test. The official format, from the course description, is continuous activities on the course platform and a final closed-book written test. The format used here is a proposal of this site, not declared by the course: 10 multiple-choice questions worth 1.5 points each and 3 problems worth 5 points each, for a total of 30 points, in 90 minutes, with four options per question and exactly one correct option.
Conventions used in the whole test: every input vector contains the constant coordinate when a weight vector is used; and are the natural logarithm; matrices are written by rows, so [ [1, 2], [3, 4] ] has first row .
How to use it: work with a timer, write each formula in letters before putting the numbers in, and look at the "Result" only when a question is finished.
Question 1
The first lecture says when machine learning is the right tool: three things must hold together. Which of the following problems satisfies all three?
- A) Computing the area of a circle from its radius: a pattern exists and many data points can be recorded, so machine learning is the right tool even if the exact formula is known.
- B) Predicting a label that was assigned by tossing a fair coin for every object, with a million recorded examples: the data are plentiful, so machine learning will find the rule.
- C) Deciding whether to approve credit from historical records of applicants: a pattern links the applicant information to good or bad customers, nobody can write it as a formula, and the records are available.
- D) A relation between inputs and outputs that exists and cannot be written as a formula, but for which no example has ever been recorded.
Show the result
C
Show the full solution
C is correct: the credit example of 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 → has all three requirements stated on the slide: a pattern exists, we cannot pin it down mathematically, we have data on it. A fails the second requirement: when the pattern can be written as an exact formula (the area of a circle) it can be pinned down mathematically and there is nothing to learn. B fails the first: labels assigned by a coin have no pattern, so no quantity of data reveals one. D fails the third: without data there is no experience from which to choose a hypothesis.
Question 2
A single perceptron has to classify the four points and , labelled , and and , labelled . Which statement is correct?
- A) No straight line separates the two classes, so the Perceptron Learning Algorithm, which stops only when every point is correct, would never stop; this is why the notebooks add a maximum number of iterations.
- B) The line separates them: and lie on one side and and on the other.
- C) After adding the constant coordinate and running the algorithm for enough epochs, the weights found separate the four points.
- D) The bound guarantees that the algorithm stops after a finite number of updates on these points.
Show the result
A
Show the full solution
A is correct: these four points are the exclusive-or pattern of 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 →; whichever line is drawn, one point ends on the wrong side, and an algorithm that stops only when all points are correct never stops, so a maximum number of iterations is needed. B is false: for the point gives and the point gives , so two points of the same class are on opposite sides of the line (and and lie on it). C is false: the constant coordinate only absorbs the threshold into the weight ; the hypothesis is still a single halfspace, which cannot represent this pattern. D is false: the bound of Perceptron Convergence and the Margin BoundThe distance of a point x from the hyperplane w^T x + b = 0 is |w^T x + b| / sqrt(w^T w), obtained by writing x = x_p + gamma with gamma parallel to w. If the data are linearly separable with margin gamma (a unit vector w* with y_i w*^T x_i >= gamma for all i) and every point lies in a ball of radius R, the Perceptron Learning Algorithm makes at most K <= R^2 / gamma^2 updates. Proof: after K updates w_{K+1}^T w* >= K gamma, hence norm of w_{K+1} >= K gamma; and norm of w_{K+1} squared <= K R^2; combine.Perceptron Convergence and the Margin Bound → assumes that the data are linearly separable with a margin , and here no such margin exists.
Question 3
With the notation of the course, a column vector is and its norm is . For , what is ?
- A)
- B)
- C)
- D)
Show the result
D
Show the full solution
The squares of the entries are , , , , with sum , and (the same quantity that bounds each point by in Perceptron Convergence and the Margin BoundThe distance of a point x from the hyperplane w^T x + b = 0 is |w^T x + b| / sqrt(w^T w), obtained by writing x = x_p + gamma with gamma parallel to w. If the data are linearly separable with margin gamma (a unit vector w* with y_i w*^T x_i >= gamma for all i) and every point lies in a ball of radius R, the Perceptron Learning Algorithm makes at most K <= R^2 / gamma^2 updates. Proof: after K updates w_{K+1}^T w* >= K gamma, hence norm of w_{K+1} >= K gamma; and norm of w_{K+1} squared <= K R^2; combine.Perceptron Convergence and the Margin Bound →; the notation page of that note gives the formula). So D is correct. A is the sum of the entries, , which is not a norm. B is the sum of the absolute values, , another quantity that is not the one defined in the notes. C is the sum of the squares, , which is : the square root is missing.
Question 4
An ADALINE with weights is trained by stochastic gradient descent. The notebook updates the weights after each example with , where the error is the label minus the output of the unit. The example is with label , and . What are the weights after this single update?
- A) , because the point is already classified correctly
- B)
- C)
- D)
Show the result
B
Show the full solution
The output of the unit is the real number , so the error is . The correction is , and the new weights are : B is correct (see 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 →). A computes the error on the sign of the output, as the perceptron does (, no mistake, no update); ADALINE instead computes the error on the real number , which is , not . C subtracts the correction instead of adding it (with the error defined as the sign is plus). D forgets the factor of the derivative of the square: it uses .
Question 5
Logistic regression minimises the cost , where is the Bernoulli log-likelihood. Which statement about its gradient-descent step, compared with that of ADALINE, is correct?
- A) The gradient is with no data matrix, because the sigmoid already contains the inputs.
- B) The gradient has the same form as for ADALINE, but the output error is computed before the sigmoid, on , while ADALINE computes it after the identity.
- C) The gradient is and the update is : the same form as for ADALINE, with the output error computed after the sigmoid instead of after the identity.
- D) The update is , because comes from a log-likelihood and the log-likelihood has to be maximised.
Show the result
C
Show the full solution
C is correct: the page summarised in Logistic RegressionLogistic regression models the probability p of the positive class: the logit (log of the odds p/(1-p)) is assumed linear in the input, logit(p) = w^T x = z. Inverting it gives p = 1/(1 + e^(-z)), the logistic sigmoid; an object goes to class 1 when the sigmoid exceeds 0.5, i.e. when z > 0. The parameters are learned by maximising the Bernoulli log-likelihood, equivalently minimising the cost J = -y log(yhat) - (1 - y) log(1 - yhat), by gradient descent with gradient (1/m) X^T (h(x) - y).Logistic Regression → gives and , and the note comments that it is the form of 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 → with the output error computed after the sigmoid instead of after the identity. A is false: the gradient contains , as for ADALINE. B is false because it swaps the two models: the logistic error is computed after the sigmoid, and ADALINE's after the identity. D is false: the course minimises , which is a cost, so the gradient is subtracted; adding it would increase the cost (the notebook writes the equivalent step , with the error defined the other way round).
Question 6
In linear regression the data matrix has rows (one per object) and columns (the constant column included). The closed form is used. Which statement is correct?
- A) is a matrix and it is the one that has to be inverted, so the cost grows with the number of objects.
- B) is a matrix, and it is the only matrix to invert, whatever the number of rows; the number of rows only affects the cost of forming the product.
- C) Since is not square, does not exist and the closed form cannot be applied.
- D) The formula works in every case, also when cannot be inverted.
Show the result
B
Show the full solution
B is correct: is , so is , and this is the matrix whose inverse is needed; this is the argument about the cost of the formula in 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 →, where only affects the cost of forming . A mixes up the order of the product: would be , but the formula contains . C is false: it is exactly because has no inverse that the matrix , called the pseudo-inverse of , is used. D is false: the note states that the formula assumes that is invertible.
Question 7
The actual labels of eight objects are and the predicted labels are , with the positive class. Which is the confusion matrix, with the rows for the actual class (positive first) and the columns for the predicted class (positive first)?
- A)
[ [3, 1], [2, 2] ] - B)
[ [3, 2], [1, 2] ] - C)
[ [2, 2], [1, 3] ] - D)
[ [3, 1], [1, 3] ]
Show the result
A
Show the full solution
Compare the pairs one by one, as in Classification Metrics - Confusion Matrix, Precision, Recall and F1The performance of a classifier is read from the confusion matrix, whose rows are the actual classes and columns the predicted ones: TP, FN / FP, TN for a binary problem. Accuracy = (TP + TN) / total; recall = TP / (TP + FN); precision = TP / (TP + FP); F1 = 2 recall precision / (recall + precision). With an unbalanced data set accuracy can look good while recall is poor (10 positive and 90 negative objects: accuracy 0.87, recall 0.10, precision 0.20). In multi-class problems the confusion matrix is square and recall and precision are computed class by class from the diagonal.Classification Metrics - Confusion Matrix, Precision, Recall and F1 →: occurs three times (objects 1, 4, 7): ; once (object 5): ; twice (objects 3 and 8): ; twice (objects 2 and 6): . With the layout the matrix is [ [3, 1], [2, 2] ]: A is correct. B is the transpose (rows for the predicted class, columns for the actual one), which swaps and . C is the matrix obtained taking as the positive class ( in the first place). D has the right and but counts and wrongly ( and instead of and ): the actual negatives are objects 2, 3, 6 and 8, and two of them (3 and 8) are predicted positive.
Question 8
Two arrays are defined in NumPy: A = np.array([ [1, 0, 2], [3, 1, -1] ]) and B = np.array([ [2, 1, 0], [1, 1, 1] ]). Which statement is correct?
- A)
np.dot(A, B)returns[ [2, 3], [7, 3] ]. - B)
np.inner(A, B)returns[ [2, 7], [3, 3] ]. - C)
np.inner(A, B)signals an error, for the same reason asnp.dot(A, B). - D)
np.inner(A, B)returns[ [2, 3], [7, 3] ], the same matrix asnp.dot(A, B.T).
Show the result
D
Show the full solution
np.inner(A, B) of two 2-D arrays has as entry the product of row of A with row of B, as explained in Python Notebooks - Random Samples, Plots and Linear Algebra with NumPyThe first course notebook draws random samples with NumPy (uniform with np.random.rand, normal and exponential), plots them with matplotlib (line and scatter plots, histograms compared with the theoretical density from scipy.stats), and shows the NumPy products used later: np.dot and np.inner between a matrix and a vector and between two matrices, with the transpose. This note reproduces the code of the notebook "matplotlib, random numbers and statistics" with the meaning of each call.Python Notebooks - Random Samples, Plots and Linear Algebra with NumPy →: row 1 of A is and gives with row 1 of B and with row 2; row 2 of A is and gives and . So the result is [ [2, 3], [7, 3] ], the same as np.dot(A, B.T): D is correct. A is false: np.dot(A, B) is a matrix product, which needs the number of columns of A () to equal the number of rows of B (), so NumPy signals an error. B gives the transposed matrix: the entry is , not . C is false: np.inner works on these shapes, because it multiplies rows by rows.
Question 9
In the NumPy version of the perceptron of the course notebook the mistake test is if ((np.dot(w, x) * y) < 0): and, after each epoch over all the points, the loop ends if num_errors == 0. The data set is the usual one, with the column of ones, but the weights are started from w = [0, 0, 0]. What happens?
- A) The first point is a mistake,
wbecomesw + eta * (x * y), and the algorithm continues as usual until the points are separated. - B) No update is ever made: every product
np.dot(w, x) * yis , which is not smaller than ; the first epoch ends withnum_errors == 0, the loop stops withepochs = 1andwstill equal to zero. - C) The loop never ends, because the products are always and the counter of errors is never reset.
- D) The loop diverges, because the learning rate of the notebook is outside the range written in its comment.
Show the result
B
Show the full solution
With w = [0, 0, 0] the scalar product np.dot(w, x) is for every point, so the product with y is , and the test < 0 is false: a point with output exactly is not counted as a mistake. No update is made, num_errors stays during the first epoch, and the check num_errors == 0 ends the loop with epochs = 1: B is correct, as in 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 →, whose note observes that from w = 0 the loop would never update and that the notebook therefore starts from random weights. A would need the point to count as a mistake, but the test is a strict inequality. C is false: the exit condition is satisfied after the first epoch. D is false: the learning rate is not even used, because no update takes place (and the comment of the notebook about is not enforced by the code).
Question 10
In the logistic-regression notebook there are N = 100 points per class, the mini-batch size is batch_size = 50 and max_epochs = 100. In every epoch the loop for j in range(0, y.shape[0], batch_size): updates w once for each block, and all the epochs are executed. How many updates of w are made in total?
- A)
- B)
- C)
- D)
Show the result
A
Show the full solution
The data set has objects (the points of the two classes are stacked), so range(0, 200, 50) gives the starting indices : four mini-batches, hence four updates per epoch. Over max_epochs = 100 epochs this makes updates: A is correct (see Python Notebooks - Exercises on Perceptron, Regression and Logistic RegressionThe exercise notebooks of the course: generating two- and three-class data with NumPy distributions, training an ADALINE/perceptron by mini-batch stochastic gradient descent and plotting the errors per epoch, polynomial regression by the closed form w = (X^T X)^{-1} X^T y on a data matrix with columns 1, x, x^2, and logistic regression trained by mini-batch gradient descent on the log loss. Statement and solution code are given, with the inconsistencies between statement and code pointed out.Python Notebooks - Exercises on Perceptron, Regression and Logistic Regression →). B counts one update per epoch, as if the whole data set were one batch. C counts the number of objects, as if the update were made after every example (stochastic gradient descent with batch size 1 would give , which is D, not the case here). Note that the vector errors_epoch of the notebook stores the log-loss cost of each epoch, summed over the objects, not a number of updates or of mistakes.
Problem 1 (points 5)
A learning algorithm chooses its final hypothesis from a finite hypothesis set with hypotheses, using independent samples. The tolerated gap is .
a) Compute the upper bound for (1 point).
b) A colleague applies to the inequality for one fixed hypothesis, . Compute the number obtained, say by which factor it differs from the answer of part a), and explain why it is not a valid bound for (1 point).
c) Find the smallest number of samples for which the bound of part a) is at most , first with and then with hypotheses. Compare the two values of with the ratio of the two values of (2 points).
d) Two bad events and of two similar hypotheses have , and . Compute and the value given by the union bound, and say what the comparison shows about the factor (1 point).
Show the result
a) .
b) ; it is times smaller, so it understates the bound by the factor ; it is not valid because is chosen after looking at the data.
c) : for , for . Ten times more hypotheses need only about 29% more samples ( more).
d) ; union bound . The bound overestimates when the events overlap, so the factor is pessimistic for similar hypotheses.
Show the full solution
The exponent is (the gap is squared: ). Then
With these data the probability that the gap of exceeds is at most about 4%.
b) For one fixed hypothesis Hoeffding's inequality gives . Compared with part a) it is times smaller: the missing factor is exactly . The single-hypothesis inequality is valid only for a hypothesis fixed before looking at the data (a bin with a given fraction of marbles). The algorithm picks after seeing the samples, so may be any of the hypotheses; the gap of exceeds if at least one of the events happens, and the union bound adds the probabilities, each at most .
c) Solve for : take the logarithm, , so
For : and , so (check: at the bound is , at it is ).
For : and , so (at the bound is ).
The hypothesis set is ten times larger, but the number of samples grows only from to , that is by samples, about 29%: the difference is . This is the reading of the bound: the probability is exponentially small in and grows only linearly in , so enters the required through a logarithm.
d) Inclusion-exclusion for two events that can share outcomes:
The union bound drops the intersection: . The two events overlap strongly ( out of for the smaller one), so the bound overestimates by more than half. Two similar hypotheses have almost the same bad event, so counting both, as the factor does, is pessimistic: the bound of part a) is safe but loose.
Typical mistakes: using without for a chosen from the data; forgetting to square ; exchanging (the gap) and (the probability); rounding down instead of up; thinking that the union bound is an equality.
Problem 2 (points 5)
Two coins are tossed independently; heads is coded and tails , and the tosses of one coin are independent and identically distributed with probability of heads . Coin A gives, in 16 tosses, the sequence H T T H H H T H H T H H T H H H. Coin B gives 5 heads in 12 tosses.
a) For coin A, write the likelihood as a function of the number of heads and of the number of tosses , and compute it at and at (1 point).
b) Write the log-likelihood of coin A, find the maximum likelihood estimate by setting the derivative to zero, and compute and its difference from (1.5 points).
c) Compute for coin B and the value of its log-likelihood (1 point).
d) If the two coins were assumed to have the same (one i.i.d. sample of 28 tosses), find the estimate and the total log-likelihood. Compare it with and comment (1.5 points).
Show the result
a) , : ; , .
b) ; ; , , difference (likelihood times larger).
c) ; .
d) ; total against with two separate parameters: the separate fit is larger by about , which is the price of forcing the same on two coins that look different.
Show the full solution
a) Each toss contributes the factor of the Bernoulli distribution, a head giving and a tail (Bernoulli Distribution and Maximum Likelihood EstimationA binary outcome (heads = 1, tails = 0) is modelled by a Bernoulli distribution with parameter theta: P(x | theta) = theta^x (1 - theta)^(1 - x). For independent identically distributed observations the likelihood is the product of the single probabilities; with K heads in n tosses it is L(theta) = theta^K (1 - theta)^(n - K). Maximising the log-likelihood l(theta) = K log theta + (n - K) log(1 - theta) (maximum likelihood estimation) gives theta = K / n.Bernoulli Distribution and Maximum Likelihood Estimation →). Because the tosses are independent and identically distributed, the likelihood is the product of the factors; counting the heads in the sequence H T T H H H T H H T H H T H H H (positions ) gives , and the tails are :
At : . At : . The value at is about three times larger: the data are more probable under than under a fair coin.
b) The product is turned into a sum with the logarithm, which has its maximum at the same :
Set the derivative to zero, remembering the factor from the chain rule on :
the observed fraction of heads. The values: , and . The difference is , so the likelihood at is times the likelihood at ; also , slightly above the value at , as it must be for the maximum.
c) Coin B has and , so and
d) If the same is used for all 28 tosses, "identical distribution" applies to the whole sample: heads in tosses, and the same formula gives . The total log-likelihood is
With one parameter per coin the total is , which is higher by about . A model with two free parameters can always do at least as well on the data as one with a single shared parameter (the shared value is one of the choices available to the two-parameter fit), and here the gain is clear because the two estimates, and , are far apart: the data support different probabilities of heads.
Typical mistakes: counting the tails instead of the heads in ; forgetting the factor in the derivative of ; reading the likelihood as the probability of instead of the probability of the data as a function of ; averaging and instead of pooling the counts ( instead of ).
Problem 3 (points 5)
Two models, Model 1 (nearest neighbour with ) and Model 2 (nearest neighbour with ), are compared on a data set of objects. The hold-out is repeated times: each run uses a different random split in 80% training and 20% test objects, and both models use the same split in each run. The scores on the test part are:
| run | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Model 1 | 0.82 | 0.77 | 0.91 | 0.70 | 0.88 | 0.75 |
| Model 2 | 0.78 | 0.80 | 0.86 | 0.71 | 0.81 | 0.77 |
a) Give the number of training and test objects of each run and explain why the scores are paired. Compute the six differences (Model 1 minus Model 2), then list their absolute values in decreasing order, each labelled with the model that was better in that run (1.5 points).
b) In how many runs is each model better? What does the ordered list of part a) show about the size of the differences in favour of each model? (1 point)
c) The null hypothesis is that the two models perform equally, and the significance level was fixed before the experiment at . The Wilcoxon test (as in the notebooks, scipy.stats.wilcoxon(scores_1, scores_2)) returns the p-value on these six pairs. State the decision. A student proposes to raise to after seeing the p-value, in order to declare the models different: say why this is not acceptable (1.5 points).
d) If the same procedure with is applied to comparisons between pairs of models that are really equivalent, how many "significant" results are expected by chance? (1 point)
Show the result
a) training and test objects per run. Differences: , , , , , . Ordered absolute values: (Model 1), (Model 1), (Model 1), (Model 2), (Model 2), (Model 2).
b) Three runs each (runs 1, 3, 5 for Model 1; runs 2, 4, 6 for Model 2). The three largest differences favour Model 1, the three smallest favour Model 2.
c) : is not rejected, the two models are probably equivalent on these data. must be decided before the experiment; choosing it after the p-value defeats its meaning.
d) About .
Show the full solution
a) With objects and a 20% test part, each run trains on objects and is tested on (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 →). The split is arbitrary and the score depends on which objects land in the test part, so one split is fragile and the hold-out is repeated. The scores are paired because in each run the two models use the same training and test objects: the score of Model 1 in run is compared only with the score of Model 2 in the same run , which removes the effect of an easy or a hard split from the comparison. What matters is the list of differences :
| run | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
The absolute values in decreasing order, each with the better model (a positive difference means Model 1, a negative one Model 2), as in the Wilcoxon example of the notes:
0.07 -> M1 (run 5)
0.05 -> M1 (run 3)
0.04 -> M1 (run 1)
0.03 -> M2 (run 2)
0.02 -> M2 (run 6)
0.01 -> M2 (run 4)b) Model 1 is better in runs 1, 3 and 5, Model 2 in runs 2, 4 and 6: three runs each, so counting the wins does not separate the models. The ordered list shows a clear pattern in the size of the differences: all the large differences (, , ) are in favour of Model 1, all the small ones (, , ) in favour of Model 2. So the differences are not spread symmetrically around : when Model 1 wins it wins by more, and when Model 2 wins it wins by little. Whether this is more than chance is exactly what the statistical test has to decide, and with only six runs the evidence is weak.
c) The significance level is the total area of the two tails of the distribution of the differences expected if the models were equivalent, and it is decided before the experiment. The rule of the notebook is: if the p-value is greater than the two samples are probably from the same distribution, otherwise they are probably different. Here , so the null hypothesis (the two models perform equally) is not rejected: the observed differences are quite compatible with equivalent models. Raising to after seeing is not acceptable: is the probability of a false alarm that we agree to accept when the models are equal, and a value chosen after the result, only to make the result "significant", is no longer a probability fixed in advance; with one would declare a difference in half of the comparisons between equivalent models. The notebook says exactly this: "stop here and decide the value" before reading the p-value.
d) With (5%), in about comparisons out of between two equivalent models a "significant" difference will appear by chance (remark of the notes). For comparisons the expected number is .
Typical mistakes: comparing the scores of the two models on different splits (no pairing); subtracting in the wrong order and mixing the signs of the differences; deciding after reading the p-value; reading a p-value above as a proof that the models are equal instead of "no evidence of a difference".
Self-assessment grid
| item | points | what must be there for full points | typical mistakes |
|---|---|---|---|
| Question 1 | 1.5 | C: pattern exists, cannot be written as a formula, data available | accepting a problem with a known formula, with no pattern, or with no data |
| Question 2 | 1.5 | A: exclusive-or is not separable, PLA never stops, maximum iterations | thinking the bias coordinate or the margin bound fixes it |
| Question 3 | 1.5 | D: | sum of the entries; sum of the absolute values; forgetting the square root |
| Question 4 | 1.5 | B: error on the real output, correction , weights | error on the sign; wrong sign of the step; missing factor |
| Question 5 | 1.5 | C: , subtracted, error after the sigmoid | dropping ; swapping sigmoid and identity; adding the gradient |
| Question 6 | 1.5 | B: is whatever the number of rows | inverting a matrix of size ; denying the pseudo-inverse; ignoring the invertibility condition |
| Question 7 | 1.5 | A: [ [3, 1], [2, 2] ] |
transposed matrix; positive class swapped; miscounting |
| Question 8 | 1.5 | D: np.inner multiplies rows by rows, np.dot(A, B) is undefined |
applying the matrix product to equal shapes; transposed result |
| Question 9 | 1.5 | B: strict inequality, no update, stops with epochs = 1 |
counting a zero output as a mistake; thinking the loop never ends |
| Question 10 | 1.5 | A: four mini-batches per epoch times epochs | one update per epoch or per object |
| Problem 1 | 5 | bound (1); , factor , chosen after the data (1); and , linear in but logarithmic in (2); against (1) | no factor ; not squared; rounded down; union bound as equality |
| Problem 2 | 5 | , and its values (1); and (1.5); , (1); pooled , against (1.5) | counting tails; missing in the derivative; averaging the two estimates |
| Problem 3 | 5 | and objects, pairing, six differences and the ordered labelled list (1.5); three wins each and the pattern of the sizes (1); , fixed in advance (1.5); false alarms (1) | unpaired scores; chosen after the p-value; "not rejected" read as "proved equal" |
| Total | 30 |