我正在尝试在我的估算器的 eval_metric_ops 中添加 r 平方,如下所示:
def model_fn(features, labels, mode, params):
predict = prediction(features, params, mode)
loss = my_loss_fn
eval_metric_ops = {
'rsquared': tf.subtract(1.0, tf.div(tf.reduce_sum(tf.squared_difference(label, tf.reduce_sum(tf.squared_difference(labels, tf.reduce_mean(labels)))),
name = 'rsquared')
}
train_op = tf.contrib.layers.optimize_loss(
loss = loss,
global_step = global_step,
learning_rate = 0.1,
optimizer = "Adam"
)
predictions = {"predictions": predict}
return tf.estimator.EstimatorSpec(
mode = mode,
predictions = predictions,
loss = loss,
train_op = train_op,
eval_metric_ops = eval_metric_ops
)
但我有以下错误:
TypeError: eval_metric_ops 的值必须是 (metric_value, update_op) 元组,给定: Tensor("rsquared:0", shape=(), dtype=float32) for key: rsquared
我也尝试不使用 name 参数,但没有改变任何东西。你知道如何创建这个 eval_metric_ops 吗?