8000 MNT change and deprecate square_distances in TSNE (#21592) · scikit-learn/scikit-learn@cd10651 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd10651

Browse files
MNT change and deprecate square_distances in TSNE (#21592)
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
1 parent 2762387 commit cd10651

File tree

3 files changed

+119
-184
lines changed

3 files changed

+119
-184
lines changed

sklearn/manifold/_t_sne.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,13 @@ class TSNE(BaseEstimator):
654654
655655
.. versionadded:: 0.22
656656
657-
square_distances : True or 'legacy', default='legacy'
658-
Whether TSNE should square the distance values. ``'legacy'`` means
659-
that distance values are squared only when ``metric="euclidean"``.
660-
``True`` means that distance values are squared for all metrics.
657+
square_distances : True, default='deprecated'
658+
This parameter has no effect since distance values are always squared
659+
since 1.1.
661660
662-
.. versionadded:: 0.24
663-
Added to provide backward compatibility during deprecation of
664-
legacy squaring behavior.
665-
.. deprecated:: 0.24
666-
Legacy squaring behavior was deprecated in 0.24. The ``'legacy'``
667-
value will be removed in 1.1 (renaming of 0.26), at which point the
668-
default value will change to ``True``.
661+
.. deprecated:: 1.1
662+
`square_distances` has no effect from 1.1 and will be removed in
663+
1.3.
669664
670665
Attributes
671666
----------
@@ -755,7 +750,7 @@ def __init__(
755750
method="barnes_hut",
756751
angle=0.5,
757752
n_jobs=None,
758-
square_distances="legacy",
753+
square_distances="deprecated",
759754
):
760755
self.n_components = n_components
761756
self.perplexity = perplexity
@@ -771,7 +766,6 @@ def __init__(
771766
self.method = method
772767
self.angle = angle
773768
self.n_jobs 10000 = n_jobs
774-
# TODO Revisit deprecation of square_distances for 1.1-1.3 (#12401)
775769
self.square_distances = square_distances
776770

777771
def _fit(self, X, skip_num_points=0):
@@ -808,26 +802,19 @@ def _fit(self, X, skip_num_points=0):
808802
raise ValueError("'method' must be 'barnes_hut' or 'exact'")
809803
if self.angle < 0.0 or self.angle > 1.0:
810804
raise ValueError("'angle' must be between 0.0 - 1.0")
811-
if self.square_distances not in [True, "legacy"]:
812-
raise ValueError("'square_distances' must be True or 'legacy'.")
805+
if self.square_distances != "deprecated":
806+
warnings.warn(
807+
"The parameter `square_distances` has not effect and will be "
808+
"removed in version 1.3.",
809+
FutureWarning,
810+
)
813811
if self._learning_rate == "auto":
814812
# See issue #18018
815813
self._learning_rate = X.shape[0] / self.early_exaggeration / 4
816814
self._learning_rate = np.maximum(self._learning_rate, 50)
817815
else:
818816
if not (self._learning_rate > 0):
819817
raise ValueError("'learning_rate' must be a positive number or 'auto'.")
820-
if self.metric != "euclidean" and self.square_distances is not True:
821-
warnings.warn(
822-
"'square_distances' has been introduced in 0.24 to help phase "
823-
"out legacy squaring behavior. The 'legacy' setting will be "
824-
"removed in 1.1 (renaming of 0.26), and the default setting "
825-
"will be changed to True. In 1.3, 'square_distances' will be "
826-
"removed altogether, and distances will be squared by "
827-
"default. Set 'square_distances'=True to silence this "
828-
"warning.",
829-
FutureWarning,
830-
)
831818
if self.method == "barnes_hut":
832819
X = self._validate_data(
833820
X,
@@ -907,7 +894,7 @@ def _fit(self, X, skip_num_points=0):
907894
"All distances should be positive, the metric given is not correct"
908895
)
909896

910-
if self.metric != "euclidean" and self.square_distances is True:
897+
if self.metric != "euclidean":
911898
distances **= 2
912899

913900
# compute the joint probability distribution for the input space
@@ -958,13 +945,12 @@ def _fit(self, X, skip_num_points=0):
958945
# Free the memory used by the ball_tree
959946
del knn
960947

961-
if self.square_distances is True or self.metric == "euclidean":
962-
# knn return the euclidean distance but we need it squared
963-
# to be consistent with the 'exact' method. Note that the
964-
# the method was derived using the euclidean method as in the
965-
# input space. Not sure of the implication of using a different
966-
# metric.
967-
distances_nn.data **= 2
948+
# knn return the euclidean distance but we need it squared
949+
# to be consistent with the 'exact' method. Note that the
950+
# the method was derived using the euclidean method as in the
951+
# input space. Not sure of the implication of using a different
952+
# metric.
953+
distances_nn.data **= 2
968954

969955
# compute the joint probability distribution for the input space
970956
P = _joint_probabilities_nn(distances_nn, self.perplexity, self.verbose)

0 commit comments

Comments
 (0)
0