Skip to content

sklearn MDS vs skbio PCoA #15272

Closed
Closed

Description

@maxibor

Multi Dimensional Scaling (MDS) and Principal Coordinate Analysis (PCoA) are two names for the same dimension reduction technique*.

In scikit-learn, MDS is implemented with the SMACOF algorithm while in other Python libraries (such as scikit-bio) and most R packages offering it, it is implemented using singular value decomposition.

This is usually quite confusing for people who try out the sklearn implementation of MDS when comparing it with other MDS implementations (sklearn stands out).

How could one add another implementation of MDS in sklearn ? Or maybe create a new PCoA method ?

cc @adrinjalali

Activity

  1. adrinjalali commented on Oct 16, 2019

    @adrinjalali
    Member

    I'd be happy to have the other implementation as an alternative, and a parameter to set is as the algorithm.

  2. added
    Moderate
    on Oct 16, 2019
  3. amueller commented on Oct 17, 2019

    @amueller
    Member

    related to #4485 ?

  4. amueller commented on Oct 17, 2019

    @amueller
    Member

    What's the relation between PCA and PCoA? They seem quite similar but I'm not really familiar with MDS and have never heard the term PCoA

  5. maxibor commented on Oct 18, 2019

    @maxibor
    Author

    What's the relation between PCA and PCoA? They seem quite similar but I'm not really familiar with MDS and have never heard the term PCoA

    PCoA is essentially a PCA, but starting for a distance matrix (which doesn't need to be euclidean).
    It seems indeed, that it is mostly what #4485 is implementing.

    The scikit-bio implementation is quite nice: _principal_coordinate_analysis.py

  6. rth commented on Oct 18, 2019

    @rth
    Member

    It seems indeed, that is mostly what #4485 is implementing.

    @maxibor You would be very welcome to continue that PR.

  7. panpiort8 commented on Nov 6, 2019

    @panpiort8
    Contributor

    Is anyone working on that? If not, I can take it.

  8. adrinjalali commented on Nov 6, 2019

    @adrinjalali
    Member

    Seems like it's available, feel free to take it @panpiort8

  9. panpiort8 commented on Nov 7, 2019

    @panpiort8
    Contributor

    Ok, I'll take it (then I suppose 'help wanted' is misleading)

  10. panpiort8 commented on Nov 18, 2019

    @panpiort8
    Contributor

    Could someone review above PR?

  11. adrinjalali commented on Nov 18, 2019

    @adrinjalali
    Member

    We're busy mostly with the release at the moment. We should be able to focus on this more if you ping in 3 weeks ;)

  12. panpiort8 commented on Nov 18, 2019

    @panpiort8
    Contributor

    Ok, I fully understand. I'll ping soon :)

  13. panpiort8 commented on Dec 11, 2019

    @panpiort8
    Contributor

    gentle ping (;

  14. panpiort8 commented on Dec 20, 2019

    @panpiort8
    Contributor

    Could someone review above PR? (gentle ping no. 2)

  15. earmingol commented on Jan 7, 2021

    @earmingol

    Could someone review above PR? (gentle ping no. 2)

    Has this been finally implemented? I read the documentation, but there is nothing about SVD yet :(

  16. panpiort8 commented on Jan 14, 2021

    @panpiort8
    Contributor

    It's almost implemented (PR #16067), but still needs pretty much work to be merged. Feel free to continue this PR.

  17. jolespin commented on Feb 3, 2022

    @jolespin

    Has there been any progress on this recently? Looking forward to decreasing my reliance on scikit-bio for PCoA.

  18. Micky774 commented on Feb 8, 2022

    @Micky774
    Contributor

    @jolespin Current progress is in PR #22330 which provides and SVD implementation to the metric MDS context.

  19. dkobak commented on Oct 23, 2024

    @dkobak
    Contributor

    There is some confusion in the discussion above.

    PCoA is another name for "classical MDS". It takes a matrix of pairwise distances, performs some linear algebra and eigendecomposition, and gets the embedding. The loss function that is minimized is sometimes called "strain". If the input pairwise distances are Euclidean distances between some vectors, then this procedure is equivalent to PCA of those vectors. In contrast, "metric MDS" optimizes a DIFFERENT loss function called "stress", and can only be solved iteratively. These are two different optimization problems with two different solutions. There is also "non-metric MDS" which is a yet another different thing.

    I fully agree that classical MDS aka PCoA should be implemented in sklearn. My question is: what is the best API for that?

    Ideally I would prefer algorithm={"metric", "classical", "non-metric"}. But currently there is metric={True, False} switch. So the least invasive option (that would not require a deprecation cycle) would be to add a separate parameter classical={True, False}.

    What do people think?

  20. dkobak commented on Nov 4, 2024

    @dkobak
    Contributor

    @amueller @adrinjalali What do you think about the optimal API (see my comment above)? Does classical={True, False} look like a reasonable solution? Or should we go with algorithm={"metric", "classical", "non-metric"} and gradually deprecate metric={True, False}?

  21. adrinjalali commented on Nov 4, 2024

    @adrinjalali
    Member

    I think the algorithm path is the nicest API FAICT. To move this forward we need reviewers for #22330

  22. dd1735 commented on Nov 17, 2024

    @dd1735

    I would like to understand the specific stress function currently implemented in scikit-learn for both metric and non-metric MDS. Does the implementation follow the Kruskal stress function as described in the referenced papers in the documentation? If not, could you kindly clarify the formula used for each and any key differences?
    I previously raised this #30240 but was advised to add my thoughts here. Thank you for your patience!

  23. dkobak commented on Nov 18, 2024

    @dkobak
    Contributor

    I would like to understand the specific stress function currently implemented in scikit-learn for both metric and non-metric MDS.

    I replied in more detail in your closed issue, but I think Wikipedia has a good overview:

  24. dkobak commented on May 6, 2025

    @dkobak
    Contributor

    I made a new PR to implement classical MDS aka PCoA: #31322.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementModeratemodule:manifold

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions