title: Linear regression model accuracy is always 1.0 in tensorflow
body: <blockquote>
  <p><em><strong>Problem:</strong></em></p>
  <p>I am building a model that will predict housing price. So, firstly I
  decided to build a Linear regression model in Tensorflow. But when I
  start training I see that my accuracy is always 1</p>
  </blockquote>
  <p><em>I am new to machine learning. Please, someone, tell me what's going wrong I can't figure it out. I searched in google but doesn't find any answer that solves my problem.</em></p>
  <p>Here's my code</p>
  <pre><code>df_train = df_train.loc[:, ['OverallQual', 'GrLivArea', 'GarageArea', 'SalePrice']]
  df_X = df_train.loc[:, ['OverallQual', 'GrLivArea', 'GarageArea']]
  df_Y = df_train.loc[:, ['SalePrice']]
  df_yy = get_dummies(df_Y)
  print(&quot;Shape of df_X: &quot;, df_X.shape)
  
  X_train, X_test, y_train, y_test = train_test_split(df_X, df_yy, test_size=0.15)
  X_train = np.asarray(X_train).astype(np.float32)
  X_test = np.asarray(X_test).astype(np.float32)
  y_train = np.asarray(y_train).astype(np.float32)
  y_test = np.asarray(y_test).astype(np.float32)
  
  
  X = tf.placeholder(tf.float32, [None, num_of_features])
  y = tf.placeholder(tf.float32, [None, 1])
  
  W = tf.Variable(tf.zeros([num_of_features, 1]))
  b = tf.Variable(tf.zeros([1]))
  
  prediction = tf.add(tf.matmul(X, W), b)
  num_epochs = 20000
  # calculating loss
  cost = tf.reduce_mean(tf.losses.softmax_cross_entropy(onehot_labels=y, logits=prediction))
  
  optimizer = tf.train.GradientDescentOptimizer(0.00001).minimize(cost)
  
  correct_prediction = tf.equal(tf.argmax(prediction, axis=1), tf.argmax(y, axis=1))
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  
  with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  for epoch in range(num_epochs):
      if epoch % 100 == 0:
          train_accuracy = accuracy.eval(feed_dict={X: X_train, y: y_train})
          print('step %d, training accuracy %g' % (epoch, train_accuracy))
          optimizer.run(feed_dict={X: X_train, y: y_train})
  
  print('test accuracy %g' % accuracy.eval(feed_dict={
  X: X_test, y: y_test}))
  </code></pre>
  <p>Output is:</p>
  <pre><code>step 0, training accuracy 1
  step 100, training accuracy 1
  step 200, training accuracy 1
  step 300, training accuracy 1
  step 400, training accuracy 1
  step 500, training accuracy 1
  step 600, training accuracy 1
  step 700, training accuracy 1
  ............................
  ............................
  step 19500, training accuracy 1
  step 19600, training accuracy 1
  step 19700, training accuracy 1
  step 19800, training accuracy 1
  step 19900, training accuracy 1
  test accuracy 1
  </code></pre>
  <p><em><strong>EDIT:</strong></em>
  I changed my cost function to this</p>
  <pre><code>cost = tf.reduce_sum(tf.pow(prediction-y, 2))/(2*1241)
  </code></pre>
  <p>But still my output is always 1.</p>
  <p><em><strong>EDIT 2:</strong></em>
  <em>In response to lejlot comment:</em>
  Thanks lejlot. I changed my accuracy code to this</p>
  <pre><code>with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  merged_summary = tf.summary.merge_all()
  writer = tf.summary.FileWriter(&quot;/tmp/hpp1&quot;)
  writer.add_graph(sess.graph)
  
  for epoch in range(num_epochs):
      if epoch % 5:
          s = sess.run(merged_summary, feed_dict={X: X_train, y: y_train})
          writer.add_summary(s, epoch)
      sess.run(optimizer,feed_dict={X: X_train, y: y_train})
      if (epoch+1) % display_step == 0:
          c = sess.run(cost, feed_dict={X: X_train, y: y_train})
          print(&quot;Epoch:&quot;, '%04d' % (epoch+1), &quot;cost=&quot;, &quot;{:.9f}&quot;.format(c), \
              &quot;W=&quot;, sess.run(W), &quot;b=&quot;, sess.run(b))
  
  print(&quot;Optimization Finished!&quot;)
  training_cost = sess.run(cost, feed_dict={X: X_train, y: y_train})
  print(&quot;Training cost=&quot;, training_cost, &quot;W=&quot;, sess.run(W), &quot;b=&quot;, sess.run(b), '\n')
  </code></pre>
  <p>But the output is all <strong>nan</strong>
  <strong>Output:</strong></p>
  <pre><code>....................................
  Epoch: 19900 cost= nan W= nan b= nan
  Epoch: 19950 cost= nan W= nan b= nan
  Epoch: 20000 cost= nan W= nan b= nan
  Optimization Finished!
  Training cost= nan W= nan b= nan 
  </code></pre>