# 1. ROC 计算产生 fpr, tpr, threshold
fpr, tpr, thresholds = roc_curve(label, pred)
# 2. 指定要写入的文件名(csv无需自己创建)
file_name = 'fpr_tpr_threshold.csv'
# 3. 写入
csvfile = open(file_name, 'wt', encoding="UTF8")
writer = csv.writer(csvfile, delimiter=",")
# 标题行写入
header = ['fpr', 'tpr', 'thresholds']
# 数据写入
csvrow1 = []
csvrow2 = []
csvrow3 = []
csvrow1.extend(fpr)
csvrow2.extend(tpr)
csvrow3.extend(thresholds)
writer.writerow(header)
writer.writerows(zip(csvrow1, csvrow2, csvrow3))
csvfile.close()
Python 将多列数据写入 csv,并写入标题行
最新推荐文章于 2023-10-24 09:22:15 发布
该博客介绍了如何使用ROC曲线来评估模型性能,并详细展示了如何将ROC曲线中的fpr、tpr和thresholds数据保存到CSV文件中,以便后续分析和使用。
1546

被折叠的 条评论
为什么被折叠?



