Description
Describe the bug
I tried to implement T-distributed Stochastic Neighbor Embedding using sklearn.manifold.TSNE
through the example on the website with scikit-learn version is 0.23.2 and 0.22.2.post1. I believe it is a typing problem...
Steps/Code to Reproduce
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)
print(X_embedded.shape)
Expected Results
Should display (4, 2)
Actual Results
`UFuncTypeError Traceback (most recent call last)
in ()
2 from sklearn.manifold import TSNE
3 X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
----> 4 X_embedded = TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(X)
5 print(X_embedded.shape)
3 frames
/usr/local/lib/python3.7/dist-packages/sklearn/manifold/t_sne.py in fit_transform(self, X, y)
884 Embedding of the training data in low-dimensional space.
885 """
--> 886 embedding = self.fit(X)
887 self.embedding = embedding
888 return self.embedding
/usr/local/lib/python3.7/dist-packages/sklearn/manifold/_t_sne.py in _fit(self, X, skip_num_points)
796 X_embedded=X_embedded,
797 neighbors=neighbors_nn,
--> 798 skip_num_points=skip_num_points)
799
800 def _tsne(self, P, degrees_of_freedom, n_samples, X_embedded,
/usr/local/lib/python3.7/dist-packages/sklearn/manifold/_t_sne.py in _tsne(self, P, degrees_of_freedom, n_samples, X_embedded, neighbors, skip_num_points)
835 P *= self.early_exaggeration
836 params, kl_divergence, it = _gradient_descent(obj_func, params,
--> 837 **opt_args)
838 if self.verbose:
839 print("[t-SNE] KL divergence after %d iterations with early "
/usr/local/lib/python3.7/dist-packages/sklearn/manifold/_t_sne.py in _gradient_descent(objective, p0, it, n_iter, n_iter_check, n_iter_without_progress, momentum, learning_rate, min_gain, min_grad_norm, verbose, args, kwargs)
365 np.clip(gains, min_gain, np.inf, out=gains)
366 grad *= gains
--> 367 update = momentum * update - learning_rate * grad
368 p += update
369
UFuncTypeError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')`
Versions
System:
python: 3.7.12 (default, Sep 10 2021, 00:21:48) [GCC 7.5.0]
executable: /usr/bin/python3
machine: Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
Python dependencies:
pip: 21.1.3
setuptools: 57.4.0
sklearn: 0.22.2.post1
numpy: 1.19.5
scipy: 1.4.1
Cython: 0.29.24
pandas: 1.1.5
matplotlib: 3.2.2
joblib: 1.0.1
Built with OpenMP: True