python - timeseries_dataset_from_array 返回未来的样本而不是以前的样本
问题描述
我的 ML 项目中有一个数据框,它最初采用以下格式。
Feature 1 | Feature 2| Feature 3 | Feature 4 | etc.
Time 1
Time 2
Time 3
Etc.
我正在尝试将此数据框更改为 3d,其中此数据框中的每个值在屏幕中都有另一个维度,包含相同特征的相同值,但在前 192 个时间步长。
在这里,我尝试使用内置函数 keras.preprocessing.timeseries_dataset_from_array(),但它返回的结果与我想要实现的相反。
我希望它会回来
Feature 1 | Feature 2| Feature 3 | Feature 4 | etc.
Time 192| [1-192] | [1-192] | [1-192] | |
Time 193| | | | |
Time 194| | | | |
Time End| | | | |
在这里,它改为返回:
Feature 1 | Feature 2| Feature 3 | Feature 4 | etc.
Time 1| [192-1] | [192-1] | [192-1] | |
Time 2| | | | |
Time 3| | | | |
Time End-192| | | | |
基本上每个样本都包含未来的 192 个值,而不是数据集之前的 192 个值。因此,它提前结束了 192 个样本,并且过早地开始了 192 个样本。
我的代码如下:
#Past is defined as 192
#x_val is the 2-d dataframe
#y_val is one of the columns in the dataframe.
dataset_historic_train = keras.preprocessing.timeseries_dataset_from_array(
x_val,
y_val,
sequence_length=past,
batch_size=len(x_val),
)
其中 x_val 是从样本的第一次到最后一次索引的整个二维数据帧,y_val 是我的目标特征,在这种情况下是特征 1。
解决方案
推荐阅读
- c# - 如何安全地将可能的空值转换为整数
- mysql - 使用 5000 万个文档对 MySQL 到 MongoDB 数据库进行建模的性能问题
- ios - 如何使用表格中的固定单元格,然后使用下面的项目列表?
- sql - SQL 批量插入忽略第一个数据行
- c++ - 使用 ffmpeg 音频编码器 adpcm_adx 将音频编码到 matroska 容器
- meshlab - MeshLab 32 位版本
- javascript - 如何让评论显示在所有帖子下
- cryptography - 是否可以从头开始定义 PKCS15 结构?
- javascript - 使用 fetch 下载大文件但使用过多缓存
- sql - 仅显示其他列中超过 2 个相同值的值