Skip to content

Locally Linear Embedding manifold doesn't work with integer inputs #6033

Closed

Description

@Jezzamonn

An error occurs when you try to use manifold.LocallyLinearEmbedding with an integer array as the input if you have certain values of the method parameter. I'm running the latest version of scikit-learn (I got this error, updated through conda, and the error still occurs).

Traceback (most recent call last):
  File "C:/Users/jswanson/Downloads/plot_compare_methods.py", line 63, in <module>
    method=method).fit_transform(X)
  File "C:\Users\jswanson\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\manifold\locally_linear.py", line 652, in fit_transform
    self._fit_transform(X)
  File "C:\Users\jswanson\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\manifold\locally_linear.py", line 623, in _fit_transform
    random_state=random_state, reg=self.reg)
  File "C:\Users\jswanson\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\manifold\locally_linear.py", line 476, in locally_linear_embedding
    Xi -= Xi.mean(0)
TypeError: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

For some code that demonstrates the error, you can run the example here http://scikit-learn.org/stable/auto_examples/manifold/plot_compare_methods.html, but cast the data to int64 first. You can do this by inserting the following line below line 38

X = (1000 * X).astype('int64')

By glancing through similar issues, I think this is caused by an update to numpy.

I'll just work around the issue by casting my data to floats, but I thought I should still bring it up.

Activity

  1. soupault commented on Feb 4, 2016

    @soupault

    I confirm. Error is raised for both method='ltsa' (see @Jezzamonn log) and method='hessian' (see log below). Everything else works fine.

    Traceback (most recent call last):
      File "test.py", line 46, in <module>
        method=method).fit_transform(X)
      File "/usr/lib/python3.5/site-packages/sklearn/manifold/locally_linear.py", line 652, in fit_transform
        self._fit_transform(X)
      File "/usr/lib/python3.5/site-packages/sklearn/manifold/locally_linear.py", line 623, in _fit_transform
        random_state=random_state, reg=self.reg)
      File "/usr/lib/python3.5/site-packages/sklearn/manifold/locally_linear.py", line 327, in locally_linear_embedding
        Gi -= Gi.mean(0)
    TypeError: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
    
  2. added a commit that references this issue on Feb 4, 2016
    83483ca
  3. jakevdp commented on Feb 4, 2016

    @jakevdp
    Member

    I added a fix in #6282

  4. soupault commented on Feb 5, 2016

    @soupault

    @jakevdp thanks a lot!

  5. amueller commented on Oct 7, 2016

    @amueller
    Member

    Fixed in #6282

  6. added 2 commits that reference this issue on Oct 7, 2016
    c948319
    84e480f
  7. added a commit that references this issue on Jun 14, 2017
    6754578
  8. added a commit that references this issue on Aug 19, 2017
    896bcfd
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions