Skip to content

Commit b0e4630

Browse files
authored
MAINT Clean up deprecated square_distances in TSNE for 1.3 (scikit-learn#26483)
1 parent 2182544 commit b0e4630

File tree

2 files changed

+2
-60
lines changed

2 files changed

+2
-60
lines changed

sklearn/manifold/_t_sne.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# * Fast Optimization for t-SNE:
99
# https://cseweb.ucsd.edu/~lvdmaaten/workshops/nips2010/papers/vandermaaten.pdf
1010

11-
import warnings
1211
from time import time
1312
import numpy as np
1413
from scipy import linalg
@@ -21,7 +20,7 @@
2120
from ..utils import check_random_state
2221
from ..utils._openmp_helpers import _openmp_effective_n_threads
2322
from ..utils.validation import check_non_negative
24-
from ..utils._param_validation import Interval, StrOptions, Hidden
23+
from ..utils._param_validation import Interval, StrOptions
2524
from ..decomposition import PCA
2625
from ..metrics.pairwise import pairwise_distances, _VALID_METRICS
2726

@@ -678,14 +677,6 @@ class TSNE(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
678677
679678
.. versionadded:: 0.22
680679
681-
square_distances : True, default='deprecated'
682-
This parameter has no effect since distance values are always squared
683-
since 1.1.
684-
685-
.. deprecated:: 1.1
686-
`square_distances` has no effect from 1.1 and will be removed in
687-
1.3.
688-
689680
Attributes
690681
----------
691682
embedding_ : array-like of shape (n_samples, n_components)
@@ -778,7 +769,6 @@ class TSNE(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
778769
"method": [StrOptions({"barnes_hut", "exact"})],
779770
"angle": [Interval(Real, 0, 1, closed="both")],
780771
"n_jobs": [None, Integral],
781-
"square_distances": ["boolean", Hidden(StrOptions({"deprecated"}))],
782772
}
783773

784774
# Control the number of exploration iterations with early_exaggeration on
@@ -805,7 +795,6 @@ def __init__(
805795
method="barnes_hut",
806796
angle=0.5,
807797
n_jobs=None,
808-
square_distances="deprecated",
809798
):
810799
self.n_components = n_components
811800
self.perplexity = perplexity
@@ -822,7 +811,6 @@ def __init__(
822811
self.method = method
823812
self.angle = angle
824813
self.n_jobs = n_jobs
825-
self.square_distances = square_distances
826814

827815
def _check_params_vs_input(self, X):
828816
if self.perplexity >= X.shape[0]:
@@ -837,14 +825,7 @@ def _fit(self, X, skip_num_points=0):
837825
"with the sparse input matrix. Use "
838826
'init="random" instead.'
839827
)
840-
if self.square_distances != "deprecated":
841-
warnings.warn(
842-
(
843-
"The parameter `square_distances` has not effect and will be "
844-
"removed in version 1.3."
845-
),
846-
FutureWarning,
847-
)
828+
848829
if self.learning_rate == "auto":
849830
# See issue #18018
850831
self.learning_rate_ = X.shape[0] / self.early_exaggeration / 4

sklearn/manifold/tests/test_t_sne.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,45 +1138,6 @@ def test_tsne_with_mahalanobis_distance():
11381138
assert_allclose(X_trans, X_trans_expected)
11391139

11401140

1141-
# FIXME: remove in 1.3 after deprecation of `square_distances`
1142-
def test_tsne_deprecation_square_distances():
1143-
"""Check that we raise a warning regarding the removal of
1144-
`square_distances`.
1145-
1146-
Also check the parameters do not have any effect.
1147-
"""
1148-
random_state = check_random_state(0)
1149-
X = random_state.randn(30, 10)
1150-
tsne = TSNE(
1151-
n_components=2,
1152-
init="pca",
1153-
learning_rate="auto",
1154-
perplexity=25.0,
1155-
angle=0,
1156-
n_jobs=1,
1157-
random_state=0,
1158-
square_distances=True,
1159-
)
1160-
warn_msg = (
1161-
"The parameter `square_distances` has not effect and will be removed in"
1162-
" version 1.3"
1163-
)
1164-
with pytest.warns(FutureWarning, match=warn_msg):
1165-
X_trans_1 = tsne.fit_transform(X)
1166-
1167-
tsne = TSNE(
1168-
n_components=2,
1169-
init="pca",
1170-
learning_rate="auto",
1171-
perplexity=25.0,
1172-
angle=0,
1173-
n_jobs=1,
1174-
random_state=0,
1175-
)
1176-
X_trans_2 = tsne.fit_transform(X)
1177-
assert_allclose(X_trans_1, X_trans_2)
1178-
1179-
11801141
@pytest.mark.parametrize("perplexity", (20, 30))
11811142
def test_tsne_perplexity_validation(perplexity):
11821143
"""Make sure that perplexity > n_samples results in a ValueError"""

0 commit comments

Comments
 (0)