Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
X = np.array([[-2, 0], [0, 1], [2, 0], [0, -1]])
Xc = X - X.mean(axis=0)
_, s, Vt = np.linalg.svd(Xc)
print(round(s[0] ** 2 / (s ** 2).sum(), 2))0.8
- Expecting
0.67, the value ofs[0] / s.sum(): variance grows with the square ofs, and the squares are8and2, so the share is8 / 10 = 0.8. - Expecting
0.2:svdreturnssin decreasing order, sos[0]belongs to the component with the largest variance.
- What share of the variance does the second component carry here?
- Why must the data be centered before calling
np.linalg.svd?