Skip to content

Commit 309a8b6

Browse files
MAINT Parameters validation for sklearn.manifold.smacof (scikit-learn#26274)
Co-authored-by: jeremie du boisberranger <jeremiedbb@yahoo.fr>
1 parent 5dd5811 commit 309a8b6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

sklearn/manifold/_mds.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ..isotonic import IsotonicRegression
1616
from ..metrics import euclidean_distances
1717
from ..utils import check_array, check_random_state, check_symmetric
18-
from ..utils._param_validation import Hidden, Interval, StrOptions
18+
from ..utils._param_validation import Hidden, Interval, StrOptions, validate_params
1919
from ..utils.parallel import Parallel, delayed
2020

2121

@@ -167,6 +167,27 @@ def _smacof_single(
167167
return X, stress, it + 1
168168

169169

170+
@validate_params(
171+
{
172+
"dissimilarities": ["array-like"],
173+
"metric": ["boolean"],
174+
"n_components": [Interval(Integral, 1, None, closed="left")],
175+
"init": ["array-like", None],
176+
"n_init": [Interval(Integral, 1, None, closed="left")],
177+
"n_jobs": [Integral, None],
178+
"max_iter": [Interval(Integral, 1, None, closed="left")],
179+
"verbose": ["verbose"],
180+
"eps": [Interval(Real, 0, None, closed="left")],
181+
"random_state": ["random_state"],
182+
"return_n_iter": ["boolean"],
183+
"normalized_stress": [
184+
"boolean",
185+
StrOptions({"auto"}),
186+
Hidden(StrOptions({"warn"})),
187+
],
188+
},
189+
prefer_skip_nested_validation=True,
190+
)
170191
def smacof(
171192
dissimilarities,
172193
*,
@@ -204,7 +225,7 @@ def smacof(
204225
205226
Parameters
206227
----------
207-
dissimilarities : ndarray of shape (n_samples, n_samples)
228+
dissimilarities : array-like of shape (n_samples, n_samples)
208229
Pairwise dissimilarities between the points. Must be symmetric.
209230
210231
metric : bool, default=True
@@ -218,7 +239,7 @@ def smacof(
218239
``init`` is used to determine the dimensionality of the embedding
219240
space.
220241
221-
init : ndarray of shape (n_samples, n_components), default=None
242+
init : array-like of shape (n_samples, n_components), default=None
222243
Starting configuration of the embedding to initialize the algorithm. By
223244
default, the algorithm is initialized with a randomly chosen array.
224245

sklearn/tests/test_public_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def _check_function_param_validation(
202202
"sklearn.linear_model.orthogonal_mp_gram",
203203
"sklearn.linear_model.ridge_regression",
204204
"sklearn.metrics.accuracy_score",
205+
"sklearn.manifold.smacof",
205206
"sklearn.metrics.auc",
206207
"sklearn.metrics.average_precision_score",
207208
"sklearn.metrics.balanced_accuracy_score",

0 commit comments

Comments
 (0)