sparse matrix svd in python

后端 未结 4 2120
生来不讨喜
生来不讨喜 2020-12-29 16:21

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.

4条回答
  •  长情又很酷
    2020-12-29 17:01

    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
    

提交回复
热议问题