我试图理解正式文档上的逻辑回归代码,但我很难理解这段代码背后的逻辑:
# early-stopping parameters
patience = 5000 # look as this many examples regardless
patience_increase = 2 # wait this much longer when a new best is
# found
improvement_threshold = 0.995 # a relative improvement of this much is
# considered significant
validation_frequency = min(n_train_batches, patience/2)
# go through this many
# minibatches before checking the network
# on the validation set; in this case we
# check every epoch
best_params = None
best_validation_loss = numpy.inf
test_score = 0.
start_time = time.clock()
done_looping = False
epoch = 0
while (epoch < n_epochs) and (not done_looping):
# Report "1" for first epoch, "n_epochs" for last epoch
epoch = epoch + 1
for minibatch_index in xrange(n_train_batches):
d_loss_wrt_params = ... # compute gradient
params -= learning_rate * d_loss_wrt_params # gradient descent
# iteration number. We want it to start at 0.
iter = (epoch - 1) * n_train_batches + minibatch_index
# note that if we do `iter % validation_frequency` it will be
# true for iter = 0 which we do not want. We want it true for
# iter = validation_frequency - 1.
if (iter + 1) % validation_frequency == 0:
this_validation_loss = ... # compute zero-one loss on validation set
if this_validation_loss < best_validation_loss:
# improve patience if loss improvement is good enough
if this_validation_loss < best_validation_loss * improvement_threshold:
patience = max(patience, iter * patience_increase)
best_params = copy.deepcopy(params)
best_validation_loss = this_validation_loss
if patience <= iter:
done_looping = True
break任何一个人,向我解释,变量:耐心,patience_increase,improvement_threshold,validation_frequency,iter代表什么?
这种情况会怎样?
if (iter + 1) % validation_frequency == 0:发布于 2015-12-12 23:10:13
Patience是停止前要做的训练批次的数量。iter是你见过的训练批次的数量。每次迭代时,您都会决定您的验证是否低于以前的最佳值。只有当分数低于improvement_threshold * validation_score时,改进才会被存储。
看来patience_increase是一个乘数。每次获得新的最低分数时,您都会将总数或培训批次提高到iter*patience_increase,但不低于patience的当前值。
validation_frequency只是检查验证分数之间的批数。
https://datascience.stackexchange.com/questions/9355
复制相似问题