Hi Chris!



 Chrisfsj2051:

I am trying to evaluate my model and find that I get different results while using bs=1 and bs=2
Here is my code:
...
    for st in range(0, len(Y_test)//batch_size):
        X_batch, Y_batch=X_test[st:st+batch_size], Y_test[st:st+batch_size]
...

And it turns out the accuracy is 0.0636 when batch size is set to 2, and 0.0674 when batch size is set to 1.


Regardless of the value of batch_size (bs), st in your for
loop moves along in increments of one.
Therefore when batch_size == 1, you iterate over all elements
of Y_test and Y_test (which is what you want).  But when
batch_size == 2 you only iterate over approximately half of
the elements, with most of the elements that you iterate over being
included in two batches.
That is, when batch_size == 2 you iterate over the correct number
of batches, but the batches overlap, so you get (approximately) two
copies of the first half of X_batch and Y_batch, and nothing from
the second half.
So you’re not calculating the accuracy on the same data, and the
results differ, as would be expected.
Good luck.
K. Frank