Skip to content

MNT carry out 1.10 deprecations in MDS - #35261

Merged
lesteve merged 12 commits into
scikit-learn:mainfrom
FrancoisPgm:dep1.10_mds
Nov 5, 2026
Merged

lesteve merged 12 commits into
scikit-learn:mainfrom
FrancoisPgm:dep1.10_mds

Conversation

@FrancoisPgm

@FrancoisPgm FrancoisPgm commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #35252

What does this implement/fix? Explain your changes.

Carry out the deprecation of dissimilarity in favor of metrics in sklearn.manifold.MDS, also deprecate the use of metrics=True or metrics=False in favor of metrics_mds. Change the default or init from "random" to "classical_mds". These deprecations originate from #32229.

AI usage disclosure

I used AI assistance for:

  • Code review

Any other comments?

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! LGTM overall, only nits below.

Also, some additional possible clean-ups you could do in this PR:

  • remove init="random" in the class docstring
  • remove init="classical_mds" in plot_mds.py, plot_compare_methods.py, plot_lle_digits.py and plot_manifold_sphere.py.

Those 2 were only there to silence the FutureWarning.

Comment thread sklearn/manifold/_mds.py Outdated
init : {'random', 'classical_mds'}, default='classical_mds'
The initialization approach. If `random`, random initialization is used.
If `classical_mds`, then classical MDS is run and used as initialization
for MDS (in this case, the value of `n_init` is ignored).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With classical_mds as the default, n_init, n_jobs and random_state have no effect unless init="random". Could you say so in their docstrings? (The random_state one also says "initialize the centers", which comes from KMeans.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also removed n_init, random_state and n_jobs where MDS is initialised with init=classical_mds since they are ignored.

Comment thread sklearn/manifold/_mds.py Outdated
Comment on lines +508 to +511
.. versionchanged:: 1.8
Prior to 1.8, `metric=True/False` was used to select metric/non-metric
MDS, which is now the role of `metric_mds`. The support for ``True``
and ``False`` will be dropped in version 1.10, use `metric_mds` instead.
and ``False`` was dropped in version 1.10, use `metric_mds` instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the 1.8 note as is and add a separate entry for 1.10:

Suggested change
.. versionchanged:: 1.8
Prior to 1.8, `metric=True/False` was used to select metric/non-metric
MDS, which is now the role of `metric_mds`. The support for ``True``
and ``False`` will be dropped in version 1.10, use `metric_mds` instead.
and ``False`` was dropped in version 1.10, use `metric_mds` instead.
.. versionchanged:: 1.8
Prior to 1.8, `metric=True/False` was used to select metric/non-metric
MDS, which is now the role of `metric_mds`.
.. versionchanged:: 1.10
Boolean values for `metric` are no longer supported, use `metric_mds`
instead.

Comment thread sklearn/manifold/_mds.py Outdated
"'classical_mds' in 1.10. To suppress this warning, provide "
"some value of `init`.",
FutureWarning,
if isinstance(self.metric, (bool, np.bool_)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When carrying out deprecations we usually just remove the option from the constraints and let param validation raise (e.g. n_init="warn" in #33595). Here it would give:

InvalidParameterError: The 'metric' parameter of MDS must be an instance of 'str' or a callable. Got True instead.

I see the point of a more helpful message since metric changed meaning, but it means keeping a hidden constraint and a manual check with no plan to remove them. I'd remove Hidden("boolean") from the metric constraint and delete this isinstance block, so that param validation rejects booleans like any other invalid value. WDYT?

@FrancoisPgm FrancoisPgm Nov 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was a bit overzealous in trying to keep the error message clear, but the deprecation cycle should be enough to warn users. Thinking about it it's true that not having a plan to remove the specific message feels weird, but putting one would be adding an extra deprecation cycle, which should not be necessary. I'll remove the custom error message.

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 2, 2026
todo: move [sklearn#35295](scikit-learn/scikit-learn#35295) from Waiting to Now: address lorentzenchr's review on removing the `_safe_indexing` alias
add: Maintenance: re-review [sklearn#35261](scikit-learn/scikit-learn#35261) (1.10 deprecations in MDS; FrancoisPgm addressed my comments)
todo: betatim's fixes on [sklearn#35053](scikit-learn/scikit-learn#35053), ogrisel asking jjerphan to review [sklearn#34935](scikit-learn/scikit-learn#34935)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@virchan

virchan commented Nov 3, 2026

Copy link
Copy Markdown
Member

Also cc'ing @dkobak for visibility.

@dkobak

dkobak commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for implementing this, looks good to me together with @cakedev0 helpful suggestions above.

@github-actions github-actions Bot added size/L and removed size/M labels Nov 3, 2026
Comment thread sklearn/manifold/_mds.py
best_pos, best_stress = None, None

if effective_n_jobs(n_jobs) == 1:
if effective_n_jobs(n_jobs) == 1 or n_init == 1:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n_jobs was actually not ignored when using init='classical_mds', as having n_jobs > 1 would here force to use joblib to parallelize, but with n_init forced to one, so the parallelized for loop would only iterate over one iteration. I believe it can only be slower than not using parallelization at all, so I suggest not to go through the parallelized path when n_init == 1. WDYT @cakedev0 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't change the result right? Have you checked that it doesn't?

If I understand this right then we are "just" avoiding an unnecessary use of joblib, but the computation that happens is the same in either case. Is that also what you think happens?

If yes, then I think it is fine to make this change. If no, it is more complicated. We can make this change if the result when using joblib is wrong (this is a bugfix). If the joblib result isn't wrong, just different I am not sure what to do.

@FrancoisPgm FrancoisPgm Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should not change the result, in both paths of the if statement, the same _smacof_single method will be used with the same arguments[1]. It should already be the case since changing the value of n_jobs should only change the optimization and not numerical results, so I admit I initially just read the code to convince myself that it was equivalent, but with the help of an LLM I made a quick code snippet to check that both are equivalent, and they are.

The code snippet in question (ran with the `or n_init == 1` commented out, otherwise you always pass through the first branch of the if).
import numpy as np
from numpy.testing import assert_allclose, assert_equal
from sklearn.manifold import MDS
rng = np.random.RandomState(0)
X = rng.randn(8, 3)
mds_1 = MDS(n_jobs=1)
mds_2 = MDS(n_jobs=2)
embedding_1 = mds_1.fit_transform(X)
embedding_2 = mds_2.fit_transform(X)
assert_allclose(embedding_1, embedding_2)
assert_allclose(mds_1.stress_, mds_2.stress_)
assert_equal(mds_1.n_iter_, mds_2.n_iter_)

[1] : Except for random_state but with init="classical_mds" it is ignored, and with init="random", adapting the test snippet above with mds_1 = MDS(n_jobs=1, init="random", random_state=0) and mds_2 = MDS(n_jobs=2, init="random", random_state=0) keeps the assertions true.

EDIT : actually, I messed up with the test snippet execution the first time, and doing it properly shows that with init="random", using n_jobs=1 or n_jobs>1 does change the results as it changes the seeding. It was already the case before this PR, now what is different is that with init="random" and n_init=1, you'll always get the seeding corresponding to the first if branch, so people with MDS(init="random", n_init=1, n_jobs=n) with n>1 will have a different result. I think that is acceptable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The results only change with a fixed random_state for init="random", n_init=1, n_jobs>1. They then match n_jobs=1, which is unchanged. So completely fine and this change is what makes "n_jobs is ignored" true in the docstring.

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
done: HGB: get [sklearn#35216](scikit-learn/scikit-learn#35216) merged (binning crash on all-missing features, fixes [sklearn#35164](scikit-learn/scikit-learn#35164)), merged before I removed it
done: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features)
drop: Threads: answer lesteve on [sklearn#35105](scikit-learn/scikit-learn#35105) (RFC deprecate `pre_dispatch`)
drop: Maintenance: follow up on [sklearn#35209](scikit-learn/scikit-learn#35209) (newton-cg test failing on the macOS x86_64 wheels)
drop: Benchmarks: review [benchmarks#142](probabl-ai/scikit-learn-benchmarks#142) (cuML benchmark config)
drop: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator)
drop: Linear: [sklearn#34793](scikit-learn/scikit-learn#34793) (Ridge centering trick for cholesky), benchmarks in [benchmarks#115](probabl-ai/scikit-learn-benchmarks#115) and [benchmarks#31](probabl-ai/scikit-learn-benchmarks#31)
drop: Upstream: sklearnex reports [sklearnex#3402](uxlfoundation/scikit-learn-intelex#3402), [sklearnex#3377](uxlfoundation/scikit-learn-intelex#3377), [sklearnex#3220](uxlfoundation/scikit-learn-intelex#3220)
drop: Upstream: [data-apis/array-api#976](data-apis/array-api#976) (why `stable=True` is the default for `xp.sort`)
drop: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148)
drop: Threads: [sklearn#34736](scikit-learn/scikit-learn#34736) (oversubscription in `pairwise_distances`), out of the reported findings item
drop: KMeans: benchmarks [benchmarks#154](probabl-ai/scikit-learn-benchmarks#154), [benchmarks#160](probabl-ai/scikit-learn-benchmarks#160), [OpenBLAS#6105](OpenMathLib/OpenBLAS#6105) and [sklearn#17334](scikit-learn/scikit-learn#17334), out of the [sklearn#35193](scikit-learn/scikit-learn#35193) item
todo: move [joblib#1899](joblib/joblib#1899), [sklearn#35261](scikit-learn/scikit-learn#35261) and [sklearn#35053](scikit-learn/scikit-learn#35053) from Reviews to Now, [sklearn#35181](scikit-learn/scikit-learn#35181) to the top of Waiting (by hand in 03835dd)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@betatim

betatim commented Nov 3, 2026

Copy link
Copy Markdown
Member

AI found that sklearn/tests/test_docstring_parameters.py line 242 can probably be removed/updated now that we have reached 1.10. Looks like it only exists to avoid a FutureWarning.

sklearn/utils/_test_common/instance_generator.py L670 can probably drop the n_init=2 (and others?)


Should we have a test that checks something like MDS().fit_transform(X) equals MDS(init="classical_mds").fit_transform(X) now that we don't have any other tests of MDS() with all defaults? But I think this might be going into the territory of improvement and not just "deal with deprecation".

@FrancoisPgm

Copy link
Copy Markdown
Member Author

AI found that sklearn/tests/test_docstring_parameters.py line 242 can probably be removed/updated now that we have reached 1.10. Looks like it only exists to avoid a FutureWarning.

Good catch, thanks, your AI has a better eye than mine ^^

sklearn/utils/_test_common/instance_generator.py L670 can probably drop the n_init=2 (and others?)

I see the point of removing the n_init=2 now that the default is lower, for the other ones they are lower than the defaults so I think the values are there to save some compute so I'd let them. But I'm not sure I get the goal of the PER_ESTIMATOR_CHECK_PARAMS dict.

@betatim

betatim commented Nov 4, 2026

Copy link
Copy Markdown
Member

sklearn/utils/_test_common/instance_generator.py L670 can probably drop the n_init=2 (and others?)

I see the point of removing the n_init=2 now that the default is lower, for the other ones they are lower than the defaults so I think the values are there to save some compute so I'd let them. But I'm not sure I get the goal of the PER_ESTIMATOR_CHECK_PARAMS dict.

Let's do n_init and leave the rest

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@cakedev0 cakedev0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some tiny nits below,:

  • _smacof_single (L76) and smacof (L302) still say "initialize the centers" in their random_state docstrings, the same KMeans wording you fixed in MDS.

Comment thread sklearn/manifold/_mds.py Resolved
@lesteve
lesteve enabled auto-merge (squash) November 5, 2026 10:53
@lesteve

lesteve commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

I accepted the last comment and I enabled auto-merge, thanks a lot @FrancoisPgm for the PR and @betatim + @cakedev0 + @virchan + @dkobak for the reviews!

@lesteve
lesteve merged commit 59ec4fb into scikit-learn:main Nov 5, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants