2016-11-15 44 views
3

我正在嘗試導入sklearn.model_selection。我試圖重新安裝scikit-learn和anaconda,但仍然無法正常工作。 以下是錯誤味精我:無法在scikit-learn中導入sklearn.model_selection

ImportError        Traceback (most recent call last) 
<ipython-input-69-e49df3a70ea4> in <module>() 
     4 get_ipython().magic(u'matplotlib inline') 
     5 # from sklearn.model_selection import train_test_split 
----> 6 import sklearn.model_selection 

/Users/Lu/anaconda/lib/python2.7/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 

/Users/Lu/anaconda/lib/python2.7/site-packages/sklearn/model_selection/_split.py in <module>() 
    34 from ..utils.random import choice 
    35 from ..base import _pprint 
---> 36 from ..gaussian_process.kernels import Kernel as GPKernel 
    37 
    38 __all__ = ['BaseCrossValidator', 

/Users/Lu/anaconda/lib/python2.7/site-packages/sklearn/gaussian_process/__init__.py in <module>() 
    11 """ 
    12 
---> 13 from .gpr import GaussianProcessRegressor 
    14 from .gpc import GaussianProcessClassifier 
    15 from . import kernels 

/Users/Lu/anaconda/lib/python2.7/site-packages/sklearn/gaussian_process/gpr.py in <module>() 
    10 import numpy as np 
    11 from scipy.linalg import cholesky, cho_solve, solve_triangular 
---> 12 from scipy.optimize import fmin_l_bfgs_b 
    13 
    14 from sklearn.base import BaseEstimator, RegressorMixin, clone 

/Users/Lu/anaconda/lib/python2.7/site-packages/scipy/optimize/__init__.py in <module>() 
    232 from .optimize import * 
    233 from ._minimize import * 
--> 234 from ._root import * 
    235 from .minpack import * 
    236 from .zeros import * 

/Users/Lu/anaconda/lib/python2.7/site-packages/scipy/optimize/_root.py in <module>() 
    17 
    18 from .optimize import MemoizeJac, OptimizeResult, _check_unknown_options 
---> 19 from .minpack import _root_hybr, leastsq 
    20 from ._spectral import _root_df_sane 
    21 from . import nonlin 

/Users/Lu/anaconda/lib/python2.7/site-packages/scipy/optimize/minpack.py in <module>() 
     2 
     3 import warnings 
----> 4 from . import _minpack 
     5 
     6 import numpy as np 

ImportError: cannot import name _minpack 
+0

你以爲更新'scipy'?你是如何重新安裝sklearn的?與'conda'? – MMF

回答

5

檢查scikit學習版本;

import sklearn 
print(sklearn.__version__) 

sklearn.model_selection可用於版本0.18.1。

你需要導入取決於你需要什麼。例如,在0.18.1版本,GridSearchCV可以在0.17.1版本導入爲

from sklearn.model_selection import GridSearchCV 

然而,同樣可如果你發現新的scikit文檔中的任何導入爲

from sklearn.grid_search import GridSearchCV 

這在您的系統中不適用於您,然後在文檔中搜索您正在使用的當前版本。導入路徑可能不同,但總體功能應該是相同的。

如果您以前沒有任何需要舊版本的項目或代碼,更好的選擇是更新您的scikit-learn軟件包。正如你說,你用巨蟒,以下職位將是有益的:

How to upgrade scikit-learn package in anaconda

+0

我做了:'conda update conda'和'conda install scikit-learn = 0.18',顯示'下面的新軟件包將被安裝:numpy:1.11.2-py27_0 scikit-learn:0.18.1-np111py27_0',然後它提供錯誤'CondaOSError:操作系統錯誤:無法鏈接(src = u'/ Users/Lu/anaconda/pkgs/numpy-1.11.2-py27_0/lib/python2.7/site-packages/numpy/compat/__ init__ .py',dst ='/ Users/Lu/anaconda/lib/python2.7/site-packages/numpy/compat/__ init__.py',type = 1,error = OSError(17,'File exists')) 。 – Echo

+0

@Echo:好,繼續。安裝後再次嘗試您的示例,然後返回給我們並報告結果。 –

+0

我試過'pip uninstall'和'pip install scikit-learn',顯示'安裝成功scikit-learn-0.18.1'。但在Python表演我使用0.17.1 – Echo