我是Keras& ML概念。我正在尝试使用https://raw.githubusercontent.com/fchollet/keras/master/examples/imdb_cnn_lstm.py执行情绪分析。我使用model.save(" imdb_cnn_lstm.h5")保存了模型并加载模型以对新文本执行预测,如
from keras.preprocessing import sequence
from keras.datasets import imdb
from keras.models import load_model
import numpy as np
import re
model = load_model('imdb_cnn_lstm.h5')
word_to_id = imdb.get_word_index()
testString = raw_input('Enter your test to be analyzed:')
strip_special_chars = re.compile("[^A-Za-z0-9 ]+")
testString = testString.lower().replace("<br />", " ")
testString=re.sub(strip_special_chars, "", testString.lower())
print("Cleaned Data ", testString)
words = testString.split() #split string into a list
x_test = [[word_to_id[word] if (word in word_to_id and word_to_id[word]<=20000) else 0 for word in words]]
x_test = sequence.pad_sequences(x_test, maxlen=100) # Should be same which you used for training data
vector = np.array([x_test.flatten()])
print("Prediction is ",model.predict(vector),model.predict_classes(vector))
对于像#34这样的文字,这是一部令人失望的电影&#34;输出为0.5724526(model.predict(vector)的输出) 对于像#34这样的文字,这是一部很棒的电影&#34;输出为0.57088572(model.predict(vector)的输出) 我应该调整什么才能获得更好的预测/分类?我假设模型预测1为正面情绪,0为负面情绪。