Introduction to Machine Learning - Mock Exam 3
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, perceptron and its convergence bound, ADALINE, logistic regression, linear regression, classification metrics, 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: an input vector contains the constant coordinate when the text says so, and in the problem on the hyperplane the bias is written separately; labels are for the perceptron and ADALINE; where a number is rounded, three significant digits are enough.
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
In the diagram of the components of learning in the course, which description is correct?
- A) The hypothesis set is produced by the learning algorithm from the data.
- B) The data are generated by the unknown target function ; the learning algorithm uses them together with the hypothesis set and returns a final hypothesis with .
- C) The final hypothesis is the target function , which becomes known at the end of the training.
- D) The samples are generated by the final hypothesis , and the algorithm then looks for the target .
Show the result
B
Show the full solution
B is the diagram 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 →: the unknown target generates the samples , the hypothesis set and the samples enter the learning algorithm, and the algorithm returns . A is false: the hypothesis set is one of the two inputs of the algorithm, fixed in advance, not an output. C is false: stays unknown; is only an approximation of it. D is false: it is the target , not , that generates the data.
Question 2
A hypothesis is fitted to samples whose inputs crowd in the region where the input density is large, between two values and . Outside there are few or no samples. What do the course notes say about the behaviour of the hypothesis outside this region?
- A) A small in-sample error guarantees that the hypothesis is close to the target everywhere.
- B) The algorithm minimises over the whole input space, so the hypothesis follows also where nothing was observed.
- C) The error outside is irrelevant, because the only error that matters is on the samples.
- D) Where there are no samples the hypothesis is not constrained at all, so it can be far from there: the error on the samples is only a proxy for the error on the inputs that will really be seen.
Show the result
D
Show the full solution
D is the point of the section on the input distribution in The Statistical Learning Framework and Empirical Risk MinimizationA hypothesis is judged by an error function computed pointwise on the data and averaged: the in-sample (empirical) error E_in(h) = (1/N) sum of e(f(x_i), h(x_i)); with squared differences it is the sum of squared errors. The learning algorithms of the course all search the hypothesis set for the h with small in-sample error, but what matters is the error on new inputs drawn from the same input distribution, so the data must cover the regions where the inputs live, and part of the data must be held back to check the result.The Statistical Learning Framework and Empirical Risk Minimization →: in the regions without data the hypothesis is not constrained, and the sketch hatches the gap between the hypothesis and there. A is false for the same reason: says nothing about regions without samples. B is false: is computed only on the samples, so only the samples constrain the hypothesis. C is false: the notes say that what matters is the error over the whole input distribution (called in 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 →), and that is only a proxy for it.
Question 3
Which statement compares the perceptron and ADALINE correctly?
- A) The perceptron compares the real number with the label, while ADALINE compares its sign.
- B) Both are updated only on the misclassified points, with the rule .
- C) The perceptron is updated only on misclassified points with and stops when no point is misclassified; ADALINE uses all the points with and stops by a stopping rule (no errors or a maximum number of epochs).
- D) Both stop only when the squared error is zero.
Show the result
C
Show the full solution
C is the comparison table 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 →: the perceptron uses only the misclassified points, the update is and it stops when no point is misclassified; ADALINE uses all the points, the update is and it stops with a stopping rule. A swaps the two: the perceptron compares the sign of with the label, ADALINE the number itself. B is false for ADALINE, which learns from all the points, not only from the mistakes. D is false: the perceptron has no squared error and stops when there are no mistakes; ADALINE stops with a stopping rule, not necessarily at zero error.
Question 4
Which statement compares perceptron, ADALINE and logistic regression correctly, as in the summary table of the course?
- A) The perceptron outputs and is updated on its mistakes; ADALINE outputs and minimises the squared error; logistic regression outputs and minimises .
- B) The three models have the same output, , and differ only in the learning rate.
- C) Logistic regression minimises the squared error like ADALINE, with the sigmoid applied to the output.
- D) ADALINE outputs and logistic regression outputs .
Show the result
A
Show the full solution
A is the summary table of 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 →: perceptron, output the sign, update on mistakes, stops when there are no mistakes; ADALINE, output , squared error, stopping rule; logistic regression, output , cost , stopping rule. B is false: the three outputs are different (sign, identity, sigmoid). C is false: logistic regression minimises the cost obtained from the Bernoulli likelihood, not the squared error. D swaps the two activation functions: the identity belongs to ADALINE, the sigmoid to logistic regression.
Question 5
A data set has samples with features, and the constant column is added to the data matrix . The weight vector is and is the vector of the outputs. Which statement about is correct?
- A) is (one column per sample), is , and is , with one error for each weight.
- B) is , is , and is with one error for each sample; is the single number .
- C) is , and is the vector , one error for each sample, with no squares.
- D) is , because the constant column is not part of the data matrix.
Show the result
B
Show the full solution
B follows 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 →: the examples are the rows of ( has the constant coordinate and the features, so columns) and the outputs are the column ; the vector is with entries , and since the error is the number . A has the examples in the columns and gives one error per weight instead of one per sample. C is false: the vector of the errors is squared, summed and divided by , giving a single number. D is false: the data matrix of the course carries the column of ones.
Question 6
On a data set with positive and negative objects a classifier gives , , , . Which conclusion is drawn in the course notes?
- A) The accuracy shows that the classifier finds most of the positive objects.
- B) The recall is and the precision is .
- C) Accuracy is the only measure that matters here, because it is the highest of the three.
- D) The accuracy is , but the recall is and the precision is : with unbalanced classes most objects are negative and are classified correctly anyway, so accuracy alone is not enough.
Show the result
D
Show the full solution
D is the lesson of the worked example of 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 →: accuracy is , recall is and precision is . A is false: only of the positives was found (recall ). B swaps the two definitions: recall divides by the actual positives , precision by the objects called positive . C is false: recall and precision show what the accuracy hides when the classes are unbalanced.
Question 7
In the first notebook with random samples, which statement is correct?
- A) In
np.random.normal(loc = 1.0, scale = 0.2, size = 100)the parameterlocis the mean andscalethe standard deviation, while innp.random.exponential(scale = 0.2, size = 100)the parameterscaleis the mean of the distribution. - B) In
np.random.normal(loc = 1.0, scale = 0.2, size = 100)the parameterscaleis the variance of the distribution. - C)
plt.hist(x, density = True)draws the number of samples in each bin, so it cannot be compared with the theoretical density. - D)
norm.pdf(x, loc = 1.0, scale = 0.2)draws new random numbers from the normal distribution.
Show the result
A
Show the full solution
A is the description 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 →: for the normal samples loc is the mean and scale the standard deviation, and for the exponential samples scale is the mean of the distribution. B is false: scale is the standard deviation, not the variance. C is false: with density = True the histogram is normalised to area , exactly so that it can be compared with the red points of the theoretical density. D is false: norm.pdf evaluates the theoretical density at the sampled values x; the samples come from np.random.normal.
Question 8
In the batch ADALINE notebook the sum of squared errors is computed by
def error_sse(errors):
error = np.sum(np.square(errors)) / 2
return errorWhat does error_sse(np.array([1, -2, 2])) return?
- A)
- B)
- C)
- D)
Show the result
C
Show the full solution
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 → the SSE of this notebook is divided by 2, unlike the SSE of the exercises. The squares are , , , their sum is , and : C is correct. A is the sum of squares without the division by 2. B is the mean of the squares, : the function divides by 2, not by the number of points. D squares the sum of the errors instead of summing the squares: , and signed errors would partly cancel.
Question 9
In the first scikit-learn example the notebook computes f1_score(lr_pred, y_test), with the predictions first and the true labels second, while the scikit-learn convention is the opposite order. Which statement is correct?
- A) The call raises an error, because the true labels must always be the first argument.
- B) The result is the same: exchanging the arguments exchanges precision and recall, and is symmetric in them; for example precision and recall , or precision and recall , both give .
- C) The result changes: with the arguments exchanged the same predictions give in one order and in the other.
- D) The call returns the recall instead of the score, because the roles of the two arguments are exchanged.
Show the result
B
Show the full solution
B is the remark of Python Notebooks - scikit-learn Model Comparison and Wilcoxon TestTwo example notebooks compare six scikit-learn classifiers (logistic regression, perceptron, KNN, decision tree, SVC, random forest) on a real data set loaded from the UCI repository: hold-out split with train_test_split, F1 score, k-fold cross-validation with cross_validate and scoring f1_macro, box plots of the fold scores, and the Wilcoxon signed-rank test (scipy.stats.wilcoxon) on the paired fold scores; the second notebook adds a stratified test set, more folds on the best models and the final training and test of the chosen model. A separate short notebook draws two normal samples to see how often the Wilcoxon test rejects at the 0.05 level.Python Notebooks - scikit-learn Model Comparison and Wilcoxon Test →: exchanging the two arguments exchanges precision and recall, and the formula of 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 →, , does not change when the two are swapped; with the numbers of the option, in both orders. A is false: the notebook runs and uses that order. C is false for the symmetry just shown. D is false: the function still returns the score; only precision and recall are exchanged inside it.
Question 10
With t = " logging" (two spaces, then the word), what does t.strip("g") return?
- A)
" loggin" - B)
"logging" - C)
" logging" - D)
" loin"
Show the result
A
Show the full solution
In Python Notebooks - Strings and Regular ExpressionsNotebook on Python strings: quoting (single, double, triple quotes), case methods (upper, lower, title, capitalize, swapcase), removing characters at the ends (strip), searching and replacing (find, startswith, endswith, replace, partition), splitting (split, splitlines), and a first use of regular expressions with the re module (search, findall, sub) with the anchors for start and end of string, the dot, the star, the plus and character classes.Python Notebooks - Strings and Regular Expressions →, strip with an argument removes only the given characters from the two ends of the string. The left end of t is a space, which is not a g, so nothing is removed there; the right end is a g, which is removed, and the next character is n, so the call returns " loggin": A is correct. B is the result of t.strip() without argument, which removes white space, not of strip("g"). C is the result when the end of the string is not a g: the notebook example x.strip("g") with a trailing space leaves x unchanged, but here the string ends with g. D removes every g, also the one inside the word, which is what replace does, not strip.
Problem 1 (points 5)
An ADALINE unit has the input (constant coordinate and one feature). Five samples are given: , , , , . Two weight vectors are compared: and .
a) For each weight vector compute the number that the unit gives on the five samples, the class predicted , and the number of misclassified samples (1.5 points).
b) Compute the in-sample error for and for (1.5 points).
c) With , which sample contributes most to ? Is it misclassified? Explain why the unit still counts it as a large error (1 point).
d) The notebook loop stops when all(adaline_output * y > 0). Does it stop with ? And with ? Which of the two weight vectors does ADALINE judge better, and can the perceptron tell them apart (1 point)?
Show the result
a) : outputs ; classes ; mistakes. : outputs ; classes ; mistakes.
b) : . : .
c) The sample : output , error , contribution out of . It is correctly classified: the error is computed on the real number , not on its sign.
d) The products adaline_output * y are for and for : all positive, so the loop stops at once with both, although is not minimal. ADALINE prefers (); the perceptron sees no mistake with either and cannot tell them apart.
Show the full solution
Setting: 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 → for the unit and the error, 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 → for the stopping test, 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 → for the perceptron.
a) Outputs and classes. The activation of ADALINE is the identity, so the unit computes and the class predicted is its sign.
| class with | |||||
| class with |
In both cases the predicted classes equal the labels: no sample is misclassified.
b) In-sample error. The error of a sample is , computed on the real number. For the errors are , , , , ; the squares are , with sum , so . For the errors are , , , , ; the squares are , with sum , so .
c) The largest contribution. For the sample has output and error : its square, , is out of the total . It is correctly classified, since the output is positive and the label is . ADALINE still counts a large error because it compares the label with the number itself and not with its sign: an output far above the label is as bad as one far below it.
d) Stopping test and comparison. The test all(adaline_output * y > 0) asks that every product is positive, that is every point is on the correct side. For the products are and for they are : all positive, so the loop stops immediately in both cases, even though the quantity being minimised, the squared error, is still far from its minimum (as the note observes, the check is made on the sign while the minimised quantity is the squared error). ADALINE judges better, since . The perceptron uses only the misclassified points and there are none, so for the perceptron the two weight vectors are equivalent.
Typical mistakes: applying the sign before computing the error; forgetting to divide by ; confusing "no mistakes" with "minimum squared error"; computing with the wrong sign for the negative samples.
Problem 2 (points 5)
A classifier for three classes , , is tested on objects. The confusion matrix has the actual class in the rows and the predicted class in the columns:
| predicted 0 | predicted 1 | predicted 2 | |
|---|---|---|---|
| actual 0 | 18 | 1 | 1 |
| actual 1 | 3 | 9 | 3 |
| actual 2 | 2 | 2 | 6 |
a) Give the total of each row and of each column, and the accuracy (1 point).
b) Compute and for each class (1.5 points).
c) Compute the score of each class and the macro , that is the averaged over the classes (1.5 points).
d) Which class has the lowest ? For class the recall is higher than the precision: say which entries of the matrix make the denominator of the precision larger (1 point).
Show the result
a) Rows: . Columns: . Accuracy .
b) , , ; , , .
c) ; macro .
d) Class has the lowest (). For class the column total exceeds the row total because objects of class and objects of class were assigned to class .
Show the full solution
Setting: 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 → for the multi-class view; the macro average is the one of the f1_macro score of Python Notebooks - scikit-learn Model Comparison and Wilcoxon TestTwo example notebooks compare six scikit-learn classifiers (logistic regression, perceptron, KNN, decision tree, SVC, random forest) on a real data set loaded from the UCI repository: hold-out split with train_test_split, F1 score, k-fold cross-validation with cross_validate and scoring f1_macro, box plots of the fold scores, and the Wilcoxon signed-rank test (scipy.stats.wilcoxon) on the paired fold scores; the second notebook adds a stratified test set, more folds on the best models and the final training and test of the chosen model. A separate short notebook draws two normal samples to see how often the Wilcoxon test rejects at the 0.05 level.Python Notebooks - scikit-learn Model Comparison and Wilcoxon Test →.
a) Totals and accuracy. The row of class is the total of the actual objects of class : , , . The column of class collects the objects assigned to class : , , . Both sets of totals add up to . The diagonal holds the correct answers, , , , so
b) Recall and precision per class. Each class is seen as "class against the rest":
Recall: , , . Precision: , , .
c) and its macro average. For each class :
- class : ;
- class : ;
- class : .
The macro is the plain average of the three: , a little lower than the accuracy because every class counts the same whatever its size.
d) Reading the matrix. The lowest is that of class , with recall and precision both . Class has a recall of (only of its objects are lost) but a precision of : the column of class has objects, of which only are really of class ; the other are the objects of class and the objects of class in the first column, and they enlarge the denominator of the precision without changing the recall.
Typical mistakes: swapping rows and columns (recall and precision exchange); dividing the recall by the predicted total; averaging recall and precision of all classes before computing instead of averaging the of the classes; using the accuracy alone to judge each class.
Problem 3 (points 5)
In the plane, a hyperplane is written with the bias separate, , with and . Four labelled points are given: with , with , with , with .
a) Compute and the distance from the hyperplane for each point (1.5 points).
b) For find the number , the vector and the point of the hyperplane nearest to . Check that lies on the hyperplane and that equals the distance of part a (1.5 points).
c) Write the same hyperplane with a vector of norm , and also with , . Show that the distance of does not change (1 point).
d) Are the four points on the correct side of the hyperplane? Which is the closest to it, and at what distance (1 point)?
Show the result
a) for ; ; distances .
b) ; ; ; ; .
c) Unit vector: , ; for : . With , : , , distance .
d) , all positive: all four points are on the correct side. The closest is , at distance .
Show the full solution
Setting: 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 → for the distance of a point from a hyperplane; the labels and the side of the hyperplane are those 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 →.
a) Distances. The distance of from the hyperplane is , with .
- : , distance .
- : , distance .
- : , distance .
- : , distance .
b) The nearest point on the hyperplane. The shortest segment from to the hyperplane is perpendicular to it, so is parallel to , , and the nearest point is . Asking that lies on the hyperplane, , gives . For : , so and . Then . Check: , so is on the hyperplane; and , the distance of part a.
c) Scaling the vector. Dividing and by gives the unit vector and : for the value is , which is already the distance (for the distance is simply ). With and , which is the same hyperplane (every coefficient divided by ), and , so the distance is . The value changes with the scale of , the distance does not, because the division by removes the scale.
d) Side and closest point. A point is on the correct side when : the products are , , , , all positive, so the hyperplane separates the four points. Dividing by gives the distances of part a: the closest point is , at distance .
Typical mistakes: forgetting to divide by (that gives , not ); dividing by instead of (that is , not the length of ); forgetting the bias in the numerator; dropping the sign of for a point on the negative side (there is negative, and still reaches the hyperplane).
Self-assessment grid
| item | points | what must be there for full points | typical mistakes |
|---|---|---|---|
| Question 1 | 1.5 | B: generates the data; the algorithm uses data and to return | as an output; confused with |
| Question 2 | 1.5 | D: without samples the hypothesis is not constrained; is only a proxy | trusting a small everywhere |
| Question 3 | 1.5 | C: perceptron on mistakes only with ; ADALINE on all points with | swapping sign and real output; ADALINE on mistakes only |
| Question 4 | 1.5 | A: sign and mistakes; identity and squared error; sigmoid and | swapping the activations; squared error for logistic regression |
| Question 5 | 1.5 | B: is , is , is a number | one error per weight; no squares; no constant column |
| Question 6 | 1.5 | D: accuracy , recall , precision , accuracy not enough | swapping recall and precision; trusting accuracy |
| Question 7 | 1.5 | A: loc mean, scale standard deviation; exponential scale is the mean |
variance instead of standard deviation; histogram as counts |
| Question 8 | 1.5 | C: sum of squares , divided by | forgetting the ; mean instead of ; squaring the sum |
| Question 9 | 1.5 | B: is symmetric in precision and recall | thinking the order changes the score |
| Question 10 | 1.5 | A: strip("g") removes g only at the ends, spaces stay |
confusing strip with replace; ignoring the leading spaces |
| Problem 1 | 5 | outputs and classes, mistakes (1.5); and (1.5); sample , error on the real number (1); stopping test true for both, better, perceptron cannot tell (1) | sign applied before the error; no division by ; "no mistakes" read as "minimum error" |
| Problem 2 | 5 | totals and , accuracy (1); recalls and precisions (1.5); per class and macro (1.5); class and the entries of the column of class (1) | rows and columns swapped; recall divided by the predicted total; macro of recall and precision |
| Problem 3 | 5 | values and distances (1.5); , , check (1.5); unit vector and give (1); correct sides, closest at (1) | no division by ; instead of ; bias forgotten |
| Total | 30 |