训练结束后做预测

2024-04-25 07:15:04 发布

您现在位置:Python中文网/ 问答频道 /正文

I've made simple prediction model with keras and bag of words based on the code which I found in the tutorials. Loading dataset and training finished without problem and accuracy is around 88%.
Dataset has two columns text and tag (i.e. "some text, a"). How can I test trained model with some other data which is not in dataset like model.predict(some text)?

以下是示例数据集: 泰克斯特,塔格 斯科托,n Trg Vinodolskog zakona 5号,a 我希望保存模型,这样就不必每次运行脚本时都训练它。是正确的方式放在剧本的结尾“模型.保存('my_model.h5')”? 如何加载模型并使用数据集中没有的数据进行预测?在

^{pr2}$

Tags: andthe数据textin模型whichmodel
2条回答

训练完模型后,可以使用model.save_weights(path)将权重保存到磁盘。在

然后可以使用model.load_weights(path)将权重加载到同一架构的模型中。在

如果您还想保存模型体系结构,可以使用更通用的model.save(path),它将保存

  1. 模型重量
  2. 模型架构
  3. 优化器声明。在

然后可以使用加载模型

from keras.models import load_model

model = load_model(path)

在您恢复了模型及其权重之后,您可以evaluate该模型来确定其准确性,或者使用predictions对新数据执行predictions

^{pr2}$

是的,根据Keras Documentation FAQ page。您只需键入:model.save(filepath)。 如果您想加载已经存在的模型,请使用:keras.models.load_model(filepath)。在

相关问题 更多 >