The problem concerns linear regression with tensor flow. Below is the code. The resulting coefficients are not correct. What am I wrong? Thank you in advance!
def tf_lin_regress(X_train, Y_train): """ Arguments: X_train - np.array of size (n by k) where n is number of observations of independent variables and k is number of variables Y_train - np.array of size (n by 1) where n is the number of observations of dependend variable Return: np.array of size (k+1 by 1) of regression coefficients """ ndim = X_train.shape[1] ### START CODE HERE ### (≈ 7-8 lines of code) X = tf.placeholder("float", shape=[None, ndim]) Y = tf.placeholder("float", shape=[None, 1]) W = tf.Variable(tf.zeros([3, 1]), name="weights") b = tf.Variable(0., name="bias") model_output = tf.add(tf.matmul(X, W), b) loss = tf.reduce_sum(tf.squared_difference(Y, model_output)) train = tf.train.GradientDescentOptimizer(0.05).minimize(loss) init = tf.global_variables_initializer() sess = tf.Session() sess.run(init) sess.run(train, feed_dict = {X: X_train, Y: Y_train}) weight, bias, loss = sess.run([W, b, loss], {X: X_train, Y: Y_train}) print("W: %sb: %s loss: %s"%(weight,bias,loss))