Get U, Sigma, V* matrix from Truncated SVD in scikit-learn
Looking into the source via the link you provided, TruncatedSVD
is basically a wrapper around sklearn.utils.extmath.randomized_svd; you can manually call this yourself like this:
from sklearn.utils.extmath import randomized_svd
U, Sigma, VT = randomized_svd(X,
n_components=15,
n_iter=5,
random_state=None)
One can use scipy.sparse.svds (for dense matrices you can use svd).
import numpy as np
from scipy.sparse.linalg import svds
matrix = np.random.random((20, 20))
num_components = 2
u, s, v = svds(matrix, k=num_components)
X = u.dot(np.diag(s)) # output of TruncatedSVD
If you're working with really big sparse matrices (perhaps your working with natural text), even scipy.sparse.svds
might blow up your computer's RAM. In such cases, consider the sparsesvd package which uses SVDLIBC, and what gensim
uses under-the-hood.
import numpy as np
from sparsesvd import sparsesvd
X = np.random.random((30, 30))
ut, s, vt = sparsesvd(X.tocsc(), k)
projected = (X * ut.T)/s