CS209 Practice Problems 1 ML
CS209 Practice Problems 1 ML
Notes: (1) These questions require thought, but do not require long answers. Please be as
Note: These
concise questions(2)
as possible. are given
If youforhave
yourapractice
questionandabout
will notthis
be evaluated.
homework, Trywe
to solve all questions.
encourage you to post
your question on our Piazza forum, at https://piazza.com/stanford/fall2018/cs229. (3) If
you missed the first lecture or are unfamiliar with the collaboration or honor code policy, please
read the policy on Handout #1 (available from the course website) before starting work. (4)
This specific homework is not graded, but we encourage you to solve each of the problems to
brush up on your linear algebra. Some of them may even be useful for subsequent problem sets.
It also serves as your introduction to using Gradescope for submissions.
2.Q.2
[0 points] Positive definite matrices
A matrix A ∈ Rn×n is positive semi-definite (PSD), denoted A 0, if A = AT and xT Ax ≥ 0
for all x ∈ Rn . A matrix A is positive definite, denoted A 0, if A = AT and xT Ax > 0 for
all x 6= 0, that is, all non-zero vectors x. The simplest example of a positive definite matrix is
the identity I (the diagonal matrix with 1s on the diagonal and 0s elsewhere), which satisfies
2 Pn
xT Ix = kxk2 = i=1 x2i .
CS229 Problem Set #0 2
(a) Suppose that the matrix A ∈ Rn×n is diagonalizable, that is, A = T ΛT −1 for an invertible
matrix T ∈ Rn×n , where Λ = diag(λ1 , . . . , λn ) is diagonal. Use the notation t(i) for the
columns of T , so that T = [t(1) · · · t(n) ], where t(i) ∈ Rn . Show that At(i) = λi t(i) , so
that the eigenvalues/eigenvector pairs of A are (t(i) , λi ).
A matrix U ∈ Rn×n is orthogonal if U T U = I. The spectral theorem, perhaps one of the most
important theorems in linear algebra, states that if A ∈ Rn×n is symetric, that is, A = AT ,
then A is diagonalizable by a real orthogonal matrix. That is, there are a diagonal matrix
Λ ∈ Rn×n and orthogonal matrix U ∈ Rn×n such that U T AU = Λ, or, equivalently,
A = U ΛU T .
Q.4 Let λi = λi (A) denote the ith eigenvalue of A.
(b) Let A be symmetric. Show that if U = [u(1) · · · u(n) ] is orthogonal, where u(i) ∈
Rn and A = U ΛU T , then u(i) is an eigenvector of A and Au(i) = λi u(i) , where Λ =
diag(λ1 , . . . , λn ).
(c) Show that if A is PSD, then λi (A) ≥ 0 for each i.
Q.5
Q.6
Q.7
iv. Draw the full Decision Tree that would be learned for this dataset.
No need to show detailed calculations
Q9. Consider f(x) = x^2 + 3x + 2 . Calculate f(1), f(2), f(3), f(4) and f(5) using the definition of f(x). Calculate f(2.5) using
KNN. Use K as 1, 2 and 3. Repeat the process for f(0). Compare with the values of f(2.5) and f(0) from the
function and explain which value of K gives the optimal result. Does this algorithm perform better for f(0) or f(2.5)
-x + y = 10
2x - y = 5
x - 2y = 20
Find the least squares solution to the above equations using any two techniques learnt in class.