在MXNet中可能错误使用自定义评估指标

我正在处理一个问题,并试图使用MXNet来解决。我尝试在代码中使用自定义指标。相关代码如下:

def calculate_sales_from_bucket(bucketArray):    return numpy.asarray(numpy.power(10, calculate_max_index_from_bucket(bucketArray)))def calculate_max_index_from_bucket(bucketArray):    answerArray = []    for bucketValue in bucketArray:        index, value = max(enumerate(bucketValue), key=operator.itemgetter(1))        answerArray.append(index)    return answerArraydef custom_metric(label, bucketArray):    return numpy.mean(numpy.power(calculate_sales_from_bucket(label)-calculate_sales_from_bucket(bucketArray),2))model.fit(    train_iter,         # 训练数据    eval_data=val_iter, # 验证数据    batch_end_callback = mx.callback.Speedometer(batch_size, 1000),    # 每1000个数据批次输出进度    num_epoch = 10,     # 训练数据的传递次数     optimizer = 'adam',    eval_metric = mx.metric.create(custom_metric),    optimizer_params=(('learning_rate', 1),))

我的输出结果是:

INFO:root:Epoch[0] Validation-custom_metric=38263835679935.953125INFO:root:Epoch[1] Batch [1000]      Speed: 91353.72 samples/sec        Train-custom_metric=39460550891.057487INFO:root:Epoch[1] Batch [2000]        Speed: 96233.05 samples/sec  Train-custom_metric=9483.127650INFO:root:Epoch[1] Batch [3000] Speed: 90828.09 samples/sec   Train-custom_metric=57538.891485INFO:root:Epoch[1] Batch [4000] Speed: 93025.54 samples/sec   Train-custom_metric=59861.927745INFO:root:Epoch[1] Train-custom_metric=8351.460495INFO:root:Epoch[1] Time cost=9.466INFO:root:Epoch[1] Validation-custom_metric=38268.250469INFO:root:Epoch[2] Batch [1000]     Speed: 94028.96 samples/sec       Train-custom_metric=58864.659051INFO:root:Epoch[2] Batch [2000]     Speed: 94562.38 samples/sec       Train-custom_metric=9482.873310INFO:root:Epoch[2] Batch [3000]      Speed: 93198.68 samples/sec        Train-custom_metric=57538.891485INFO:root:Epoch[2] Batch [4000]      Speed: 93722.89 samples/sec        Train-custom_metric=59861.927745INFO:root:Epoch[2] Train-custom_metric=8351.460495INFO:root:Epoch[2] Time cost=9.341INFO:root:Epoch[2] Validation-custom_metric=38268.250469

在这种情况下,尽管批次的训练自定义指标发生了变化,但训练自定义指标仍然保持不变。例如,在第1个和第2个epoch的第1000批次中就是如此。

我认为这是一个问题,因为无论epoch步骤的值如何,训练自定义指标和验证自定义指标都没有变化。我是MXNet的新手,我的假设可能有误。

你能确认我传递eval_metric的方式是否正确吗?


回答:

我不确定我是否理解了你的问题。你的输出显示训练自定义指标给出了不同的值,只是碰巧在每个epoch的最后两个批次中给出了相同的结果。这可能是你的模型收敛方式的一个特点。

需要明确的一点是,eval_metric仅用于提供调试输出——它实际上并不在学习过程中用作损失函数:

https://github.com/apache/incubator-mxnet/issues/1915

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注