We can apply the SVD decomposition in Scikit Learn. Let’s see how we can get the U the Sigma and the V matrices.
from sklearn.decomposition import TruncatedSVD import numpy as np np.random.seed(0) X = np.random.rand(100, 100) # four components svd = TruncatedSVD(n_components=4, n_iter=10, random_state=5) U = svd.fit_transform(X) Sigma = np.diag(svd.singular_values_) V = svd.components_
In case we want to do the matrix multiplication, we can do it as follows:
# in case we want to do the multiplication # U x Sigma U_x_Sigma = np.dot(U, Sigma) # (U x Sigma) x V U_Sigma_V = np.dot(U_x_Sigma , V)
You can have a look at the SVD with SciPy.