我正在尝试使用Tensorflow并构建一个简单的逻辑回归分类器 . 训练集包含大约五十万(480,000)个数据点 . 我正在训练100号批次 .

在训练模型时,损失在20个训练时期内从0.002降至0.000000034(整个训练集在每个时期逐批遍历) .

然而,这在训练集上给出了0.671725的准确度,这似乎非常低 . 据我了解,训练集的准确度应接近1.00(100%) . 由于我对Tensorflow很陌生,我不确定在计算中是否遗漏了一个关键细节 .

  • 将批量大小更改为1000并没有多大区别 - 从0.671698到0.671725 .

  • 可能过度拟合,但我仍然无法理解为什么它也降低了训练集的准确性 .

  • 将时期减少到10可以获得相同的精度 .

  • 将时期增加到100并不会改变准确性 .

  • 在75个时期之后,将学习率从0.001提高到0.01,产生0.000000000 . 该值非常小,以适应精度 . 训练准确性保持不变

代码段:

x = tf.placeholder(tf.float32, [None, window_size]) # data with the size of the window currently set to 6
y = tf.placeholder(tf.float32, [None, 2])

W = tf.Variable(tf.zeros([window_size, 2]))
b = tf.Variable(tf.zeros([2]))

# Construct model
model = tf.nn.sigmoid(tf.matmul(x, W) + b) #Sigmoid

cost = tf.reduce_mean(-tf.reduce_sum(y * tf.log(model), reduction_indices=1))

optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)

# Inirializing the variables
init = tf.initialize_all_variables()

print (len(feed_windows_np))

batch_size = 1000


#Splitting to train and test
train = feed_windows_np[:len(feed_windows_np)//2 - ((len(feed_windows_np)//2) % batch_size)]
train_labels = labels[:len(feed_windows_np)//2 - ((len(feed_windows_np)//2) % batch_size)]
test = feed_windows_np[(len(feed_windows_np) * 2) // 3:]
test_labels = labels[(len(feed_windows_np) * 2) // 3:]

total_batches = int(math.floor(len(train) / batch_size))

avg_costs = []

with tf.Session() as sess:
sess.run(init)

# Training cycle
for epoch in range(epochs):
avg_cost = 0.
for i in range(total_batches):
    feed_dict = {
        x: train[i * batch_size:(i + 1) * batch_size],
        y: labels[i * batch_size:(i + 1) * batch_size]
    }
    _, c = sess.run([optimizer, cost], feed_dict=feed_dict)
    #sess.run(optimizer, feed_dict=feed_dict)
    # updating the loss
    avg_cost += c / total_batches
if (epoch + 1) % display_step == 0:
    print ('Epoch:', '%04d' % (epoch + 1), 'cost=', '{:.9f}'.format(avg_cost))
    avg_costs.append(avg_cost)
print ('Optimisation Finished!')


plt.plot(avg_costs)
plt.show()

# Training accuracy
correct_prediction = tf.equal(tf.argmax(model, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
accuracy_val= sess.run(accuracy, feed_dict={x: train, y: train_labels})
print ('Accuracy on training data:', accuracy_val)

知道什么可能导致这种行为?它的大小是否很大,因为当达到80个训练数据点时,准确度会达到应有的水平?