我想學習tensorflow,目前正試圖做一個簡單的邏輯迴歸模型。這裏是我從我能找到的不同例子拼接在一起的代碼。邏輯迴歸調試tensorflow
with tf.Session() as sess:
# Training data
input = tf.constant(tra)
target = tf.constant(np.transpose(data[:,1]).astype(np.float64))
# Set model weights
W = tf.Variable(np.random.randn(10, 1).astype(np.float64))
# Construct model
mat=tf.matmul(input,W)
pred = tf.sigmoid(mat)
# Compute the error
yerror = tf.sub(pred, target)
# We are going to minimize the L2 loss. The L2 loss is the sum of the
# squared error for all our estimates of y. This penalizes large errors
# a lot, but small errors only a little.
loss = tf.nn.l2_loss(yerror)
# Gradient Descent
update_weights = tf.train.GradientDescentOptimizer(0.05).minimize(loss)
# Initializing the variables
tf.initialize_all_variables().run()
for _ in range(50):
# Repeatedly run the operations, updating the TensorFlow variable.
sess.run(update_weights)
print(loss.eval())
因此,代碼運行,但錯誤的每個「sess.run(update_weights)」 itteration後劑量沒有改善,我曾與不同勢步長嘗試。
我不知道該設置是否相關嗎?
我有點不確定如何調試它,因爲一切的計算都在運行命令完成。訓練數據很好。如果你們中的一些人能夠看到我在這整個會議中做錯了什麼,或者就如何調試這個問題提出建議。
非常感謝。
謝謝評論一些問題: 我可以把任何隨機數還是應隨機高斯均值爲0,STD 1?並且是日誌中的N(N)我擁有的功能數量還是訓練示例數量? –
如果權重都爲零,權重是多少並不重要,但是否則是,您可以輸入與輸出無關的任何內容。 「N」是指類的數量。 – drpng