在TensorFlow中,tf.losses.log_loss(labels, predictions)的输入是标签和预测值。

3

有人可以给一些例子吗? 官方文档中没有指南。 我想知道标签和预测的类型是什么? 谢谢。

1个回答

1
输入是张量,第一个包含数据点的正确预测,第二个是模型给出的实际预测。这些张量可以表示单个数据点(如示例所示)或批次。它们必须具有相同的形状。
示例:
import tensorflow as tf

""" Minimal example """
with tf.Session() as sess:
    loss = tf.losses.log_loss(tf.Variable([0., 1., 0.]), tf.Variable([0.1, 0.8, 0.1]))
    sess.run(tf.global_variables_initializer())
    result = sess.run(loss)
    print('Minimal example loss: %f' % result)

tf.reset_default_graph()

""" More realistic example """
with tf.Session() as sess:
    # Create placeholders for inputs
    X_placeholder = tf.placeholder(tf.float32, [3])
    y_placeholder = tf.placeholder(tf.float32, [3])

    # Set up the model structure, resulting in a set of predictions
    predictions = tf.multiply(X_placeholder, 2.)

    # Compute the loss of the calculated predictions
    loss = tf.losses.log_loss(y_placeholder, predictions)

    # Run the loss tensor with values for the placeholders
    result = sess.run(loss, feed_dict={X_placeholder: [0.5, 0.5, 0.5], y_placeholder: [0., 1., 0.]})
    print('Realistic example loss: %f' % result)

2
“predictions” 是指对数几率或 softmax 概率吗?如果是,为什么这很重要? - mynameisvinn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接