早停法的应用(keras)

前提

在解决过拟合问题中,有许多的方法可以使用,其中有一个方法叫早停法,这篇文章就是以 keras API 为例展示如何使用早停法

callback

在应用早停法时需要使用 callback 回调函数,进行初始化

cb = callback()

而在 model.fit 中可以使用 callback

model.fit(callback=[cb])

early stopping

keras中有EarlyStopping这个api,官方文档
进行初始化

keras.callbacks.callbacks.EarlyStopping(monitor=
'val_loss', min_delta=0, patience=0, verbose=0, m
ode='auto',baseline=None, restore_best_weights=Fal
se)

初始化

es = EarlyStopping()

arguments


monitor: quantity to be monitored.
min_delta: minimum change in the monitored quantity to qualify as an improvement, i.e. an absolute change of less than min_delta, will count as no improvement.
patience: number of epochs that produced the monitored quantity with no improvement after which training will be stopped. Validation quantities may not be produced for every epoch, if the validation frequency (model.fit(validation_freq=5)) is greater than one.
verbose: verbosity mode.
mode: one of {auto, min, max}. In min mode, training will stop when the quantity monitored has stopped decreasing; in max mode it will stop when the quantity monitored has stopped increasing; in auto mode, the direction is automatically inferred from the name of the monitored quantity.
baseline: Baseline value for the monitored quantity to reach. Training will stop if the model doesn’t show improvement over the baseline.
restore_best_weights: whether to restore model weights from the epoch with the best value of the monitored quantity. If False, the model weights obtained at the last step of training are used.


在这个api中重要的是monitor和mode两个属性
monitor是一个监视器,可以用来监视模型的性能,有几个参数可以使用(比如val_accuracy和val_loss),而mode中中有auto、min、max三个属性,min代表着你想要监视的性能最小,而max则相反,auto会根据你的monitor属性自动选择

其他属性:

patience:表示可以等待的epochs,就是在多少patience次epochs之后没有改进便早停
baseline:在微调模型中使用的比较多,代表着在这个基准之上或者之下才可以停止培训,经常用于改善模型
min_delta:性能指标只有高于此属性才被看作一次改进

应用:

监控loss属性(mode='min)
es = EarlyStopping(monitor='val_loss', mode='min')
监控accuracy(mode='max)
es = EarlyStopping(monitor='val_accuracy', mode='max', min_delta=1)
设置baseline
es = EarlyStopping(monitor='val_loss', mode='min', baseline=0.4)

如果想要得到更详细的解释:可以移步此链接

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值