简体   繁体   中英

sklearn.manifold.TSNE TypeError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32'))...)

I have run the sklearn.manifold.TSNE example code from the sklearn documentation, but I got the error described in the questions' title.

I have already tried updating my sklearn version to the latest one (by !pip install -U scikit-learn ) (scikit-learn=1.0.1). However, the problem is still there.

Does anyone know how to fix it?

  • python = 3.7.12
  • sklearn= 1.0.1

Example code:

import numpy as np
from sklearn.manifold import TSNE
X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
X_embedded = TSNE(n_components=2, learning_rate='auto',
              init='random').fit_transform(X)
X_embedded.shape

The error line happened in:

X_embedded = TSNE(n_components=2, learning_rate='auto',
              init='random').fit_transform(X)

Error message:

UFuncTypeError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')

Delete learning_rate='auto' solved my problem.

Thanks @FlaviaGiammarino comment!!

The problem is with 'auto' value of learning rate. Looks like a bug in this version of sklearn, cause all of string values are not acceptable for this parameter; With float value for example learning_rate = 100 , there would be no problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM