1

I am running a classification model using LSTM model. I am getting different accuracy for the validation data during every run. I have set the random.seed(50), however different accuracy for different samples:

Here is my code:

import numpy as np
np.random.seed(50)

This is how the data was shuffled: split the data into a training set and a validation set

indices = np.arange(data.shape[0])
np.random.shuffle(indices)
data = data[indices]
labels = labels[indices]
num_validation_samples = int(VALIDATION_SPLIT * data.shape[0])

x_train = data[:-num_validation_samples]
y_train = labels[:-num_validation_samples]
x_val = data[-num_validation_samples:]
y_val = labels[-num_validation_samples:]

This is the model:

model = Sequential()
model.add(Embedding(num_words, EMBEDDING_DIM, weights=[embedding_matrix], input_length=MAX_SEQUENCE_LENGTH))
model.add(LSTM(100))
#model.add(Dense(2, activation = 'sigmoid'))
model.add(Dense(2, batch_input_shape=(None, 1000)))
model.add(Dense(2))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(x_train, y_train, epochs = 10, batch_size=64)
# Final evaluation of the model
scores = model.evaluate(x_val, y_val, verbose=0)
print("Accuracy: %.2f%%" % (scores[1]*100))
Doubt Dhanabalu
  • 457
  • 4
  • 8
  • 18

0 Answers0