我正在测试 keras 的 imdb 数据集。问题是,当我分开训练和测试 2000 个单词时,我的准确率接近 87%:
(X_train, train_labels), (X_test, test_labels) = imdb.load_data(num_words=2000)
但是当我将单词增加到 5000 或 10000 时,模型表现不佳:
(X_train, train_labels), (X_test, test_labels) = imdb.load_data(num_words=10000)
这是我的模型:
model = models.Sequential()
model.add(layers.Dense(256, activation='relu', input_shape=(10000,)))
model.add(layers.Dense(16, activation='relu' ))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
history =model.fit(X_train, y_train, epochs=10, batch_size=64,validation_data=(x_val, y_val))
谁能解释一下为什么会出现这种情况?我虽然有更多的样本(和更少的过度拟合),但我应该得到一个非常好的模型。
感谢您的建议
最佳答案
增加num_words
并不会增加样本数量,而是会增加词汇量,从而导致每个样本包含更多单词(统计上),朝着 curse of dimensionality 的方向发展。 ,这对模型有害。
来自docs :
num_words: integer or None. Top most frequent words to consider. Any less frequent word will appear as oov_char value in the sequence data.
关于python-3.x - 当训练样本增加时,准确率降低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56450080/