Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn.manifold.MDS has no transform method

Tags:

scikit-learn

After I make an MDS object mds, and fit it with mds.fit(X), I thought I would be able to project new points using mds.transform(X_new). I think that's the API in other manifold classes. But there is only fit_transform. I guess from the description that fit_transform does some more fitting, and I don't want to change the projection which has already been calculated!

EDIT: wait, maybe this doesn't make sense. I did some more reading. If I now understand right, the MDS algorithm is an iterative one that "just moves points around" until the stress value gets low -- and doesn't actually allow for projection.

But still, I'm a bit confused about what fit_transform does. The docs say "Fit the data from X, and returns the embedded coordinates". How is that different from just fitting and taking mds.embedding_?

like image 307
jmmcd Avatar asked Feb 22 '14 23:02

jmmcd


2 Answers

For a scikit-learn transformer, estimator.fit_transform(X) is always equivalent to estimator.fit(X).transform(X), but usually implemented more efficiently. In this case, it is indeed the same as estimator.fit(X).embedding_; it's there because scikit-learn classes such as Pipeline may call it.

It seems there's no transform method on any of the manifold learners, perhaps by mistake; I just opened an issue about this.

like image 71
Fred Foo Avatar answered Oct 16 '22 08:10

Fred Foo


sklearn MDS, SpectralEnbedding, and TSNE cannot be used for feature reduction for classification. They do not have a stand-alone transform() method like KernelPCA or LocallyLinearEmbedding. Without a transform() method, there is no way to transform and score new data.

MDS and TSNE are used for feature set analysis only. Typical examples are for visualization, but their use in feature analysis goes beyond just visualization.

Use PCA for linearly separable feature sets and a non-linear transformer like LLE for non-linearly separable feature sets.

like image 22
tmck Avatar answered Oct 16 '22 07:10

tmck