Tensorflow:自定义错误aggreg

2024-10-01 02:28:15 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我们想要改变Abalone regression example,这样就有了一个额外的求值度量。称为pctWrong的度量等于误差大于1%的预测百分比: === pseudocode === pctWrong = countTrue(if (|y-y_hat|/y > 1%) True else False) / countTotal

=== Python ===
105 # Calculate additional eval metrics
106 eval_metric_ops = {
107     "rmse": tf.metrics.root_mean_squared_error(
108         tf.cast(labels, tf.float64), predictions),
109     "pctWrong": ???
110 }

你将如何定义这样的度量?我找到了tf.metrics.percentage_below(),这可能会有帮助,但我不知道如何使用它。尤其是我不知道如何获得它的values参数。你知道吗


Tags: trueif度量exampletfhatevalmetrics
1条回答
网友
1楼 · 发布于 2024-10-01 02:28:15

更新:毕竟没那么难。下面的代码有点粗糙,但很有效。你知道吗

# Calculate additional eval metrics
ys = tf.cast(labels, tf.float64)
y_hats = predictions
losses = tf.divide(tf.abs(tf.subtract(ys, y_hats)), ys)
accuracies = -losses

eval_metric_ops = {
    "rmse": tf.metrics.root_mean_squared_error(tf.cast(labels, tf.float64), predictions),
    "pctWrong": tf.metrics.percentage_below(accuracies, -0.01)
}

相关问题 更多 >