简体   繁体   English

如何使用训练有素的 keras 模型预测数据

[英]How do I predict data using a trained keras model

My independent variable is a datetime object and my dependent variable is an float.我的自变量是一个日期时间对象,我的因变量是一个浮点数。 Currently, I have a keras model that predicts accurately, but I found out that model.predict() only returns predictions for the values that are already known.目前,我有一个准确预测的 keras 模型,但我发现model.predict()只返回对已知值的预测。 Is there a method I can call to tell the program to use the model to predict unknown values?有没有我可以调用的方法来告诉程序使用模型来预测未知值? If there isn't please give me instructions about how to predict these unknown values.如果没有,请给我有关如何预测这些未知值的说明。

Currently, I have a Keras model that predicts accurately, but I found out that model.predict() only returns predictions for the values that are already known目前,我有一个准确预测的 Keras 模型,但我发现 model.predict() 只返回已知值的预测

That is incorrect.那是不正确的。 A predict statement doesn't just 'search and return' results from training data.预测语句不仅仅是从训练数据中“搜索并返回”结果。 That's not how machine learning works at all.这根本不是机器学习的工作方式。 The whole reason that you build models and have a train and test dataset is to ensure you have a model that is generalizable (ie can be used to make predictions on unseen data, assuming the observation is coming from the same underlying distribution that the model is trained on)您构建模型并拥有训练和测试数据集的全部原因是确保您拥有一个可推广的模型(即可用于对未见数据进行预测,假设观察来自与模型相同的底层分布受过训练)

In your specific case, you are using a DateTime variable an independent, which means you should refrain from using variable such as year, which are non-recurring since you can use it to make predictions about the future (model learns patterns in 2019 but 2020 may be out of its vocabulary and thus years after that are not feasible to use for predictions.)在您的特定情况下,您使用的是独立的 DateTime 变量,这意味着您应该避免使用诸如年份之类的变量,因为您可以使用它来预测未来(模型在 2019 年但 2020 年学习模式)可能已经超出了它的词汇量,因此多年后无法用于预测。)

Instead, you should engineer some features from your DateTime variable and use recurring variables which may show reveal some patterns in the dependent variable.相反,您应该从 DateTime 变量中设计一些功能并使用重复变量,这些变量可能会显示因变量中的某些模式。 These variables are like days of the week, months, seasons, hours of the day.这些变量就像一周中的几天、几个月、季节、一天中的几个小时。 Depending on what your dependent variable is, you can surely find some patterns in these.根据您的因变量是什么,您肯定可以在其中找到一些模式。

All of this totally depends on what you are trying to model and what is the goal of the model.predict() wrt your problem statement.所有这一切完全取决于您尝试建模的内容以及model.predict()您的问题陈述的目标是什么。 Please elaborate if possible so that people can give you more specific answers.如果可能,请详细说明,以便人们可以给您更具体的答案。

Your assumption is incorrect.你的假设是不正确的。 model.predict is specifically intended to use a trained model to make predictions on a data set typically not used previously for example a test set and not a training or validation set. model.predict 专门用于使用经过训练的模型对以前通常未使用的数据集进行预测,例如测试集而不是训练或验证集。 To use it you need to create a data set to feed to model.predict.要使用它,您需要创建一个数据集以提供给 model.predict。 See answer here.请参阅此处的答案 on how to provide input to model.predict关于如何向 model.predict 提供输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM