程序代写 CSC311, Fall 2021

Linear Algebra Review Problems
CSC311, Fall 2021
Commute times
1. Suppose we are trying to predict commute times based on the distance traveled and day of the week. We have the following data:

Copyright By PowCoder代写 加微信 powcoder

dist day commute time 2.71 25 3.41 31 5.22 45 1.03 16 2.85 22
(a) We estimate that commute times have the following relationship: commute time = 10 × dist − day
What are our predicted commute times? How can we use matrices to compute this quickly?
(Solution: Let X denote our matrix of features i.e.
2.7 1 3.4 1  . . . 
2.8 5 10
we compute Xw to get our predictions. Note that we often append an additional column of 1s (a bias term) so that our linear model is not constrained to passing through the origin.
In numpy, we use np.dot(X, w).
(b) Suppose we want to calculate the average mean squared error between the predictions and the ground truth. How do we do this?
(Solution: Letting y denote the vector of ground truth commute times, we compute
n1|Xw−y|2 = 15(Xw−y)T(Xw−y)
We can do this in code with np.mean((np.dot(X, w) − y) ** 2) )

Misc problems
1. Are the following set of vectors linearly independent or dependent? Justify. 1 2 3
(Solution: They are linearly dependent, since we have 3 vectors in 2 dimensions.)
7 2 2. Compute the projection of the vector a = 2 onto the direction b = 1 .
(Solution: From geometry, the length of the projected vector is |a| cos θ, where θ is the angle between the two vectors. We multiply this by the unit vector in the direction:
b a · b b a · b 16 2 6.4 (|a|cosθ)|b| =|a||a||b||b| = b·bb= 5 1 = 3.2

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com