YingfanWang / PaCMAP

PaCMAP: Large-scale Dimension Reduction Technique Preserving Both Global and Local Structure
Apache License 2.0
524 stars 53 forks source link

Doesn't work in sklearn's Pipeline #15

Closed jochenater closed 3 years ago

jochenater commented 3 years ago

pipe = Pipeline([('reduce_dim', pacman()), ('kmeans, KMeans())])

AttributeError: 'PaCMAP' object has no attribute 'random_state'

Would be great if it did

hyhuang00 commented 3 years ago

Could you report the version of your PaCMAP? In some cases, update to the newest version via pip install --upgrade pacmap could solve the problem.

jochenater commented 3 years ago

I just installed it today so should be the newest version. It's: 0.5.2

hyhuang00 commented 3 years ago

I see. I have reproduced your error locally. Let me try to fix this.

hyhuang00 commented 3 years ago

The problem with the current version of PaCMAP is that the random_state parameter got renamed into seed into the PaCMAP instance. When you try to print the PaCMAP instances, however, the sklearn convention will ask the instance to print all its parameter as is. I will try to bring up a hotfix later today. To use the PaCMAP before the hotfix released, please try to avoid printing it out (e.g. pacman = pacmap.PaCMAP())

hyhuang00 commented 3 years ago

A hotfix have been pushed to the PyPI. However, given that current PaCMAP algorithm is transductive instead of inductive, it does not implement transform() method (just as the sklearn TSNE implementation), which means you will still be unable to use it in Pipeline. Please try to use the workaround provide in my last comment.

jochenater commented 3 years ago

Thanks for the quick fix! I've just seen the other issue about the lack of transform method. I think it would greatly improve the usability if it had one ;)

jochenater commented 3 years ago

For people that just need to use it in their pipeline, here is some ugly hack:

pacman = PaCMAP() def transform(self, *args, **kwargs): return self.fit_transform(*args, **kwargs) pacman.transform = transform.__get__(pacman)

hyhuang00 commented 2 years ago

The transform method has been added in the latest release.