【发布时间】:2016-11-10 20:29:30
【问题描述】:
我正在尝试学习 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)”迭代后错误并没有改善,我尝试了不同的步长。
不知设置是否正确?
我有点不确定如何调试它,因为一切的计算都是在运行命令中完成的。训练数据很好。如果你们中的一些人可以看到我在整个会话中做错了什么,或者就如何调试它提出建议。
非常感谢您的帮助。
【问题讨论】:
标签: python tensorflow logistic-regression