ImportError: cannot import name choice when importing sklearn.mixture

后端 未结 3 790
慢半拍i
慢半拍i 2021-01-17 23:43

I am using scikit learn 0.15.0. When I try to import sklearn.mixture I get ImportError: cannot import name choice

Any ideas?

================================

相关标签:
3条回答
  • 2021-01-17 23:49
    from sklearn.mixture import GaussianMixture
    

    using this would make it more specific to work with .gmm,

    and

    from sklearn.cluster import KMeans
    

    for:

         16 from ..neighbors import kneighbors_graph
         17 from ..manifold import spectral_embedding
    ---> 18 from .k_means_ import k_means
    
    0 讨论(0)
  • 2021-01-17 23:56

    I was getting the same error when I tried to import KMeans as : from sklearn.cluster import KMeans

    Error > ImportError: cannot import name choice

    I found the answer here: https://github.com/scikit-learn/scikit-learn/issues/3461

    Since I have upgraded to Scikit version 0.15 a few days back, the older version of random.so was present in /usr/local/lib/python2.7/dist-packages/sklearn/utils.

    I manually deleted it and now I do not get the error anymore.

    Hope this helps.

    0 讨论(0)
  • 2021-01-18 00:06

    As noted, it might have to do with old files (that are implemented in python as opposed to libraries?) in a new package you probably updated using pip install -U packagename (in my case pip install -U scikit-learn) It might be worth first trying to uninstall the package and install it again before manually deleting stuff... (worked in my case) uninstall (in my case run it on Anaconda Command prompt):

       pip uninstall scikit-learn
    

    then:

       pip install -U numpy scipy scikit-learn
    

    (added dependencies just in case) then just to be sure

       pip install scikit-learn
    

    should say it's installed

    0 讨论(0)
提交回复
热议问题