title: TensorFlow: implementing Mean Squared Error
body: <p>I'm currently learning TensorFlow and came across with <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/linear_regression.ipynb" rel="nofollow noreferrer">this notebook</a>.</p>
  
  <p>I have a question with how the mean squared error cost function is implemented:</p>
  
  <pre><code>import tensorflow as tf 
  import numpy as np 
  
  predicted = np.array([1,2,3])
  Y = np.array([4,5,6])
  num_instances = predicted.shape[0]
  
  cost = tf.reduce_sum(tf.pow(predicted-Y, 2))/(2*num_instances)
  cost2 = tf.reduce_mean(tf.square(predicted - Y))
  
  with tf.Session() as sess:
    print(sess.run(cost))
    print(sess.run(cost2))
  </code></pre>
  
  <p>I don't get it why does it have to multiply the denominator of 1st cost function to 2. I got different answers from the different implementations of MSE, cost yields 4.5 while cost2 yields 9. following the formula of the mean squared error, I should get a value of 9. but the 1st cost function is the one that is implemented in the python notebook that I'm trying to learn. </p>