Skip to content

TruncatedSVD.transform does not check if fitted #16806

Closed

Description

@lorentzenchr

Describe the bug

TruncatedSVD.transform does not call check_is_fitted(self).

Steps/Code to Reproduce

numpy as np
from sklearn.decomposition import TruncatedSVD

tsvd = TruncatedSVD()
X = np.arange(6).reshape((3,2))
tsvd.transform(X)

Expected Results

NotFittedError

Actual Results

AttributeError: 'TruncatedSVD' object has no attribute 'components_'

Further Notes

Is there a reason, why TruncatedSVD.transform calls X = check_array(X, accept_sparse='csr'), i.e. converts to CSR-format?

Versions

sklearn: 0.23.dev0

Activity

  1. rth commented on Mar 30, 2020

    @rth
    Member

    AttributeError: 'TruncatedSVD' object has no attribute 'components_'

    Well I wouldn't say it's a bug, more of an error message/exception type that can be improved. PR to add check_is_fitted welcome.

    I don't think we really check in common tests that NotFittedError is raised on unfited estimators? Otherwise they wouldn't have passed here.

    Is there a reason, why TruncatedSVD.transform calls X = check_array(X, accept_sparse='csr'), i.e. converts to CSR-format?

    Maybe because X @ self.components_.T is then faster? Not sure. Added a long time ago in #3447 so might be worth re-evaluating..

  2. alexitkes commented on Mar 31, 2020

    @alexitkes
    Contributor

    PR to add check_is_fitted welcome.

    I want to do it. The patch I made seems to work already, but I also want to add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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