nlintz / TensorFlow-Tutorials

Simple tutorials using Google's TensorFlow Framework
6k stars 1.51k forks source link

Linear_regression hasn't scale cost #94

Closed JaledMC closed 6 years ago

JaledMC commented 6 years ago

Hi,

I'm not sure, but cost function should not be scaled by number of elements, to prevent Inf values with big batches?

m = tf.size(Y)
cost = tf.square(Y - y_model) / 2 * m

or this: tf.reduce_mean(tf.squared_difference(prediction, Y))

JaledMC commented 6 years ago

I just saw that you apply this cost function to one sample each step. My fault. Sorry.

The problem is that this solution need a inner loop: for i in range(100): for (x, y) in zip(trX, trY): sess.run(train_op, feed_dict={X: x, Y: y})

You can get rid of one loop with a matrix approach during output calculation. This is more efficient: return tf.matmul(X, w)