ImportError: cannot import name ‘if_delegate_has_method‘ from ‘sklearn.utils.metaestimators‘解决
·
ImportError: cannot import name ‘if_delegate_has_method’ from ‘sklearn.utils.metaestimators’ (D:\anaconda\lib\site-packages\sklearn\utils\metaestimators.py)问题解决
在使用SMOTE算法的时候出现了这个问题,查阅网上的资料都说是if_delegate_has_method 在sklearn1.1.3时被舍弃了,需要在permutation_imporance.py文件中将所有if_delegate_has_method 替换为 available_if,但是我找遍了permutation_imporance.py也没有发现if_delegate_has_method。
所以尝试自己来解决这个问题:
检查报错结果
在metaestimators.py中没有找到,甚至发现里面已经改成available_if了。所以查看了报错过程,发现提到了imblearn下面的pipeline.py这个文件。
进入pipeline.py
在库的调入这里发现了if_delegate_has_method,后续也看到了if_delegate_has_method用在哪里


所以把这里的所有的if_delegate_has_method都改为available_if。如图所示


出现了第二个问题
上面的报错消失了,但是出现了其他一个问题: ‘NoneType’ object has no attribute ‘split’
解决办法就是cmd进入anaconda环境下,输入conda list查看 scikit-learn 和 threadpoolctl 的版本。
conda list


这里我只将threadpoolctl版本升级了
pip install threadpoolctl==3.1.0
更多推荐
所有评论(0)