# What should be the value of batch_size in fit() method when using sgd (Stochastic Gradient Descent) as the optimizer?

I am confused about the batch size of this model. I have used sgd i.e., Stochastic Gradient Descent as the optimizer (see the code). I am aware that in sgd, a single random instance from the training set is used to compute the gradient at each step. So, according to it, the batch_size should be equal to 1. Now, in the tf.keras.Sequential.fit() documentation it says:

If unspecified, batch_size will default to 32.

So, do I have to manually set the batch_size equal to 1? It is because the default value, 32 will make it a Mini-batch Gradient Descent.

    import tensorflow as tf
from tensorflow import keras

fashion_mnist = keras.datasets.fashion_mnist
(X_train_full, y_train_full), (X_test, y_test) = fashion_mnist.load_data()

X_valid, X_train = X_train_full[:5000]/255.0, X_train_full[5000:]/255.0
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]

model = keras.models.Sequential()


• Actually, I was concerned that if I set my batch_size more than 1, will I still be able to call it a Stochastic Gradient Descent? According to my research, the answer should be no. So, I was wondering what is the point of using Stochastic Gradient Descent as the optimizer if I am not setting batch_size equal to 1. – Nowroz Islam Jul 18 at 17:10