今晚调用sklearn.model_selection时,报错了!百度了一下,发现是scipy.misc中的comb位置已经移到scipy.special中去,有点小坑。
from sklearn.model_selection import train_test_split
D:\anaconda3\lib\site-packages\sklearn\model_selection\__init__.py in <module>()----> 1 from ._split import BaseCrossValidator2 from ._split import KFold3 from ._split import GroupKFold4 from ._split import StratifiedKFold5 from ._split import TimeSeriesSplitD:\anaconda3\lib\site-packages\sklearn\model_selection\_split.py in <module>()23 import numpy as np24 ---> 25 from scipy.misc import comb26 from ..utils import indexable, check_random_state, safe_indexing27 from ..utils.validation import _num_samples, column_or_1dImportError: cannot import name 'comb'
解决方法如下:
在python环境下,可以是Anacanda或python,找到以下两个文件,并打开进行修改:
文件1:lib\site-packages\sklearn\model_selection\_split.py,将文件中的from scipy.misc import comb改为为from scipy.special import comb文件2:lib\site-packages\sklearn\metrics\cluster\supervised.py,将文件中的from scipy.misc import comb改为为from scipy.special import comb
文件中可以ctrl+f 输入关键词快速定位到~~