Reputation: 685
I am trying to import sklearn.model_selection
. I have tried to reinstall scikit-learn and anaconda, still not working.
Here is the error msg I got:
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
Upvotes: 11
Views: 53761
Reputation: 12321
Check your scikit-learn version;
import sklearn
print(sklearn.__version__)
sklearn.model_selection
is available for version 0.18.1.
What you need to import depends on what you require. For instance, in version 0.18.1, GridSearchCV
can be imported as
from sklearn.model_selection import GridSearchCV
Whereas in version 0.17.1, the same can be imported as
from sklearn.grid_search import GridSearchCV
If you find anything in the new scikit documentation that doesn't work for you in your system, then search the document for the current version you are using. The import path might be different but the overall functionality ought to be the same.
If you don't have any previous projects or code that requires the older version, the better option would be to update your scikit-learn package. As you stated that you use Anaconda, the following post would be useful:
How to upgrade scikit-learn package in anaconda
Upvotes: 11