[代码] tensorflow代码段
参考 tf.metrics.mean, 编写一个广告中常用的pcoc 度量,在tf.esitmator 模型中使用
class Kmetrics(object):
@staticmethod
def pcoc(labels, predictions, weights=None, updates_collections=None, name=None):
with tf.variable_scope(name, 'pcoc', (labels, predictions, weights)):
y, y_op = tf.metrics.mean(labels, weights=weights)
p, p_op = tf.metrics.mean(predictions, weights=weights)
pcoc_value = tf.abs(p / (y + 1e-8) - 1, 'pcoc_value')
update_op = tf.abs(p_op / (y_op + 1e-8) - 1, 'update_op')
if updates_collections:
tf.add_to_collections(updates_collections, update_op)
return pcoc_value, update_op