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

sklearn 1.0.2版本无法导入regression_report的问题求助

sklearn 1.0.2中ImportError: cannot import name 'regression_report'的解决方法

问题复现

执行以下代码时触发错误:

from sklearn.metrics import regression_report,confusion_matrix
print(confusion_matrix(y_train,predict_train))
print(Regression_report(y_train,predict_train))

报错信息:

ImportError: cannot import name 'regression_report' from 'sklearn.metrics' (C:\Users\charl\Anaconda\lib\site-packages\sklearn\metrics_init_.py)

解决步骤

  • 核心原因:sklearn的metrics模块不存在regression_report这个函数。结合你用到的confusion_matrix(分类任务专用指标),你实际需要的是分类任务的评估报告函数classification_report;同时Python对大小写敏感,你代码里的Regression_report也是错误写法。
  • 代码修正:
    1. 修改导入语句:
      from sklearn.metrics import classification_report, confusion_matrix
      
    2. 修改函数调用行:
      print(classification_report(y_train, predict_train))
      

如果实际是做回归任务,sklearn提供了r2_score、mean_squared_error、mean_absolute_error等回归评估指标,按需导入使用即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 17:20:36