将时间序列转换为Keras输入 [英] Time series translation into Keras input

查看:306
本文介绍了将时间序列转换为Keras输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时间序列数据(ECG).我有30秒块的注释. 每个块有1000个数据点.这些数据块中有500个.

目标,注释例如范围为1到5.

为清楚起见,请参见图

关于X-DATA

如何将其转换为输入数据[示例,时间步长,特征]的Keras表示法?

我的猜测:

  • Samples =块(500)
  • timesteps = values(1000)
  • 功能=心电图(1)

产生[500,1000,1]

关于Y数据(目标)

我的目标或y数据会导致 [500,1,1]

经过一轮热编码后, [500,5,1]

问题在于Keras期望X和y数据具有相同的维数.但是将我的ydata每时间步增加到1000对我来说是没有意义的.

感谢您的帮助

p.s.无法像我和岳母一样直接回答.预先感谢

解决方案

我认为您在错误地考虑y.根据我对您的了解,您是图表. 在一次热编码之后,y实际上是(500,5).也就是说,每个块都有一个结果.

在Keras中,也不需要X和y具有相同的尺寸(除非您有seq2seq要求,在这里不是这种情况).

我们想要的是给我们一个概率分布的模型 每个块的可能标签,我们将使用softmax来实现 在最后(Dense)层上.

这是我模拟问题的方式:

import numpy as np
from keras.models import Model
from keras.layers import Dense, LSTM


# using eye doesn't capture one-hot but works for the example
series = np.random.rand(500, 1000, 1)
labels = np.eye(500, 5)

inp = Input(shape=(1000, 1))
lstm = LSTM(128)(inp)
out = Dense(5, activation='softmax')(lstm)
model = Model(inputs=[inp], outputs=[out])
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam')
model.fit(series, labels)

I have timeseries data (ECG). I have annotations for blocks of 30seconds. each block has 1000 data points. We have 500 of those data blocks.

The target, the annotations are e.g. in range 1 to 5.

To be clear please see Figure

About X-DATA

How translate that into the Keras notation for input data [Samples,timesteps, features]?

My guess:

  • Samples=Blocks (500)
  • timesteps=values(1000)
  • features= ECG as itselve (1)

resulting in [500,1000,1]

About Y-Data(target)

My target or y data would result in [500,1,1]

after one hot encoding it would be [500,5,1]

The problem is that Keras expect the X and y data to be of same dimensions. But increasing my ydata to 1000 per timestep would not make sense to me.

Thanks for your help

p.s. cannot answer directly as I am with my parent in law. Thanks in advance

解决方案

I think you're thinking about y incorrectly. From my understanding based on you're graph. y actually is (500, 5) after one hot encoding. That is, for every block there is a single outcome.

Also there is no need for X and y to have the same dimensions in Keras (unless you have a seq2seq requirement which is not the case here).

What we do want is the model to give us a probability distribution over the possible labels for each block, and that we'll achieve using a softmax on the last (Dense) layer.

Here is how I simulated your problem:

import numpy as np
from keras.models import Model
from keras.layers import Dense, LSTM


# using eye doesn't capture one-hot but works for the example
series = np.random.rand(500, 1000, 1)
labels = np.eye(500, 5)

inp = Input(shape=(1000, 1))
lstm = LSTM(128)(inp)
out = Dense(5, activation='softmax')(lstm)
model = Model(inputs=[inp], outputs=[out])
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam')
model.fit(series, labels)

这篇关于将时间序列转换为Keras输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆