【问题标题】:Tensorflow basic titanic example: accuracy stuckTensorflow基本的泰坦尼克号例子:准确性卡住了
【发布时间】:2017-09-02 07:21:58
【问题描述】:

我正在尝试对 TensorFlow 进行自我教育。我决定在 tensorflow 中实现臭名昭著的 kaggle titanic 挑战,不使用 tf.layers、tf.train 或 keras。我正在使用可能是一个可笑的超大网络。我的问题是我似乎无法正确计算准确度。

在我的示例中,Y 是我最后一层(宽度为 1)的输出。 Y_ 是该训练示例的标签。因此,当我计算准确性时,我将其计算为:

Y_int = tf.cast(Y_, tf.int64)
is_correct = tf.equal(tf.argmax(Y,1),Y_int)

accuracy = tf.reduce_mean(tf.cast(is_correct,tf.float32))

我每 500 次迭代运行一次: a,c = sess.run([accuracy,xe], feed_dict=test_data)

交叉熵“很好地”减少了 - 有很大的改进空间,但它确实会改变迭代。然而,准确度却被顽固地卡住了(这是第一个值):

迭代:0

0.606742 72.3839

迭代:500

0.606742 42.3199

迭代:1000

.....

迭代:18500

0.606742 38.2022

迭代:19000

0.606742 38.4258

迭代:19500

0.606742 37.9204

编辑:完整的 python 文件: https://github.com/mrx80/so/blob/master/titanic_nn.py

【问题讨论】:

  • 你能给出一个iter的Y和Y_的实际值吗?
  • 给你:0.651685 32.1792 Y:: [[ -9.14530421e-04] [ 1.29497278e+00] [ -9.14530421e-04] [ 1.02632809e+00] [ 3.94688576e-01] [ 9.22473788e-01] [ -9.14530421e-04] [ -9.14530421e-04] [ 1.29656982e+00] [ 1.06453359e+00]] Y_: [[0] [1] [0] [1] [1 ] [1] [0] [0] [1] [1]]

标签: tensorflow


【解决方案1】:

好的,我想通了,感谢上面天津的提示。我在检查 Y 和 Y_ 的相等性之前四舍五入:

Y_int = tf.cast(Y, tf.float32)
is_correct = tf.equal(tf.round(Y_int),Y_)

【讨论】:

    猜你喜欢
    • 2016-06-19
    • 2022-01-03
    • 2020-10-25
    • 2019-03-01
    • 1970-01-01
    • 2018-10-24
    • 2017-06-27
    • 2021-07-29
    • 1970-01-01
    相关资源
    最近更新 更多