Mini batch Gradient Descent: Handling the last mini batch

I have written code that I believed would handle the end case where the number of training examples in the mini batch is not a muliple of mini batch sizes. However I continue to get the error, “slice indices must be integers or None or have an index method error.”

Can you explain to me what I’m doing wrong with the slicing?

Hi @ianigbog,

I guess m / mini_batch_size is a float and not an integer.

However, I advise you to recheck your implementation because it doesn’t look right :slight_smile:
For example, are you sure all of your training examples belong to precisely one mini batch? Are there training examples that are missing from a mini batch? Are there training examples that are included in more than one mini batch?

Hi @hark99,

Please remove your solution code :slight_smile: Maybe you have an error in your code for the last case, i.e., last mini-batch < mini_batch_size i.e less than 64.

Try and print the shapes of the last mini batch as well… Maybe you will figure out what you are doing wrong :slight_smile:

Thats the output
mini_batch_X : (12288, 20)
mini_batch_Y : (1, 20)

For the last batch you extract the first 20 samples [:, :s]. Shouldnt you extract the missing samples from the end somehow?

thanks, :). the last mini-batch is the end values

1 Like