2017-02-20 76 views
1

我已經實現了可正常工作的邏輯迴歸。它能夠正確打印出精確度。我顯示的準確性如此...無法使用張量流打印正確的預測

# Test model 
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) 
# Calculate accuracy 
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 

print("Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels})) 

正如我所說,這工作正常。但是,在閱讀完教程後,我知道correct_prediction應該是一組布爾值,它告訴我們我們的預測是否正確。我想打印這個布爾值,但遇到問題。我嘗試以下...

print(correct_prediction) 
>>>Tensor("Equal:0", shape=(?,), dtype=bool) 

,然後我想...

print(sess.run(correct_prediction)) 
>>>InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float 
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]] 

我很新的TensorFlow。我怎樣才能打印出這個變量作爲一系列的預測?

回答

1

您仍然需要輸入數據。試試:

print(correct_prediction.eval({x: mnist.test.images, y: mnist.test.labels}))