0
import tensorflow as tf
# Model parameters
A = tf.Variable([.3], dtype=tf.float32)
W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
q_model = A * (x**2) + W * x + b
y = tf.placeholder(tf.float32)
# loss
loss = tf.reduce_sum(tf.square(q_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
# training data
x_train = [0, 1, 2, 3, 4]
y_train = [0, 1, 4, 9, 16]
# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(1000):
sess.run(train, {x: x_train, y: y_train})
# evaluate training accuracy
curr_A, curr_W, curr_b, curr_loss = sess.run([A, W, b, loss], {x: x_train, y: y_train})
print("A: %s W: %s b: %s loss: %s"%(curr_A, curr_W, curr_b, curr_loss))
tfはモデルコードを入力して線形回帰を実行します。しかし、私は二次回帰をすることができるかどうかを見て回りたいと思っていました。そうするために、私はtf.Variable Aを追加し、それをモデルに入れて、それが値として得たものを教えて出力を修正しました。ここですべてのTensorflow出力がナノです。
結果は以下のとおりです。
A: [ nan] W: [ nan] b: [ nan] loss: nan
y'allのは、ここでの問題は何だと思いますか?椅子とキーボードの間にありますか?