问题描述
我正在学习逻辑回归,我想在通过梯度下降最小化过程中计算交叉熵损失函数的值是多少,但是当我使用 tensorflow 的 sigmoid_cross_entropy_with_logits 函数时,我得到的结果与我自己得到的结果不同表达。
这是一个例子:
import numpy as np
import tensorflow as tf
pred = np.array([[0.2],[0.3],[0.4]])
test_y = np.array([[0.5],[0.6],[0.7]])
print(tf.nn.sigmoid_cross_entropy_with_logits(logits = pred,labels = test_y))
print(-test_y * tf.math.log(pred) - (1-test_y) * tf.math.log(1-pred))
输出:
tf.Tensor(
[[0.69813887]
[0.67435524]
[0.63301525]],shape=(3,1),dtype=float64)
tf.Tensor(
[[0.91629073]
[0.86505366]
[0.7946512 ]],dtype=float64)
谁能给我解释一下这有什么问题?我查看了有关其功能的 tensorflow 文档,看起来它应该与我的表达式完全相同。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)