November 2017
Intermediate to advanced
374 pages
10h 19m
English
Now that we've walked through how, is performed in scikit-learn, let's look at how we can use only SciPy, and learn a bit in the process.
First, we need to use SciPy's linalg to perform SVD:
from scipy.linalg import svdimport numpy as npD = np.array([[1, 2], [1, 3], [1, 4]])Darray([[1, 2],[1, 3],[1, 4]])U, S, V = svd(D, full_matrices=False)U.shape, S.shape, V.shape((3L, 2L), (2L,), (2L, 2L))
We can reconstruct the original matrix D to confirm U, S, and V as a decomposition:
np.dot(U.dot(np.diag(S)), V)array([[1, 2],[1, 3],[1, 4]])
The matrix that is actually returned by truncated SVD is the dot product of the U and S matrices. If we want to simulate the truncation, we will drop the smallest singular values and the corresponding ...
Read now
Unlock full access