0
これはサンプルからの非常に単純な線形回帰アルゴリズムです。それは正常に動作します。ターゲット関数はy = 1-xです。テンソルは線形回帰でサンプルを正しく処理できません
sess.run(init)
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(cost)
for i in range(1000):
sess.run(train, {x:[1,2,3,4,-3], y:[0,-1,-2,-3,4]})
curr_W, curr_b, curr_loss = sess.run([W, b, cost], {x:[1,2,3,4,-3], y:[0,-1,-2,-3,4]})
print("W, b, cost: ", curr_W, curr_b, curr_loss)
しかし、私は、x = 35を追加した場合、およびy = -34、返さコストが非常に大きくなる:
('W, b, cost: ', array([ -1.27068623e+36], dtype=float32), array([ -4.23763612e+34], dtype=float32), inf)
('W, b, cost: ', array([ 1.40919235e+36], dtype=float32), array([ 4.69954423e+34], dtype=float32), inf)
('W, b, cost: ', array([ -1.56279610e+36], dtype=float32), array([ -5.21179788e+34], dtype=float32), inf)
('W, b, cost: ', array([ 1.73314268e+36], dtype=float32), array([ 5.77989253e+34], dtype=float32), inf)
('W, b, cost: ', array([-inf], dtype=float32), array([ -6.40990497e+34], dtype=float32), inf)
('W, b, cost: ', array([ nan], dtype=float32), array([ nan], dtype=float32), nan)
('W, b, cost: ', array([ nan], dtype=float32), array([ nan], dtype=float32), nan)
('W, b, cost: ', array([ nan], dtype=float32), array([ nan], dtype=float32), nan)