You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?
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.
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}.
@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}?
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!
Activity
adrinjalali commentedon Oct 16, 2019
I'd be happy to have the other implementation as an alternative, and a parameter to set is as the
algorithm.amueller commentedon Oct 17, 2019
related to #4485 ?
amueller commentedon Oct 17, 2019
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
maxibor commentedon Oct 18, 2019
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
rth commentedon Oct 18, 2019
@maxibor You would be very welcome to continue that PR.
panpiort8 commentedon Nov 6, 2019
Is anyone working on that? If not, I can take it.
adrinjalali commentedon Nov 6, 2019
Seems like it's available, feel free to take it @panpiort8
panpiort8 commentedon Nov 7, 2019
Ok, I'll take it (then I suppose 'help wanted' is misleading)
panpiort8 commentedon Nov 18, 2019
Could someone review above PR?
adrinjalali commentedon Nov 18, 2019
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 ;)
panpiort8 commentedon Nov 18, 2019
Ok, I fully understand. I'll ping soon :)
panpiort8 commentedon Dec 11, 2019
gentle ping (;
panpiort8 commentedon Dec 20, 2019
Could someone review above PR? (gentle ping no. 2)
earmingol commentedon Jan 7, 2021
Has this been finally implemented? I read the documentation, but there is nothing about SVD yet :(
panpiort8 commentedon Jan 14, 2021
It's almost implemented (PR #16067), but still needs pretty much work to be merged. Feel free to continue this PR.
jolespin commentedon Feb 3, 2022
Has there been any progress on this recently? Looking forward to decreasing my reliance on
scikit-bioforPCoA.Micky774 commentedon Feb 8, 2022
@jolespin Current progress is in PR #22330 which provides and SVD implementation to the metric MDS context.
dkobak commentedon Oct 23, 2024
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 ismetric={True, False}switch. So the least invasive option (that would not require a deprecation cycle) would be to add a separate parameterclassical={True, False}.What do people think?
dkobak commentedon Nov 4, 2024
@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 withalgorithm={"metric", "classical", "non-metric"}and gradually deprecatemetric={True, False}?adrinjalali commentedon Nov 4, 2024
I think the
algorithmpath is the nicest API FAICT. To move this forward we need reviewers for #22330dd1735 commentedon Nov 17, 2024
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!
dkobak commentedon Nov 18, 2024
I replied in more detail in your closed issue, but I think Wikipedia has a good overview:
dkobak commentedon May 6, 2025
I made a new PR to implement classical MDS aka PCoA: #31322.