【问题标题】:univariate_data function does not work in python tensorflow tutorial (pandas dataframe)univariate_data 函数在 python tensorflow 教程(熊猫数据框)中不起作用
【发布时间】:2020-08-31 05:44:30
【问题描述】:

我正在尝试学习这个 tensorflow 教程:https://www.tensorflow.org/tutorials/structured_data/time_series

但是,当我使用 univariate_data 函数时,它不起作用。半年前我试过这个教程,它也不起作用。

我使用的是我自己的数据,但它的准备方式与教程中的天气数据相同:

常规示例天气数据也出现此错误。 这是我得到的错误:

感谢您的帮助!

【问题讨论】:

    标签: 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)
    

    在上述代码中定义后调用该函数应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2018-04-20
      • 2017-01-04
      • 1970-01-01
      • 2014-05-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-03
      • 2017-05-10
      • 1970-01-01
      相关资源
      最近更新 更多