使用AutoML库EvalML时遇ImportError问题求解决方案
这个错误是因为EvalML依赖的Featuretools版本与当前安装的Featuretools版本不兼容——EvalML试图从featuretools.primitives导入DiversityScore,但该类在当前Featuretools版本中已被移除或转移到其他模块。以下是可行的解决方案:
匹配Featuretools与EvalML的兼容版本
先查看EvalML官方要求的Featuretools依赖版本:pip show evalml在输出的
Requires字段中找到Featuretools的版本范围,然后安装对应版本的Featuretools:pip install featuretools==[指定兼容版本号]例如,若EvalML 0.40.x要求Featuretools 1.10.x,执行
pip install featuretools==1.10.0即可。降级EvalML到兼容版本
若不想改动Featuretools版本,可降级EvalML到与当前Featuretools匹配的版本。先确认当前Featuretools版本:pip show featuretools再查找EvalML的版本历史,找到依赖该Featuretools版本的EvalML版本并安装:
pip install evalml==[指定兼容版本号]临时手动修正导入路径(不推荐)
若Featuretools只是将DiversityScore转移到了子模块(比如featuretools.primitives.natural_language),可临时修改EvalML的导入文件:
打开路径/usr/local/lib/python3.10/dist-packages/evalml/pipelines/components/transformers/preprocessing/natural_language_featurizer.py,将第5行的导入语句修改为:from featuretools.primitives.natural_language import DiversityScore注意:此方法在重新安装EvalML后会失效,仅适合临时应急使用。
内容的提问来源于stack exchange,提问作者Dibyajyoti Sahoo

