Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import spherecluster with scikit-learn 1.0.2: sklearn.cluster.k_means_ has been renamed #35

Open
ngiatsog opened this issue Feb 11, 2022 · 3 comments

Comments

@ngiatsog
Copy link

The traceback is

Traceback (most recent call last):
File "//python3.9/site-packages/IPython/core/interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
import spherecluster
File "/snap/pycharm-community/267/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "//python3.9/site-packages/spherecluster/init.py", line 2, in
from .spherical_kmeans import SphericalKMeans
File "/snap/pycharm-community/267/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self.system_import(name, *args, **kwargs)
File "//python3.9/site-packages/spherecluster/spherical_kmeans.py", line 7, in
from sklearn.cluster.k_means
import (
File "/snap/pycharm-community/267/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self.system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'sklearn.cluster.k_means
'

The problem is that 'sklearn.cluster.k_means_' has been renamed to 'sklearn.cluster._kmeans' in some intermediate scikit-learn version.

@rfayat
Copy link

rfayat commented Nov 16, 2022

Hi !

I haven't tested it with the most recent version of scikit but I solved this issue for scikit 0.24 in my pull request #34 (you can also check my fork) where the change from sklearn.cluster.k_means_ to sklearn.cluster._kmeans appeared.

From what I remember it was a bit more complicated than a simple renaming issue because some functions called by sklearn.cluster.k_means_ are now class methods of KMeans.

Hope this helps !

Romain

@Darel13712
Copy link

@rfayat Hey, I tried your version, but ran into

from sklearn.cluster import _k_means_fast as _k_means

ImportError: cannot import name '_k_means_fast' from 'sklearn.cluster'

Does it mean that interfaces changed once again or I'm just using a wrong version?

@rfayat
Copy link

rfayat commented Apr 11, 2023

Hey @Darel13712 indeed I just checked and it seems to have changed again between v0.24 and V1.0.2, my fork won't work for this newest version...

Sorry for the false hope 😞

Cheers,

RF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants