模型训练指标优化与数据集平衡策略
1. 精度与召回率
1.1 精度的概念
精度(Precision)可以理解为“不确定就不叫”。以普雷斯顿(Preston)为例,它只有确定是窃贼时才会吠叫。从形式上来说,精度是真正例(True Positives)与真正例和假正例(False Positives)并集的比率。普雷斯顿通过将分类阈值尽可能右移,排除尽可能多无趣的负事件,实现了近乎 1.0 的精度,即它吠叫的对象中 99% 都是盗贼。
1.2 在代码中实现精度和召回率
为了在训练过程中跟踪精度和召回率,我们需要更新 logMetrics 函数。具体步骤如下:
1. 计算所需的值:
neg_count = int(negLabel_mask.sum())
pos_count = int(posLabel_mask.sum())
trueNeg_count = neg_correct = int((negLabel_mask & negPred_mask).sum())
truePos_count = pos_correct = int((posLabel_mask & posPred_mask).sum())
falsePos_count = neg_count - neg_correct
falseNeg_count = pos_count - pos_correct
- 计算精度和召回率并存储在
metrics_dict
超级会员免费看
订阅专栏 解锁全文
3万+

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



