8000 FIX Set TSNE's internal PCA to always use numpy as output (#25370) · scikit-learn/scikit-learn@78efbee · GitHub
[go: up one dir, main page]

Skip to content

Commit 78efbee

Browse files
betatimglemaitreTomDLT
authored andcommitted
FIX Set TSNE's internal PCA to always use numpy as output (#25370)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Tom Dupré la Tour <tom.duprelatour.10@gmail.com>
1 parent c6da8a0 commit 78efbee

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/whats_new/v1.2.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Changelog
4646
`verbose` parameter set to a value greater than 0.
4747
:pr:`25250` by :user:`Jérémie Du Boisberranger <jeremiedbb>`.
4848

49+
:mod:`sklearn.manifold`
50+
.......................
51+
52+
- |Fix| :class:`manifold.TSNE` now works correctly when output type is
53+
set to pandas :pr:`25370` by :user:`Tim Head <betatim>`.
54+
55+
4956
:mod:`sklearn.preprocessing`
5057
............................
5158

sklearn/manifold/_t_sne.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,8 @@ def _fit(self, X, skip_num_points=0):
990990
svd_solver="randomized",
991991
random_state=random_state,
992992
)
993+
# Always output a numpy array, no matter what is configured globally
994+
pca.set_output(transform="default")
993995
X_embedded = pca.fit_transform(X).astype(np.float32, copy=False)
994996
# PCA is rescaled so that PC1 has standard deviation 1e-4 which is
995997
# the default value for random initialization. See issue #18018.

sklearn/manifold/tests/test_t_sne.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import scipy.sparse as sp
66
import pytest
77

8+
from sklearn import config_context
89
from sklearn.neighbors import NearestNeighbors
910
from sklearn.neighbors import kneighbors_graph
1011
from sklearn.exceptions import EfficiencyWarning
@@ -1191,3 +1192,14 @@ def test_tsne_perplexity_validation(perplexity):
11911192
msg = "perplexity must be less than n_samples"
11921193
with pytest.raises(ValueError, match=msg):
11931194
est.fit_transform(X)
1195+
1196+
1197+
def test_tsne_works_with_pandas_output():
1198+
"""Make sure that TSNE works when the output is set to "pandas".
1199+
1200+
Non-regression test for gh-25365.
1201+
"""
1202+
pytest.importorskip("pandas")
1203+
with config_context(transform_output="pandas"):
1204+
arr = np.arange(35 * 4).reshape(35, 4)
1205+
TSNE(n_components=2).fit_transform(arr)

0 commit comments

Comments
 (0)
0