Predictive Hacks

SVD with Scikit Learn

We can apply the SVD decomposition in Scikit Learn. Let’s see how we can get the U the Sigma and the V matrices.

Example of SVD in Python 1
from sklearn.decomposition import TruncatedSVD
import numpy as np

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 =, Sigma)
# (U x Sigma) x V
U_Sigma_V = , V)

You can have a look at the SVD with SciPy.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s