【问题标题】:Converting pandas series to 3D input vectors for LSTM implementation将 pandas 系列转换为 3D 输入向量以实现 LSTM
【发布时间】:2020-12-15 17:12:36
【问题描述】:

我有一个 pandas 系列,其中每一行是一个列表序列,每个序列包含 50 个时间步长作为输入,另一个序列包含相应的 10 个时间步长序列作为输出。它们的头部形状分别为 (5,)。我希望将训练数据转换为形状 (n_samples, 50, 1) 并将测试数据转换为形状 (n_samples, 10),以便将其提供给 多对多 LSTM 模型。我在 Stackoverflow 上尝试了几种方法,但似乎没有一个对我有用。无论我做什么,我都会不断收到错误:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).

【问题讨论】:

    标签: python pandas numpy lstm


    【解决方案1】:

    我的同事帮我解答了这个问题:

    N = 100 #number of samples
    X = df_new['sequence']
    y = df_new['target']
    X = X.iloc[:N]
    X = np.array([[np.array(x) for x in X.values]]).T.reshape(N, 50, 1)
    y = y.iloc[:N]
    y = np.array([np.array(x) for x in y.values])
    print(X.shape)
    print(y.shape)
    

    我错过的部分是使用转置函数来操作数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      • 2019-03-08
      • 2019-11-28
      相关资源
      最近更新 更多