Skip to content

Commit

Permalink
MAINT Clean up deprecated square_distances in TSNE for 1.3 (scikit-le…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiedbb committed Jun 8, 2023
1 parent 2182544 commit b0e4630
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
23 changes: 2 additions & 21 deletions sklearn/manifold/_t_sne.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# * Fast Optimization for t-SNE:
# https://cseweb.ucsd.edu/~lvdmaaten/workshops/nips2010/papers/vandermaaten.pdf

import warnings
from time import time
import numpy as np
from scipy import linalg
Expand All @@ -21,7 +20,7 @@
from ..utils import check_random_state
from ..utils._openmp_helpers import _openmp_effective_n_threads
from ..utils.validation import check_non_negative
from ..utils._param_validation import Interval, StrOptions, Hidden
from ..utils._param_validation import Interval, StrOptions
from ..decomposition import PCA
from ..metrics.pairwise import pairwise_distances, _VALID_METRICS

Expand Down Expand Up @@ -678,14 +677,6 @@ class TSNE(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
.. versionadded:: 0.22
square_distances : True, default='deprecated'
This parameter has no effect since distance values are always squared
since 1.1.
.. deprecated:: 1.1
`square_distances` has no effect from 1.1 and will be removed in
1.3.
Attributes
----------
embedding_ : array-like of shape (n_samples, n_components)
Expand Down Expand Up @@ -778,7 +769,6 @@ class TSNE(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
"method": [StrOptions({"barnes_hut", "exact"})],
"angle": [Interval(Real, 0, 1, closed="both")],
"n_jobs": [None, Integral],
"square_distances": ["boolean", Hidden(StrOptions({"deprecated"}))],
}

# Control the number of exploration iterations with early_exaggeration on
Expand All @@ -805,7 +795,6 @@ def __init__(
method="barnes_hut",
angle=0.5,
n_jobs=None,
square_distances="deprecated",
):
self.n_components = n_components
self.perplexity = perplexity
Expand All @@ -822,7 +811,6 @@ def __init__(
self.method = method
self.angle = angle
self.n_jobs = n_jobs
self.square_distances = square_distances

def _check_params_vs_input(self, X):
if self.perplexity >= X.shape[0]:
Expand All @@ -837,14 +825,7 @@ def _fit(self, X, skip_num_points=0):
"with the sparse input matrix. Use "
'init="random" instead.'
)
if self.square_distances != "deprecated":
warnings.warn(
(
"The parameter `square_distances` has not effect and will be "
"removed in version 1.3."
),
FutureWarning,
)

if self.learning_rate == "auto":
# See issue #18018
self.learning_rate_ = X.shape[0] / self.early_exaggeration / 4
Expand Down
39 changes: 0 additions & 39 deletions sklearn/manifold/tests/test_t_sne.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,45 +1138,6 @@ def test_tsne_with_mahalanobis_distance():
assert_allclose(X_trans, X_trans_expected)


# FIXME: remove in 1.3 after deprecation of `square_distances`
def test_tsne_deprecation_square_distances():
"""Check that we raise a warning regarding the removal of
`square_distances`.
Also check the parameters do not have any effect.
"""
random_state = check_random_state(0)
X = random_state.randn(30, 10)
tsne = TSNE(
n_components=2,
init="pca",
learning_rate="auto",
perplexity=25.0,
angle=0,
n_jobs=1,
random_state=0,
square_distances=True,
)
warn_msg = (
"The parameter `square_distances` has not effect and will be removed in"
" version 1.3"
)
with pytest.warns(FutureWarning, match=warn_msg):
X_trans_1 = tsne.fit_transform(X)

tsne = TSNE(
n_components=2,
init="pca",
learning_rate="auto",
perplexity=25.0,
angle=0,
n_jobs=1,
random_state=0,
)
X_trans_2 = tsne.fit_transform(X)
assert_allclose(X_trans_1, X_trans_2)


@pytest.mark.parametrize("perplexity", (20, 30))
def test_tsne_perplexity_validation(perplexity):
"""Make sure that perplexity > n_samples results in a ValueError"""
Expand Down

0 comments on commit b0e4630

Please sign in to comment.