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
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐