** TP:(实际为正例,预测也为正例) 实际为男生,预测为男生; FP:(实际为负例,预测为正例) 实际为女生,预测为男生;
FN:(实际为正例,预测为负例) 实际为男生,预测为女生; TN:(实际为负例,预测也为负例) 实际为女生,预测为女生; **
准确率(Accuracy) = (TP + TN) / 总样本 。 定义是: 对于给定的测试数据集,分类器正确分类的样本数与总样本数之比。
精确率(Precision) = TP / (TP + FP)
。它表示:预测为正的样本中有多少是真正的正样本,它是针对我们预测结果而言的。Precision又称为查准率。
召回率(Recall) = TP / (TP + FN) = 40/70 = 57.14% 。它表示:样本中的正例有多少被预测正确了,
它是针对我们原来的样本而言的。Recall又称为查全率。

由于本代码是在输出预测输出图片每个像素的评价指标所写,其他情况,稍作修改即可
sum=128*128*10 def pixlAcc(y_true, y_pred): y_pred=tf.cast(y_pred,dtype=tf.
float32) y_true=tf.cast(y_true,dtype=tf.float32) tfThre=tf.fill(y_pred.shape,0.5
) # 正样本 y_pred=tf.where(tf.greater(y_pred, tfThre), 1.0,0) sum_true_pred=tf.
reduce_sum(y_pred*y_true) #负样本 neg_y_perd=1-y_pred neg_y_true=1-y_true
neg_sum_true_pred=tf.reduce_sum(neg_y_perd*neg_y_true) return (sum_true_pred+
neg_sum_true_pred)/(sum) def PosRecall(y_true, y_pred): y_pred=tf.cast(y_pred,
dtype=tf.float32) y_true=tf.cast(y_true,dtype=tf.float32) tfThre=tf.fill(y_pred.
shape,0.5) y_pred=tf.where(tf.greater(y_pred, tfThre), 1.0,0) true_pos=y_true*
y_pred sum_pos_true=tf.reduce_sum(true_pos) sum_true=tf.reduce_sum(y_true)
return (sum_pos_true)/(sum_true+0.001) def Precision(y_true,y_pred): y_pred=tf.
cast(y_pred,dtype=tf.float32) y_true=tf.cast(y_true,dtype=tf.float32)
#这里的0.5为自己设置的比例,可以自行调整 tfThre=tf.fill(y_pred.shape,0.5) y_pred=tf.where(tf.
greater(y_pred, tfThre), 1.0,0) true_pos=y_true*y_pred sum_pos_true=tf.
reduce_sum(true_pos) sum_pos_pred=tf.reduce_sum(y_pred) return sum_pos_true/
sum_pos_preddef F1_m(y_true, y_pred): y_pred=tf.cast(y_pred,dtype=tf.float32)
y_true=tf.cast(y_true,dtype=tf.float32) rightRadio=Precision(y_true, y_pred)
RecallRadio=PosRecall(y_true, y_pred) return 2.0*rightRadio*RecallRadio/(
rightRadio+RecallRadio+0.001)

技术
今日推荐
PPT
阅读数 126
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信