我想从sklearn导入StratifiedKFold来进行交叉验证。我的电脑使用scikit-learn 0.18。在python控制台中,我输入:
from sklearn.model_selection import StratifiedKFold
弹出以下错误信息:
File "<ipython-input-307-7880cb661350>", line 1, in <module>
from sklearn.model_selection import StratifiedKFold
File "C:UsersuserAnaconda2libsite-packagessklearnmodel_selection__init__.py", line 1, in <module>
from ._split import BaseCrossValidator
File "C:UsersuserAnaconda2libsite-packagessklearnmodel_selection_split.py", line 35, in <module>
from ..gaussian_process.kernels import Kernel as GPKernel
File "C:UsersuserAnaconda2libsite-packagessklearngaussian_process__init__.py", line 13, in <module>
from .gpr import GaussianProcessRegressor
File "C:UsersuserAnaconda2libsite-packagessklearngaussian_processgpr.py", line 15, in <module>
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C
File "C:UsersuserAnaconda2libsite-packagessklearngaussian_processkernels.py", line 30, in <module>
from ..metrics.pairwise import pairwise_kernels
File "C:UsersuserAnaconda2libsite-packagessklearnmetrics__init__.py", line 7, in <module>
from .ranking import auc
File "C:UsersuserAnaconda2libsite-packagessklearnmetricsranking.py", line 30, in <module>
from ..utils.extmath import stable_cumsum
ImportError: cannot import name stable_cumsum
问题已解决:
删除scikit-learn:
conda remove scikit-learn
然后重新安装:
pip install -U scikit-learn