![](/img/trans.png)
[英]Train machine learning model with scikit learn for time-series prediction
[英]How can I have a series of numpy ndarrays as the input data to train a tensorflow machine learning model?
我正在尝试构建一个机器学习模型,该模型可以从一系列数字中预测一个数字。 我正在使用来自 Tensorflow 的 keras API 的序列模型。
基本上我的 x 数据是一个 Pandas 系列,其中包含 numpy ndarrays,其中包含浮点数。 我的 y 数据是一系列形状为 (1,1) 的 numpy ndarray,所以基本上只是一个浮点值。
你可以想象我的数据集看起来像这样:
指数 | x 数据(熊猫系列) | y 数据(熊猫系列) |
---|---|---|
0 | np.ndarray(shape (1209278,) ) |
np.ndarray(shape = () ) |
1 | np.ndarray(shape (1211140,) ) |
np.ndarray(shape = () ) |
2 | np.ndarray(shape (1418411,) ) |
np.ndarray(shape = () ) |
3 | np.ndarray(shape (1077132,) ) |
np.ndarray(shape = () ) |
... | ... | ... |
如上所述,我的 x 数据和 y 数据的类型是 pandas 系列。 当我尝试使用 fit 函数训练我的模型时,会产生以下错误:
ValueError:无法将 NumPy 数组转换为张量(不支持的对象类型 numpy.ndarray)
我还尝试将 pandas 系列转换为 numpy 数组,但这并没有帮助。 看起来,我有一系列不同形状的 ndarrays 作为我的输入数据这一事实本身就是问题所在。
我真的不知道我能做些什么来修复这个错误。 这引出了我的问题:
如何将一系列 numpy ndarrays 作为输入数据来训练 tensorflow 机器学习模型?
Pandas 数据系列不支持直接转换为张量。 所以我会先尝试将它们转换为list :
X = X.to_list()
Y = Y.to_list()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.