包含列表的归一化矩阵

问题描述 投票:0回答:1

当前,我具有以下数据帧(前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)

但是,当我尝试将其传递给模型(不进行归一化)或在传递前进行归一化时,收到以下错误:

py_call_impl(可调用,dots $ args,dots $ keywords)错误:矩阵类型不能转换为python(只能转换整数,数字,复数,逻辑和字符矩阵

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

EDIT:完整的dput()可以在此处找到,用于数据包数据帧https://pastebin.com/cXKdSB2y

r dataframe matrix keras normalization
1个回答
1
投票

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

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))
© www.soinside.com 2019 - 2024. All rights reserved.