sparse matrix svd in python
Asked Answered
S

4

6

Does anyone know how to perform svd operation on a sparse matrix in python? It seems that there is no such functionality provided in scipy.sparse.linalg.

Squat answered 13/7, 2010 at 7:0 Comment(2)
Seems you're out of luck and have to wrap a Fortran library such as PROPACK yourself. Or ask the Scipy developers to add PROPACK-based SVD in an upcoming version.Boxer
There is also the SVDPACK library which has C and C++ versions/interfaces.Boxer
V
3

You can use the Divisi library to accomplish this; from the home page:

  • It is a library written in Python, using a C library (SVDLIBC) to perform the sparse SVD operation using the Lanczos algorithm. Other mathematical computations are performed by NumPy.
Valonia answered 13/7, 2010 at 23:14 Comment(0)
T
4

Sounds like sparsesvd is what you're looking for! SVDLIBC efficiently wrapped in Python (no extra data copies made in RAM).

Simply run "easy_install sparsesvd" to install.

Trautman answered 22/10, 2010 at 19:3 Comment(0)
V
3

You can use the Divisi library to accomplish this; from the home page:

  • It is a library written in Python, using a C library (SVDLIBC) to perform the sparse SVD operation using the Lanczos algorithm. Other mathematical computations are performed by NumPy.
Valonia answered 13/7, 2010 at 23:14 Comment(0)
H
3

You can try scipy.sparse.linalg.svd, although the documentation is still a work-in-progress and thus rather laconic.

Heidt answered 30/9, 2010 at 21:2 Comment(1)
You probably mean the procedure called "svds". I tried it, but wasn't happy with the results myself...Sotted
J
3

A simple example using python-recsys library:

from recsys.algorithm.factorize import SVD

svd = SVD()
svd.load_data(dataset)
svd.compute(k=100, mean_center=True)

ITEMID1 = 1  # Toy Story
svd.similar(ITEMID1)
# Returns:
# [(1,    1.0),                 # Toy Story
#  (3114, 0.87060391051018071), # Toy Story 2
#  (2355, 0.67706936677315799), # A bug's life
#  (588,  0.5807351496754426),  # Aladdin
#  (595,  0.46031829709743477), # Beauty and the Beast
#  (1907, 0.44589398718134365), # Mulan
#  (364,  0.42908159895574161), # The Lion King
#  (2081, 0.42566581277820803), # The Little Mermaid
#  (3396, 0.42474056361935913), # The Muppet Movie
#  (2761, 0.40439361857585354)] # The Iron Giant

ITEMID2 = 2355 # A bug's life
svd.similarity(ITEMID1, ITEMID2)
# 0.67706936677315799
Junna answered 10/4, 2012 at 19:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.