You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法从sklearn.metrics导入plot_precision_recall_curve问题求助

解决无法导入plot_precision_recall_curve的问题

1. 检查scikit-learn版本兼容性

plot_precision_recall_curve在scikit-learn 1.2及以上版本中,已从sklearn.metrics迁移到sklearn.metrics.plot模块下。若你的scikit-learn版本是1.2+,直接从sklearn.metrics导入必然报错。

  • 查看当前版本:
    pip show scikit-learn
    
  • 若版本≥1.2,修改导入语句:
    from sklearn.metrics.plot import plot_precision_recall_curve
    
  • 若需保留原导入方式,可降级到1.1.x版本:
    pip install scikit-learn==1.1.3
    

2. 确认VSCode使用的Python环境

VSCode可能未切换到你重装scikit-learn的目标环境:

  • 点击VSCode左下角的Python环境选择器,确认选中的是路径为\Programs\Python\Python311的Python311环境。
  • 若环境不对,切换后重启VSCode或通过快捷键Ctrl+Shift+P选择"Reload Window"重新加载窗口。

3. 彻底清理残留后重装

若上述方法无效,尝试彻底清理残留文件后重新安装:

  • 卸载scikit-learn:
    pip uninstall -y scikit-learn
    
  • 手动删除\Programs\Python\Python311\Lib\site-packages下所有包含sklearn或scikit_learn的文件夹与文件。
  • 重新安装指定版本:
    pip install scikit-learn==1.1.3  # 或你需要的对应版本
    

内容的提问来源于stack exchange,提问作者Ilham Kurniawan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 19:02:12