【问题标题】:univariate_data function does not work in python tensorflow tutorial (pandas dataframe)univariate_data 函数在 python tensorflow 教程(熊猫数据框)中不起作用
【发布时间】:2020-08-31 05:44:30
【问题描述】:
【问题讨论】:
标签:
python
pandas
dataframe
tensorflow
recurrent-neural-network
【解决方案1】:
univariate_data 不是 python 的内置函数之一,也不是该教程中使用的任何库。
这是您正在关注的同一文档/教程中的用户定义函数。
这是函数的代码(在您发布的同一链接中也提到过):
def univariate_data(dataset, start_index, end_index, history_size, target_size):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
for i in range(start_index, end_index):
indices = range(i-history_size, i)
# Reshape data from (history_size,) to (history_size, 1)
data.append(np.reshape(dataset[indices], (history_size, 1)))
labels.append(dataset[i+target_size])
return np.array(data), np.array(labels)
在上述代码中定义后调用该函数应该可以解决问题。