【问题标题】:LSTM input shape through json file通过 json 文件的 LSTM 输入形状
【发布时间】:2020-10-06 14:34:03
【问题描述】:

我正在研究 LSTM,在对数据进行预处理后,我以列表的形式获得数据 X,其中包含 3 个特征列表,每个列表包含列表形式的 50 个点的序列。

X = [list:100 [list:3 [list:50]]]
Y = [list:100]

由于它是一个多元 LSTM,我不确定如何将所有 3 个序列作为 Keras-Lstm 的输入。我需要在 Pandas 数据框中转换它吗?

model = models.Sequential()    
model.add(layers.Bidirectional(layers.LSTM(units=32,
                                               input_shape=(?,?,?)))

【问题讨论】:

    标签: python-3.x keras lstm


    【解决方案1】:

    您可以执行以下操作将列表转换为 NumPy 数组:

    X = np.array(X)
    Y = np.array(Y)
    

    在此转换后调用以下内容:

    print(X.shape)
    print(Y.shape)
    

    应该分别输出:(100, 3, 50) 和 (100,)。最后LSTM层的input_shape可以是(None, 50)。

    【讨论】:

      【解决方案2】:

      LSTM 调用参数Doc

      inputs: A 3D tensor with shape [batch, timesteps, feature].
      

      您必须将该列表转换为 numpy 数组才能使用 Keras。

      根据您提供的 X 形状,理论上它应该可以工作。但是,您必须弄清楚数组的 3 个维度实际包含什么。

      • 第一个维度应该是你的 batch_size,即你有多少批数据。

      • 第二维是你的时间步长数据。

      例如:句子中的单词,“cat sat on dog” -> 'cat' 是时间步长 1,'sat' 是时间步长 2,'on' 是时间步长 3,依此类推。

      • 第 3 维表示您的数据在每个时间步的特征。对于我们之前的句子,我们可以对每个单词进行向量化

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-27
        • 2019-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多