机器学习: 性能度量
2017-10-28 19:56
363 查看
介绍
在机器学习中,性能度量主要体现在三个指标: 查准率(P)、查全率(R)、F1 。代码模板
# coding=utf-8 import sys reload(sys) sys.setdefaultencoding('utf-8') ... ... def performance(tp, fn, fp, tn): # 查准率 P = tp / float(tp + fp) # 查全率 R = tp / float(tp + fn) # F1 F1 = (2 * P * R) / (P + R) # print P, R, F1 return P, R, F1 ... ... P, R, F1 = performance(white_pixels, red_pixels, green_pixels, black_pixels) print '查准率 P = {:>.3f}, 查全率 R = {:>.3f}, F1 = {:>.3f}'.format(P, R, F1).encode('gb18030') ... ...
运用示例
# coding=utf-8 import sys reload(sys) sys.setdefaultencoding('utf-8') diff_path = './data/diff.jpg' black_pixels, white_pixels, green_pixels, red_pixels = 29158, 530899, 75994, 3949 sum_pixels = 640000 def performance(tp, fn, fp, tn): # 查准率 P = tp / float(tp + fp) # 查全率 R = tp / float(tp + fn) # F1 F1 = (2 * P * R) / (P + R) # print P, R, F1 return P, R, F1 def occupancy_cal(a, b): result = (a + b) / float(sum_pixels) return result def loss_cal(a, b): result = (a - b) / float(a) return result print '以 二值化结果 作为 预测值, 标注框结果 作为 ground_truth 时:'.encode('gb18030') truth, predict = occupancy_cal(w 4000 hite_pixels, red_pixels), occupancy_cal(white_pixels, green_pixels) loss = loss_cal(truth, predict) print '实际 横截面区域 占图像 {:>.3f}, 预测值为 {:>.3f}, 损失比例为 {:>.3f}'.format(truth, predict, loss).encode('gb18030') P, R, F1 = performance(white_pixels, red_pixels, green_pixels, black_pixels) print '查准率 P = {:>.3f}, 查全率 R = {:>.3f}, F1 = {:>.3f}'.format(P, R, F1).encode('gb18030') print print '以 标注框结果 作为 预测值, 二值化结果 作为 ground_truth 时:'.encode('gb18030') truth, predict = occupancy_cal(white_pixels, green_pixels), occupancy_cal(white_pixels, red_pixels) loss = loss_cal(truth, predict) print '实际 横截面区域 占图像 {:>.3f}, 预测值为 {:>.3f}, 损失比例为 {:>.3f}'.format(truth, predict, loss).encode('gb18030') P, R, F1 = performance(white_pixels, green_pixels, red_pixels, black_pixels) print '查准率 P = {:>.3f}, 查全率 R = {:>.3f}, F1 = {:>.3f}'.format(P, R, F1).encode('gb18030')
打印结果:
以 二值化结果 作为 预测值, 标注框结果 作为 ground_truth 时: 实际 横截面区域 占图像 0.836, 预测值为 0.948, 损失比例为 -0.135 查准率 P = 0.875, 查全率 R = 0.993, F1 = 0.930 以 标注框结果 作为 预测值, 二值化结果 作为 ground_truth 时: 实际 横截面区域 占图像 0.948, 预测值为 0.836, 损失比例为 0.119 查准率 P = 0.993, 查全率 R = 0.875, F1 = 0.930
相关文章推荐
- 机器学习之分类模型的性能度量
- 【机器学习-西瓜书】九、聚类:性能度量;距离计算
- 机器学习笔记 - 性能度量
- 机器学习:算法性能度量之查准率与查全率
- 机器学习之性能度量
- 机器学习笔记(六)性能度量
- 机器学习中性能度量(错诶率、精度、查准率、查全率、F)
- 机器学习知识点(三十六)分类器性能度量指标f1-score
- 机器学习之性能度量
- 【机器学习-西瓜书】二、性能度量:召回率;P-R曲线;F1值;ROC;AUC
- 机器学习之性能度量
- 机器学习性能度量指标:AUC
- 说说那些机器学习中的性能度量方式
- 机器学习 —— 性能度量和比较检验、模型评估方法
- 机器学习之分类性能度量指标 : ROC曲线、AUC值、正确率、召回率
- 机器学习模型性能度量
- 【机器学习】分类性能度量指标 : ROC曲线、AUC值、正确率、召回率、敏感度、特异度
- 机器学习实战笔记(Python实现)-07-模型评估与分类性能度量
- 机器学习模型性能度量
- 周志华《机器学习》 学习笔记(四) 性能度量