{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6665","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6665/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6665/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6665/events","html_url":"https://github.com/scikit-learn/scikit-learn/issues/6665","id":148639142,"number":6665,"title":"t-SNE fails with array must not contain infs or NaNs","user":{"login":"joelkuiper","id":971293,"avatar_url":"https://avatars.githubusercontent.com/u/971293?v=3","gravatar_id":"","url":"https://api.github.com/users/joelkuiper","html_url":"https://github.com/joelkuiper","followers_url":"https://api.github.com/users/joelkuiper/followers","following_url":"https://api.github.com/users/joelkuiper/following{/other_user}","gists_url":"https://api.github.com/users/joelkuiper/gists{/gist_id}","starred_url":"https://api.github.com/users/joelkuiper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelkuiper/subscriptions","organizations_url":"https://api.github.com/users/joelkuiper/orgs","repos_url":"https://api.github.com/users/joelkuiper/repos","events_url":"https://api.github.com/users/joelkuiper/events{/privacy}","received_events_url":"https://api.github.com/users/joelkuiper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-04-15T11:45:35Z","updated_at":"2016-05-11T05:29:51Z","closed_at":null,"body":"```\r\nDarwin-15.0.0-x86_64-i386-64bit\r\n('Python', '2.7.11 |Anaconda custom (x86_64)| (default, Dec  6 2015, 18:57:58) \\n[GCC 4.2.1 (Apple Inc. build 5577)]')\r\n('NumPy', '1.11.0')\r\n('SciPy', '0.17.0')\r\n('Scikit-Learn', '0.17.1')\r\n```\r\n\r\nWhen trying to run a t-SNE \r\n```\r\nproj = TSNE().fit_transform(X)\r\nValueError: array must not contain infs or NaNs\r\n```\r\n\r\nHowever \r\n```\r\nnp.isfinite(X).all() # True \r\nnp.isnan(X).all() # False\r\nnp.isinf(X).all() # False\r\n```\r\n\r\nFull Stack Trace: \r\n```\r\n\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-16-c25f35fd042c> in <module>()\r\n----> 1 plot(X, y)\r\n\r\n<ipython-input-1-72bdb7124d13> in plot(X, y)\r\n     74 \r\n     75 def plot(X, y):\r\n---> 76     proj = TSNE().fit_transform(X)\r\n     77     scatter(proj, y)\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/sklearn/manifold/t_sne.pyc in fit_transform(self, X, y)\r\n    864             Embedding of the training data in low-dimensional space.\r\n    865         \"\"\"\r\n--> 866         embedding = self._fit(X)\r\n    867         self.embedding_ = embedding\r\n    868         return self.embedding_\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/sklearn/manifold/t_sne.pyc in _fit(self, X, skip_num_points)\r\n    775                           X_embedded=X_embedded,\r\n    776                           neighbors=neighbors_nn,\r\n--> 777                           skip_num_points=skip_num_points)\r\n    778 \r\n    779     def _tsne(self, P, degrees_of_freedom, n_samples, random_state,\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/sklearn/manifold/t_sne.pyc in _tsne(self, P, degrees_of_freedom, n_samples, random_state, X_embedded, neighbors, skip_num_points)\r\n    830         opt_args['momentum'] = 0.8\r\n    831         opt_args['it'] = it + 1\r\n--> 832         params, error, it = _gradient_descent(obj_func, params, **opt_args)\r\n    833         if self.verbose:\r\n    834             print(\"[t-SNE] Error after %d iterations with early \"\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/sklearn/manifold/t_sne.pyc in _gradient_descent(objective, p0, it, n_iter, objective_error, n_iter_check, n_iter_without_progress, momentum, learning_rate, min_gain, min_grad_norm, min_error_diff, verbose, args, kwargs)\r\n    385     for i in range(it, n_iter):\r\n    386         new_error, grad = objective(p, *args, **kwargs)\r\n--> 387         grad_norm = linalg.norm(grad)\r\n    388 \r\n    389         inc = update * grad >= 0.0\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/scipy/linalg/misc.pyc in norm(a, ord, axis, keepdims)\r\n    127     \"\"\"\r\n    128     # Differs from numpy only in non-finite handling and the use of blas.\r\n--> 129     a = np.asarray_chkfinite(a)\r\n    130 \r\n    131     # Only use optimized norms if axis and keepdims are not specified.\r\n\r\n/Users/joelkuiper/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.pyc in asarray_chkfinite(a, dtype, order)\r\n   1020     if a.dtype.char in typecodes['AllFloat'] and not np.isfinite(a).all():\r\n   1021         raise ValueError(\r\n-> 1022             \"array must not contain infs or NaNs\")\r\n   1023     return a\r\n   1024 \r\n\r\nValueError: array must not contain infs or NaNs\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/218365487","html_url":"https://github.com/scikit-learn/scikit-learn/issues/6665#issuecomment-218365487","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6665","id":218365487,"user":{"login":"ivan-krukov","id":1881263,"avatar_url":"https://avatars.githubusercontent.com/u/1881263?v=3","gravatar_id":"","url":"https://api.github.com/users/ivan-krukov","html_url":"https://github.com/ivan-krukov","followers_url":"https://api.github.com/users/ivan-krukov/followers","following_url":"https://api.github.com/users/ivan-krukov/following{/other_user}","gists_url":"https://api.github.com/users/ivan-krukov/gists{/gist_id}","starred_url":"https://api.github.com/users/ivan-krukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivan-krukov/subscriptions","organizations_url":"https://api.github.com/users/ivan-krukov/orgs","repos_url":"https://api.github.com/users/ivan-krukov/repos","events_url":"https://api.github.com/users/ivan-krukov/events{/privacy}","received_events_url":"https://api.github.com/users/ivan-krukov/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T05:29:51Z","updated_at":"2016-05-11T05:29:51Z","body":"Reproduced for 3.5 with anaconda under OS X El Capitan.\r\n```Darwin 15.4.0\r\nPython 3.5.1 :: Anaconda custom (x86_64)\r\nnumpy 1.10.4\r\nscipy 0.17.0\r\nscikit-learn 0.17.1\r\n```\r\n\r\n```python\r\nimport random\r\nfrom sklearn.manifold import TSNE\r\nrandom.seed(1)\r\na = np.random.uniform(size=(100,20))\r\nTSNE(n_components=2).fit_transform(a)\r\n```"}}