Skip to content

Improve TruncatedSVD.transform on sparse csc matrices #16828

@lorentzenchr

Description

@lorentzenchr

Describe the workflow you want to enable

import scipy.sparse as ss
from sklearn.decomposition import TruncatedSVD

X = ss.random(1000, 100, format='csc')
tsvd = TruncatedSVD().fit(X)

tsvd.transform(X)

Currently, in the last line, transform(X) will first convert X from csc to csr and then apply a dot product. I think this conversion is unnecessary, costs additional time, and one should better rely on scipy.sparse (or safe_sparse_dot) to convert if necessary.

Describe your proposed solution

Allow csc in

X = check_array(X, accept_sparse='csr')

Additional context

A PR with a benchmark result might be nice.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions