2
votes

I'm trying to educate myself on tensorflow. I decided to implement the infamous kaggle titanic challenge in tensorflow, without using tf.layers, tf.train, or keras. I'm using what's probably a comically oversized network. My problem is that I can't seem to get the accuracy calculation correct.

In my example, Y is the output of my final layer (width 1). Y_ is the label of that training example. So, when I compute accuracy, I compute it as:

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))

I run it every 500 iterations: a,c = sess.run([accuracy,xe], feed_dict=test_data)

Cross entropy reduces "nicely" - there's lots of room for improvement, but it does change iteration to iteration. Accuracy, though, is stubbornly stuck (it's the first value):

iter: 0

0.606742 72.3839

iter: 500

0.606742 42.3199

iter: 1000

.....

iter: 18500

0.606742 38.2022

iter: 19000

0.606742 38.4258

iter: 19500

0.606742 37.9204

EDIT: the full python file: https://github.com/mrx80/so/blob/master/titanic_nn.py

1
Can you give the actual value of Y and Y_ for one iter? - Tianjin Gu
Here you go: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]] - Madhu

1 Answers

0
votes

OK, I figured it out, thanks to Tianjin's hint above. I rounded before checking the equality of Y and Y_:

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