包含列表的规范化矩阵

Normalising matrix which contains lists

目前,我有以下数据框(前 30 列来自 dput()):

structure(list(PacketTime = c(0.0636830000000002, 0.0691829999999989, 
0.0639040000000008, 0.0636270000000003, 0.0656370000000024, 0.064778000000004, 
0.0616950000000003, 0.0666280000000015, 0.0630829999999989, 0.0665130000000005, 
0.0621160000000032, 0.0654010000000014, 0.0652889999999928, 0.0640989999999988, 
0.0621339999999861, 0.0645319999999998, 0.065757000000005, 0.0624459999999942, 
0.061782000000008, 0.0626439999999917, 0.0648419999999987, 0.0664910000000134, 
0.0644649999999984, 0.0654030000000034, 0.0657139999999998, 0.0642799999999966, 
0.069137000000012, 0.0631520000000023, 0.0634139999999945, 0.0615009999999927
), FrameLen = list(c(304L, 276L, 276L), c(304L, 276L, 276L), 
    c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 276L
    ), c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 
    276L, 276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 276L, 
    276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 
    276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 
    276L, 276L), c(304L, 276L, 276L, 276L, 276L), c(304L, 276L, 
    276L), c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 
    276L, 276L, 276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 
    276L), c(304L, 276L, 276L, 276L), c(304L, 276L, 276L, 276L, 
    276L), c(304L, 276L, 276L), c(304L, 276L, 276L), c(304L, 
    276L, 276L), c(304L, 276L, 276L), c(304L, 276L, 276L)), IPLen = list(
    c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 272L
    ), c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 
    272L), c(300L, 272L, 272L), c(300L, 272L, 272L, 272L, 272L
    ), c(300L, 272L, 272L), c(300L, 272L, 272L, 272L, 272L), 
    c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 272L
    ), c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 
    272L), c(300L, 272L, 272L, 272L, 272L), c(300L, 272L, 272L
    ), c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 
    272L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 272L
    ), c(300L, 272L, 272L, 272L), c(300L, 272L, 272L, 272L, 272L
    ), c(300L, 272L, 272L), c(300L, 272L, 272L), c(300L, 272L, 
    272L), c(300L, 272L, 272L), c(300L, 272L, 272L)), Movement = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -30L), class = c("tbl_df", 
"tbl", "data.frame"))

从这里开始,我可以使用 keras 包将数据帧(在变量 packets 中)放入矩阵中,使用:

packets.m <- as.matrix(packets)

但是,当我尝试将其传递到模型中(没有规范化)或在传递之前进行规范化时,我收到以下错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : Matrix type cannot be converted to python (only integer, numeric, complex, logical, and character matrixes can be converted

因此,如何有效地规范化包含列表的 FrameLenIPLen 两列,以便我可以准确地将其用于使用 keras 包的深度学习模型?

编辑:完整的dput()可以在这里找到,对于包数据帧https://pastebin.com/cXKdSB2y

这取决于你如何训练这些数据

library(tidyverse)

多个实例

df %>% 
  unnest()

多项功能

df %>% 
  mutate(position = map(FrameLen,seq_along),id = row_number()) %>%
  unnest() %>% 
  pivot_wider(names_from = position,values_from = c(FrameLen,IPLen))