- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在解决一个问题,并尝试使用 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 answerArray
def custom_metric(label, bucketArray):
return numpy.mean(numpy.power(calculate_sales_from_bucket(label)-calculate_sales_from_bucket(bucketArray),2))
model.fit(
train_iter, # training data
eval_data=val_iter, # validation data
batch_end_callback = mx.callback.Speedometer(batch_size, 1000), # output progress for each 1000 data batches
num_epoch = 10, # number of data passes for training
optimizer = 'adam',
eval_metric = mx.metric.create(custom_metric),
optimizer_params=(('learning_rate', 1),)
)
我得到的输出为:
INFO:root:Epoch[0] Validation-custom_metric=38263835679935.953125
INFO:root:Epoch[1] Batch [1000] Speed: 91353.72 samples/sec Train-custom_metric=39460550891.057487
INFO:root:Epoch[1] Batch [2000] Speed: 96233.05 samples/sec Train-custom_metric=9483.127650
INFO:root:Epoch[1] Batch [3000] Speed: 90828.09 samples/sec Train-custom_metric=57538.891485
INFO:root:Epoch[1] Batch [4000] Speed: 93025.54 samples/sec Train-custom_metric=59861.927745
INFO:root:Epoch[1] Train-custom_metric=8351.460495
INFO:root:Epoch[1] Time cost=9.466
INFO:root:Epoch[1] Validation-custom_metric=38268.250469
INFO:root:Epoch[2] Batch [1000] Speed: 94028.96 samples/sec Train-custom_metric=58864.659051
INFO:root:Epoch[2] Batch [2000] Speed: 94562.38 samples/sec Train-custom_metric=9482.873310
INFO:root:Epoch[2] Batch [3000] Speed: 93198.68 samples/sec Train-custom_metric=57538.891485
INFO:root:Epoch[2] Batch [4000] Speed: 93722.89 samples/sec Train-custom_metric=59861.927745
INFO:root:Epoch[2] Train-custom_metric=8351.460495
INFO:root:Epoch[2] Time cost=9.341
INFO:root:Epoch[2] Validation-custom_metric=38268.250469
在这种情况下,无论批处理的 train-custom_metric 发生变化,train-custom_metric 仍然相同。就像 epoch 1 和 epoch 2 的批处理 1000 一样。
我认为这是一个问题,因为无论纪元步骤的值如何,Train-custom_metric和Validation-custom_metric都不会改变。我是 MXNet 的初学者,这个假设可能是错误的。
您能否确认我是否以正确的方式传递了 eval_metric?
最佳答案
不确定我是否理解这个问题。您的输出显示 train-custom-metric 给出了不同的值,它恰好为每个时期的最后两批给出了相同的结果。这可能只是您的模型收敛方式的一个怪癖。
需要明确的一件事是 eval_metric 仅用于提供调试输出 - 它实际上在学习过程中并不用作损失函数:
关于machine-learning - MXNet 中自定义 eval_metric 的使用可能不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45592174/
如何在 MXNET 中创建自定义损失函数?例如,我不想计算一个标签的交叉熵损失(使用标准 mx.sym.SoftmaxOutput 层计算交叉熵损失并返回一个可以作为损失符号传递给拟合函数的符号),而
我尝试在 XgBoost 中使用 eval_metric 参数,但收到此错误: TypeError: fit() got an unexpected keyword argument 'eval_me
我正在解决一个问题,并尝试使用 MXNet 来解决。我试图在代码中使用自定义指标。相同的代码是: def calculate_sales_from_bucket(bucketArray): r
我正在尝试使用 XGBoost ,并将 eval_metric 优化为 auc(如 here 所述)。 这在直接使用分类器时工作正常,但在我尝试将其用作 pipeline 时失败了. 将 .fit 参
选择 auc、error 或 logloss 作为 XGBoost 的 eval_metric 对其性能有何影响?假设数据不平衡。它如何影响准确度、召回率和精确度? 最佳答案 在不同的评估矩阵 之间进
我是一名优秀的程序员,十分优秀!