0

I've some error. plz help me... I study to Linear regression but I don't know reason and can't solve this problem any more.

import tensorflow as tf

X = tf.placeholder(tf.float32, shape=[None])
Y = tf.placeholder(tf.float32, shape=[None])


x_train = [1,2,3]
y_train = [1,2,3]

w = tf.Variable(tf.random_normal([1]), name="weight")
b = tf.Variable(tf.random_normal([1]), name="bias")

hypothesis = x_train * w + b
cost = tf.reduce_mean(tf.square(hypothesis - y_train))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
train = optimizer.minimize(cost)

sess = tf.Session()
sess.run(tf.global_variables_initializer())

sess.run(train)
if(step % 20 == 0):
    print(step,'\t',sess.run(cost),'\t',sess.run(w),'\t',sess.run(b))

for step in range(501):
    _cost, _w, _b = \
    sess.run([cost,w,b,train],
            feed_dict={X:[1,2,3,4,5], Y:[2.1,3.1,4.1,5.1,6.1]})
    if step % 20 == 0:
        print(step, _cost, _w, _b)

print(sess.run(hypothesis, feed_dict={x:[5]}))

Error in print(sess.run(hypothesis, feed_dict={x:[5]})) mentioned below:

have too many values to unpack (expected 3)

WHAT IS THE too many values to unpack (expected 3) ERROR?.. (T0T)

MrLeeh
  • 5,321
  • 6
  • 33
  • 51
Jacob Kwon
  • 23
  • 4

1 Answers1

3

in your session you run cost, w, b and train. Therefore 4 values are returned, even though train only returns None.

_cost, _w, _b, _ = \
sess.run([cost,w,b,train],
        feed_dict={X:[1,2,3,4,5], Y:[2.1,3.1,4.1,5.1,6.1]})
Diana
  • 377
  • 2
  • 8