我正在使用LSTM模型运行分类模型。我在每次运行期间获得验证数据的准确度不同。我设置了random.seed(50),但不同样本的准确度不同:
这是我的代码:
import numpy as np
np.random.seed(50)
这是数据被洗牌的方式: 将数据拆分为训练集和验证集
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:]
这是模型:
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))