Bird
0
0

You have a sparse matrix A of shape (20000, 10000) representing user-item interactions. You want to extract 100 latent features using svds. Which approach is best?

hard📝 Application Q8 of 15
SciPy - Sparse Linear Algebra
You have a sparse matrix A of shape (20000, 10000) representing user-item interactions. You want to extract 100 latent features using svds. Which approach is best?
AConvert <code>A</code> to a dense array and use <code>np.linalg.svd</code>
BConvert <code>A</code> to a sparse format and call <code>svds(A, k=100)</code>
CUse <code>svds</code> with <code>k=5000</code> to get more features
DUse <code>svds</code> without specifying <code>k</code> to get all singular values
Step-by-Step Solution
Solution:
  1. Step 1: Confirm matrix format

    Ensure A is in a sparse format (e.g., CSR) for efficient computation.
  2. Step 2: Set k parameter

    Set k=100 to extract 100 latent features.
  3. Step 3: Avoid dense conversion

    Converting to dense is memory-intensive and inefficient for large matrices.
  4. Step 4: Avoid invalid k values

    k must be less than min(A.shape), so 5000 is invalid here.
  5. Final Answer:

    A -> Option B
  6. Quick Check:

    Use sparse format and valid k for svds [OK]
Quick Trick: Keep matrix sparse and k < min(shape) [OK]
Common Mistakes:
  • Converting large sparse matrices to dense
  • Setting k larger than minimum matrix dimension
  • Not specifying k and expecting full SVD

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes