8000 sklearn.manifold.TSNE, ValueError: Buffer dtype mismatch, expected 'float_t' but got 'float' · Issue #4124 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div class="clearfix new-discussion-timeline js-check-all-container container-xl px-3 px-md-4 px-lg-5 mt-4" data-pjax="" data-turbo-frame="">

sklearn.manifold.TSNE, ValueError: Buffer dtype mismatch, expected 'float_t' but got 'float' #4124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
h10r opened this issue Jan 19, 2015 · 6 comments
Labels
Milestone

Comments

@h10r
Copy link
Contributor
h10r commented Jan 19, 2015

Thank you so much for adding sklearn.manifold.TSNE, I'm very excited that it's now part of sklearn! However, when I try using it, I get the following error message (both with 0.15.2 and 0.16):

Traceback (most recent call last):
File "main.py", line 104, in <module>
vectors_tsne = do_tsne_on_vectors( vectors_in_file )
File "main.py", line 56, in do_tsne_on_vectors
return tsne.fit_transform( vectors )
File "(...)/sklearn/manifold/t_sne.py", line 519, in fit_transform
self._fit(X)
File "(...)/sklearn/manifold/t_sne.py", line 444, in _fit
P = _joint_probabilities(distances, self.perplexity, self.verbose)
File "(...)/sklearn/manifold/t_sne.py", line 51, in _joint_probabilities
distances, desired_perplexity, verbose)
File "_utils.pyx", line 14, in sklearn.manifold._utils._binary_search_perplexity (sklearn/manifold/_utils.c:2023)
ValueError: Buffer dtype mismatch, expected 'float_t' but got 'float'

To fix this, I did:

vectors = np.asfarray( vectors, dtype='float' )

which seems to work for me.

My input is a list of vectors I get from gensim.models.word2vec.

Kind regards and thanks for the great library!
Hendrik

@amueller
Copy link
Member

Hi. Thanks for the report.
Can you please provide the code that you are using, type and dtype of your input (vectors)?
What OS are you on (and 32bit or 64bit?)

@h10r
Copy link
Contributor Author
h10r commented Jan 20, 2015

Hi Andreas,

I'm on Mac OS X 10.9.5 (13F34) with 64 bit.

The code

def do_tsne_on_vectors( vectors ):
    tsne_array = np.array( vectors )
    tsne = TSNE(n_components=2, random_state=0)
    return tsne.fit_transform( vectors ) 

When I do tsne_array.dtype, I get float32 and <type 'numpy.ndarray'>.

The vector just contains numbers:

[  1.84206292e-02   1.06022261e-01  -1.34022012e-01  -6.32563373e-03
   7.17194155e-02   3.79017629e-02  -2.69094426e-02  -1.99426636e-01
  -1.18101127e-02   2.96421014e-02  -1.06844241e-02  -1.01331301e-01 ...

SKlearn version:

VERSION
    0.15.2

Kind regards,
Hendrik

@amueller amueller added the Bug label Jan 20, 2015
@amueller amueller added this to the 0.16 milestone Jan 20, 2015
@amueller
Copy link
Member

Thanks, I can reproduce. That is a bug :-/

@h10r
Copy link
Contributor Author
h10r commented Jan 20, 2015

Ah, too bad. As mentioned, vectors = np.asfarray( vectors, dtype='float' ) is a possible workaround that works for me.

Again, thanks a lot for your work and this great library!
All the best from Stockholm,
Hendrik

@amueller
Copy link
Member

Yeah, the fix here is pretty simple. I just have to come up with a way to test that this problem doesn't show up anywhere in the library ever again ;)

@amueller
Copy link
Member

Fixed in #4136.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0