Skip to content

Type Error thrown for Isomap Embedding when calling fit with scipy.sparse.csr.csr_matrix #7426

Closed

Description

@garretthoffman

Description

Type Error thrown for Isomap Embedding when calling fit when passing in sparse matrix

Steps/Code to Reproduce

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.preprocessing import Normalizer
from sklearn.manifold import Isomap

docs = ['Help I have a bug!' for x in range(1000)]

count_vectorizer = CountVectorizer(analyzer = 'word', ngram_range = (1,2), stop_words = 'english',
                                   lowercase= True, max_features = None, binary = False)

normalizer = Normalizer(norm='l2')

doc_vecs = normalizer.fit_transform(count_vectorizer.fit_transform(docs))

isomap = Isomap(n_neighbors=5, 
                n_components=2, 
                eigen_solver='auto', 
                tol=0, 
                max_iter=None, 
                path_method='auto', 
                neighbors_algorithm='auto')

isomap.fit(doc_vecs)

Expected Results

fit embedding

Actual Results

TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.

Versions

Darwin-15.6.0-x86_64-i386-64bit
('Python', '2.7.12 |Anaconda custom (x86_64)| (default, Jul  2 2016, 17:43:17) \n[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)]')
('NumPy', '1.11.1')
('SciPy', '0.17.1')
('Scikit-Learn', '0.17.1')

Activity

  1. amueller commented on Sep 14, 2016

    @amueller
    Member

    I'm not sure if it's an issue in the input validation or the docstring. Can you try to change the check_array in Isomap.fit to accept_sparse="csr"?

  2. jnothman commented on Sep 14, 2016

    @jnothman
    Member

    At a glance it looks like it should support sparse and it's a problem with
    the use of check_array.

    On 15 September 2016 at 09:04, Andreas Mueller [email protected]
    wrote:

    I'm not sure if it's an issue in the input validation or the docstring.
    Can you try to change the check_array in Isomap.fit to accept_sparse="csr"
    ?

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly, view it on GitHub
    #7426 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAEz63K2REo1BZGbcTO-p5EpMH_lbIhXks5qqH2JgaJpZM4J9TGi
    .

  3. garretthoffman commented on Sep 15, 2016

    @garretthoffman
    Author

    Yea, changing the check_array in the _fit_transform method to include accept_sparse="csr" allows the example above to run successfully. With this change the fit_transform method results in the expected (1000, 2) ndarray.

  4. jnothman commented on Sep 15, 2016

    @jnothman
    Member

    A PR including a test are very welcome.

    On 15 September 2016 at 10:09, Garrett Hoffman [email protected]
    wrote:

    Yea, changing the check_array in the _fit_transform method to include
    accept_sparse="csr" allows the example above to run successfully. With
    this change the fit_transform method results in the expected (1000, 8)
    ndarray.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #7426 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAEz63OfxMtIHkXC4oC_YNm1JTU8g7_-ks5qqIy0gaJpZM4J9TGi
    .

  5. jnothman commented on Sep 15, 2016

    @jnothman
    Member

    *is

    On 15 September 2016 at 10:10, Joel Nothman [email protected] wrote:

    A PR including a test are very welcome.

    On 15 September 2016 at 10:09, Garrett Hoffman [email protected]
    wrote:

    Yea, changing the check_array in the _fit_transform method to include
    accept_sparse="csr" allows the example above to run successfully. With
    this change the fit_transform method results in the expected (1000, 8)
    ndarray.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #7426 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAEz63OfxMtIHkXC4oC_YNm1JTU8g7_-ks5qqIy0gaJpZM4J9TGi
    .

  6. garretthoffman commented on Sep 15, 2016

    @garretthoffman
    Author

    no problem, I can handle that

  7. added
    Easy
    on Oct 13, 2016
  8. amueller commented on Oct 13, 2016

    @amueller
    Member

    @garretthoffman have you looked into this?

  9. garretthoffman commented on Oct 13, 2016

    @garretthoffman
    Author

    I have the test code with the fix but got caught up in a bunch of stuff at work and Pushed the fix yet. I can get to this this weekend.

  10. amueller commented on Oct 14, 2016

    @amueller
    Member

    much appreciated @garretthoffman and no rush :)

  11. dalmia commented on Nov 9, 2016

    @dalmia
    Contributor

    Hi @garretthoffman, are you still working on this?

  12. garretthoffman commented on Nov 9, 2016

    @garretthoffman
    Author

    Yes - things have gotten busy again but I will actually be able to get to this this weekend.

  13. TomDLT commented on Sep 18, 2019

    @TomDLT
    Member

    Fixed in #10482

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Easy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions