【问题标题】:When to use generator TensorFlow in time series何时在时间序列中使用生成器 TensorFlow
【发布时间】:2020-12-15 18:21:06
【问题描述】:

我正在构建一个 LSTM ANN,但我不确定在我的情况下使用生成器。网络应该有几个它应该迭代的超参数,例如时期,激活函数......但是,如果在这种情况下使用生成器,则每次迭代都在不同的集合上进行训练,对吗?那么更正确的是使用列表或数组吗?谢谢

for epoch in EPOCHS do:
for activation in ACTIVATION do:
trainLSTM(epoch, activation)
save best model

【问题讨论】:

    标签: tensorflow generator lstm


    【解决方案1】:

    建议Time Series Data使用Generator,在Tutorial of Tensorflow Time Series Analysis中有详细说明。这种Generator 的代码如下所示:

    class WindowGenerator():
      def __init__(self, input_width, label_width, shift,
                   train_df=train_df, val_df=val_df, test_df=test_df,
                   label_columns=None):
        # Store the raw data.
        self.train_df = train_df
        self.val_df = val_df
        self.test_df = test_df
    
        # Work out the label column indices.
        self.label_columns = label_columns
        if label_columns is not None:
          self.label_columns_indices = {name: i for i, name in
                                        enumerate(label_columns)}
        self.column_indices = {name: i for i, name in
                               enumerate(train_df.columns)}
    
        # Work out the window parameters.
        self.input_width = input_width
        self.label_width = label_width
        self.shift = shift
    
        self.total_window_size = input_width + shift
    
        self.input_slice = slice(0, input_width)
        self.input_indices = np.arange(self.total_window_size)[self.input_slice]
    
        self.label_start = self.total_window_size - self.label_width
        self.labels_slice = slice(self.label_start, None)
        self.label_indices = np.arange(self.total_window_size)[self.labels_slice]
    
      def __repr__(self):
        return '\n'.join([
            f'Total window size: {self.total_window_size}',
            f'Input indices: {self.input_indices}',
            f'Label indices: {self.label_indices}',
            f'Label column name(s): {self.label_columns}'])
    

    例如,如果您的 Data 是从 1960 年(1 月 1 日)到 2016 年(12 月 31 日),并且您想要 predict 2017 年整个二月的天气,请考虑过去2年的数据窗口,上述类的参数值如下所示:

    input_width: 2 Years => 365 * 2 = 730
    label_width: Entire Feb Month => 28
    shift: We are not predicting from Jan 1st 2017 but are shifting by entire Month of Jan => 30
    train_df, test_df, val_df => Self Explanatory
    label_columns : Name of the Target Column
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多