sklearn导入错误 - ImportError:无法导入名称' comb'

时间:2017-11-07 06:37:18

标签: scikit-learn python-3.6

我正在尝试这样做:

from sklearn.model_selection import train_test_split

并收到错误:

In [31]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-31-73edc048c06b> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python3.6/site-packages/sklearn/model_selection/__init__.py in <module>()
----> 1 from ._split import BaseCrossValidator
      2 from ._split import KFold
      3 from ._split import GroupKFold
      4 from ._split import StratifiedKFold
      5 from ._split import TimeSeriesSplit

/usr/local/lib/python3.6/site-packages/sklearn/model_selection/_split.py in <module>()
     29 from ..externals.six import with_metaclass
     30 from ..externals.six.moves import zip
---> 31 from ..utils.fixes import signature, comb
     32 from ..base import _pprint
     33 

ImportError: cannot import name 'comb'

任何帮助都会有很大帮助。

2 个答案:

答案 0 :(得分:0)

SciPy> = 0.19使用from scipy.special import comb而不是from scipy.misc import combhttps://github.com/scikit-learn/scikit-learn/pull/9046

utils/fixes.py source

try:  # SciPy >= 0.19
    from scipy.special import comb, logsumexp
except ImportError:
    from scipy.misc import comb, logsumexp  # noqa 

答案 1 :(得分:0)

我有同样的错误。 conda删除-为您的环境命名-全部。接下来,重新安装环境。它对我有用。