Homework 1
concept and math

- grayscale only: \(d = 15*15 = 225\)
- RGB: \(d = 15*15*3 = 675\)


- the error rate is \(P(error) = 0.25 * 0.5 + 0.25 * 0.8 + 0.25 * 0.8 + 0.25 * 0.9 = 0.75\)
- if the classifier always return same label, it should return A, and error rate is \(0.5\)

P1 = (0.5, 0.5), P2 = (0.5, 1.5)
- the label point for \(\begin{bmatrix}0.5 \\ 0.5\end{bmatrix}\) is 2
-
- \(\sqrt{1 + 0} = 1\) < \(\sqrt{1 + 1} = \sqrt{2}\), so the label \(\begin{bmatrix}0.5 \\ 0.5\end{bmatrix}\) is closer, lebel = 2
- the label \(\begin{bmatrix}0.5 \\ 1.5\end{bmatrix}\) is closer, lebel = 1
- it will never predict class 3
- for a point (x,y), \(l(P_1)^2 = (x - 0.5)^2 + (y - 0.5)^2\), \(l(P_2)^2 = (x - 0.5)^2 + (y - 1.5)^2\), so \(P_1 < P_2\) when \(y < 1\), \(P_1 > P_2\) when \(y > 1\), and \(P_1 = P_2\) when \(y = 1\). So the decision boundary is the line \(y = 1\). therefore, the error rate is 0.5

the point is located at (3.5, 4.5) the most close point is (4,4), with label star the next close point is (2,4), square the third close point is (4,6), square 4th close point is (2,6), star 5th close point is (4,2), square
- 1-NN: star
- 3-NN: square
- 5-NN: square
coding

-
the test point 100:

the nearest neighbor image:

the prediction is successful
-
here is the confusion matrix:
[[ 99 0 0 0 0 1 0 0 0 0]
[ 0 100 0 0 0 0 0 0 0 0]
[ 0 1 94 1 0 0 0 3 1 0]
[ 0 0 2 91 2 4 0 0 1 0]
[ 0 0 0 0 97 0 0 0 0 3]
[ 1 0 0 0 0 98 0 0 0 1]
[ 0 0 0 0 0 1 99 0 0 0]
[ 0 4 0 0 1 0 0 94 0 1]
[ 2 0 1 1 1 0 1 1 92 1]
[ 1 1 1 1 2 1 0 3 0 90]]
the most accurate class is 1, the lest accurate class is 9
- the average grayscale for each images is:
[45.12679672241211, 19.94109535217285, 38.56541061401367, 36.835243225097656, 31.114784240722656, 35.164283752441406, 36.48517990112305, 29.564733505249023, 39.26533126831055, 32.149410247802734]
here is the image of the average grayscale for each digit:












-
error rate for l1 is: 0.21666666666666667, error rate for l2 is: 0.23333333333333334
-
confusion matrix for l1 is: [[14. 0. 2.] [ 9. 9. 0.] [ 1. 1. 24.]] confusion matrix for l2 is: [[12. 1. 3.] [ 9. 9. 0.] [ 1. 0. 25.]]