model.predict()
期望第一个参数是一个numpy数组。您提供了一个列表,该列表不具有numpy数组具有的shape
属性。
否则,您的代码看起来很好,除了您对预测不做任何事。确保将其存储在变量中,例如:
prediction = model.predict(np.array(tk.texts_to_sequences(text)))
print(prediction)
0
model.predict()
期望第一个参数是一个numpy数组。您提供了一个列表,该列表不具有numpy数组具有的shape
属性。
否则,您的代码看起来很好,除了您对预测不做任何事。确保将其存储在变量中,例如:
prediction = model.predict(np.array(tk.texts_to_sequences(text)))
print(prediction)
0
model.predict_classes(<numpy_array>)
样本https://gist.github.com/alexcpn/0683bb940cae510cf84d5976c1652abd
0
我在Keras中训练了一个神经网络,以对某些数据进行非线性回归。这是我的代码的一部分,用于使用以前保存的模型配置和权重对新数据进行测试。
fname = r"C:\Users\tauseef\Desktop\keras\tutorials\BestWeights.hdf5"
modelConfig = joblib.load('modelConfig.pkl')
recreatedModel = Sequential.from_config(modelConfig)
recreatedModel.load_weights(fname)
unseenTestData = np.genfromtxt(r"C:\Users\tauseef\Desktop\keras\arrayOf100Rows257Columns.txt",delimiter=" ")
X_test = unseenTestData
standard_scalerX = StandardScaler()
standard_scalerX.fit(X_test)
X_test_std = standard_scalerX.transform(X_test)
X_test_std = X_test_std.astype('float32')
unseenData_predictions = recreatedModel.predict(X_test_std)
0
您必须使用与用于构建模型相同的Tokenizer!
否则,这将为每个单词提供不同的向量。
然后,我正在使用:
phrase = "not good"
tokens = myTokenizer.texts_to_matrix([phrase])
model.predict(np.array(tokens))
0
我正在使用路透社示例数据集,它运行良好(我的模型已经过训练)。我阅读了有关如何保存模型的信息,因此以后可以加载它以再次使用。但是,如何使用此保存的模型预测新文本?我是否使用
models.predict()
?我是否需要以特殊方式准备此文本?
我尝试过
但是我总是
关于如何使用经过训练的模型进行预测,您有任何建议吗?