Skip to content

Commit 243d61a

Browse files
DOC Improve the error message in TSNE to include the problematic values (scikit-learn#30876)
Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
1 parent 66ffb58 commit 243d61a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sklearn/manifold/_t_sne.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,10 @@ def __init__(
859859

860860
def _check_params_vs_input(self, X):
861861
if self.perplexity >= X.shape[0]:
862-
raise ValueError("perplexity must be less than n_samples")
862+
raise ValueError(
863+
f"perplexity ({self.perplexity}) must be less "
864+
f"than n_samples ({X.shape[0]})"
865+
)
863866

864867
def _fit(self, X, skip_num_points=0):
865868
"""Private function to fit the model using X as training data."""

sklearn/manifold/tests/test_t_sne.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import sys
23
from io import StringIO
34

@@ -1170,7 +1171,7 @@ def test_tsne_perplexity_validation(perplexity):
11701171
perplexity=perplexity,
11711172
random_state=random_state,
11721173
)
1173-
msg = "perplexity must be less than n_samples"
1174+
msg = re.escape(f"perplexity ({perplexity}) must be less than n_samples (20)")
11741175
with pytest.raises(ValueError, match=msg):
11751176
est.fit_transform(X)
11761177

0 commit comments

Comments
 (0)