我想学习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