我试图通过编写以下代码来找到回归模型:
X1 = tf.placeholder(tf.float32)
X2 = tf.placeholder(tf.float32)
X3 = tf.placeholder(tf.float32)
X4 = tf.placeholder(tf.float32)
X5 = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)
W1 = tf.Variable(tf.random_normal([1, 1]), dtype = tf.float32,name='weight1')
W2 = tf.Variable(tf.random_normal([1, 1]), dtype = tf.float32,name='weight2')
W3 = tf.Variable(tf.random_normal([1, 1]), dtype = tf.float32, name='weight3')
W4 = tf.Variable(tf.random_normal([1, 1]), dtype = tf.float32,name='weight4')
W5 = tf.Variable(tf.random_normal([1, 1]), dtype = tf.float32,name='weight5')
b1= b = tf.Variable(tf.random_normal([1]), dtype = tf.float32 ,name='bias1')
hypothesis = tf.sigmoid(tf.matmul(X1, W1)+tf.matmul(X2, W2)+tf.matmul(X3, W3)+tf.matmul(X4, W4) + tf.matmul(X5, W5) + b1)
cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) * tf.log(1 - hypothesis))
train = tf.train.GradientDescentOptimizer(learning_rate=0.000000000000000001).minimize(cost)
predicted = tf.cast(hypothesis > 0.5, dtype=tf.float32)
accuracy = tf.reduce_mean(tf.cast(tf.equal(predicted, Y), dtype=tf.float32))
with tf.Session() as sess:
# Initialize TensorFlow variables
sess.run(tf.global_variables_initializer())
for step in range(5000):
sess.run(train, feed_dict={X1:ct, X2: temperature, X3:humidity, X4: windspeed, X5:tideheight, Y:sst})
但是当我转动这段代码时,所有权重都出现了Nan值。