前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >机器学习: 性能度量

机器学习: 性能度量

作者头像
JNingWei
发布2018-09-28 14:27:30
6360
发布2018-09-28 14:27:30
举报
文章被收录于专栏:JNing的专栏JNing的专栏

介绍

在机器学习中,性能度量主要体现在三个指标: 查准率(P)、查全率(R)、F1 。

代码模板

代码语言:javascript
复制
# 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')

... ...

Note

  • fp: false positive,错误地判断为正例;
  • tp: truly positive,正确地判断为正例。

运用示例

代码语言:javascript
复制
# 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(white_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')

打印结果:

代码语言:javascript
复制
以 二值化结果 作为 预测值, 标注框结果 作为 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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年10月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 介绍
  • 代码模板
  • 运用示例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档