找出所有epoch中指标的最大值【tips】

跑深度学习训练时,需要找到指标最好的模型作为训练结果,可以使用下面的程序寻找。

解释:roc_auc_score:求任一评价指标的函数,返回的是一个数值

s_obs = Score_Observer('AUROC') 
s_obs.update(roc_auc_score(is_anomaly, anomaly_score), epoch,
                             print_score=True)
class Score_Observer:

    def __init__(self, name):
        self.name = name
        self.max_epoch = 0
        self.max_score = 0
        self.last = 0

    def update(self, score, epoch, print_score=False):
        self.last = score
        if self.max_score == None or score > self.max_score:
            self.max_score = score
            self.max_epoch = epoch
        if print_score:
            self.print_score()

    def print_score(self):
        print('{:s}: \t last: {:.4f} \t max: {:.4f} \t epoch_max: {:d}'.format(self.name, self.last, self.max_score, self.max_epoch))                                                                                                                                                                         

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值