python 如何把classification_report输出到csv文件

作者:农民小飞侠 时间:2023-01-31 21:02:02 

今天想把classification_report的统计结果输出到文件中,我这里分享一下一个简洁的方式:

我的pandas版本:

pandas 1.0.3

代码:


from sklearn.metrics import classification_report
report = classification_report(y_test, y_pred, output_dict=True)
df = pd.DataFrame(report).transpose()
df.to_csv("result.csv", index= True)

是不是很简单,下面是我导出来的一个结果:

python 如何把classification_report输出到csv文件

补充:sklearn classification_report 输出说明

svm-rbf0.606
precision recall f1-score support
0.0 0.56 0.39 0.46 431
1.0 0.62 0.77 0.69 569
avg / total 0.60 0.61 0.59 1000

最后一行是用support 加权平均算出来的,如0.59 = (431*0.46+569*0.69)/ 1000

来源:https://blog.csdn.net/w5688414/article/details/107458575

标签:python,classification,report,csv
0
投稿

猜你喜欢

  • 浅谈Python的正则表达式

    2022-05-11 00:54:16
  • 常见数据库系统比较 Oracle数据库

    2010-07-28 12:44:00
  • python爬虫基础之简易网页搜集器

    2023-08-25 14:05:17
  • 设计师和美工

    2008-10-27 13:43:00
  • 页面中图像格式的选用之我见

    2007-10-31 18:11:00
  • Python栈的实现方法示例【列表、单链表】

    2023-07-20 15:51:42
  • pyinstaller还原python代码过程图解

    2022-04-09 10:06:59
  • Python内置数据结构列表与元组示例详解

    2021-08-17 21:28:14
  • 删除pandas中产生Unnamed:0列的操作

    2021-07-27 03:12:03
  • ASP操作XML文件的完整实例

    2007-09-26 12:05:00
  • Prometheus开发中间件Exporter过程详解

    2023-04-18 16:14:13
  • 在线Ajax载入动画生成工具 - Loadinfo

    2008-02-18 13:34:00
  • Python 操作mysql数据库查询之fetchone(), fetchmany(), fetchall()用法示例

    2023-07-09 00:11:24
  • 详解python requests中的post请求的参数问题

    2023-09-20 07:50:40
  • asp中access升级到sql server后要做的工作

    2007-08-11 13:35:00
  • python如何实现excel数据添加到mongodb

    2023-05-05 17:23:18
  • OpenCV图像变换之傅里叶变换的一些应用

    2023-12-01 22:11:34
  • server.mappath方法详解

    2023-07-05 08:07:48
  • 基于Python的OCR实现示例

    2021-03-05 20:58:43
  • 使用Pandas将inf, nan转化成特定的值

    2023-04-15 23:36:33
  • asp之家 网络编程 m.aspxhome.com