Batch Size of Stateful LSTM in keras
I solved the problem this way: 

I realized that I needed to find the HCF (highest common factor) of both the length of x_train and x_test. For this I wrote a simple HCF python code the output of it is the batch_size. 

Hence data set of different size will have different batch sizes.

Following is the code I used to find the HCF: 

def computeHCF(x, y):
    if x &gt; y:
        smaller = y
    else:
        smaller = x
    for i in range(1, smaller+1):
        if((x % i == 0) and (y % i == 0)):
            hcf = i

    return hcf

batch_size= computeHCF(x_train.shape[0], x_test.shape[0])


And use this batch_size  both while defining the model, fitting the model(model.fit(..)) &amp; predicting(model.predict(...)). 

NOTE: We need to specify batch size while predicting the model. As:

model.predict(x_test, batch_size=batch_size)


Hope this helps someone!