Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dkobak
Copy link
Contributor

@dkobak dkobak commented Sep 20, 2025

This is a follow-up to #31322 that added a classical MDS implementation as ClassicalMDS class. As discussed over there, this PR does the following:

  1. It adds support for non-Euclidean metrics to the MDS class, following example of ClassicalMDS.
  2. It changes the API of MDS to make it consistent with ClassicalMDS and other sklearn classes: distance metric is now set via the metric argument, and metric/non-metric MDS can be toggled via metric_mds=True/False argument. Backwards compatibility is ensured for the next scikit-learn versions.
  3. Classical MDS is added as an initialization option to the MDS class, to be made default in the future.

PS. Apologies for lots of obsolete commits here :-( Just ignore them.

@dkobak
Copy link
Contributor Author

dkobak commented Sep 20, 2025

@antoinebaker As promised, now that my Classical MDS PR has been merged, I prepared a follow-up PR to modify the MDS class accordingly. Would be great if you could take a look.

@dkobak
Copy link
Contributor Author

dkobak commented Sep 30, 2025

@adrinjalali Also pinging you here explicitly. This is a straightforward PR that completes the MDS-related changes I was planning. It would be great to have this merged in time for 1.8, so that it goes out together with the previous MDS-related PR... 🙏 Hope this is still feasible!

@dkobak
Copy link
Contributor Author

dkobak commented Oct 6, 2025

@adrinjalali Thanks a lot! All good comments, I have implemented all of them.

One question. The code contained the following legacy snippet:

        if X.shape[0] == X.shape[1] and (self._metric != "precomputed"):
            warnings.warn(
                "The MDS API has changed. ``fit`` now constructs a"
                " dissimilarity matrix from data. To use a custom "
                "dissimilarity matrix, set "
                "``metric='precomputed'``."
            )

This warning can be triggered in case X has as many features as samples (admittedly unlikely case, but it can happen). In that case there will be no way to get rid of this warning. Is this OK? Should we drop this warning altogether? It sounds like a future warning but is not implemented as a future warning...

@adrinjalali
Copy link
Member

This warning can be triggered in case X has as many features as samples (admittedly unlikely case, but it can happen). In that case there will be no way to get rid of this warning. Is this OK? Should we drop this warning altogether? It sounds like a future warning but is not implemented as a future warning...

When that happens, we have more significant problems 😅 There are other places in the code where things break when number of features is exactly the same as number of samples and it's not a pairwise thing.

@dkobak
Copy link
Contributor Author

dkobak commented Oct 7, 2025

There are other places in the code where things break when number of features is exactly the same as number of samples and it's not a pairwise thing.

Okay, but I edited the warning text now to be more explicit and not to say that the "API has changed" (it was a long time ago, so that part is obsolete).

@dkobak
Copy link
Contributor Author

dkobak commented Oct 20, 2025

Hi @adrinjalali, let me know if there is anything I can still do here! 🙏

Copy link
Contributor

@antoinebaker antoinebaker left a comment

Choose a reason for hiding this comment

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

Here a few suggestions, but I'm unfamiliar with the conventions for the deprecation cycle, so to be confirmed by a more seasoned developer :)

To summarize the changes in 1.8:

  • dissimilarity is renamed metric
  • metric is renamed metric_mds
  • metric_params is added

@dkobak
Copy link
Contributor Author

dkobak commented Oct 21, 2025

Thanks @antoinebaker, this makes sense and indeed follows the official guidelines. I pushed your edits.

@dkobak
Copy link
Contributor Author

dkobak commented Oct 28, 2025

@antoinebaker Do you think there is anything else I should do here? I am not sure when the deadline for 1.8 is, but I am getting worried that this PR won't make it in time...

Copy link
Contributor

@antoinebaker antoinebaker left a comment

Choose a reason for hiding this comment

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

Apart from a nitpick, LGTM !

It's cool that the new initialization fixes the non-metric MDS examples (like plot_compare_methods and plot_manifold_sphere).

It would be nice if the second reviewer can confirm that the API changes are well handled.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

LGTM. We need a second reviewer here.\

EDIT: I just saw Antoine having reviewed. So good to go.

@adrinjalali adrinjalali merged commit b1b01a1 into scikit-learn:main Nov 6, 2025
38 checks passed
@dkobak dkobak deleted the mds-init-and-metrics branch November 6, 2025 09:49
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.

3 participants