Predictive Hacks

Example of SVD in Python

It is common to use SVD for recommendation systems. Let’s say that we have a data frame called user_ratings that can be the score of each user to each movie.

from scipy.sparse.linalg import svds
import numpy as np

# Decompose the matrix
U, sigma, Vt = svds(user_ratings_centered, k=6)

# Convert sigma into a diagonal matrix
sigma = np.diag(sigma)

# U x Sigma
U_x_Sigma =, sigma)

# (U x Sigma) x Vt
U_Sigma_Vt = , Vt)

The U_Sigma_Vt is the product of the three decomposed matrices

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