如何在时间序列分类中结合 LSTM 和 CNN [英] How to combine LSTM and CNN in timeseries classification

查看:154
本文介绍了如何在时间序列分类中结合 LSTM 和 CNN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有图像作为数据时,最常使用 CNN.但是,我已经看到 CNN 是用于时间序列的 sometines.因此,我针对我的时间序列分类问题分别尝试了 LSTM 和 CNN 模型.我的两个模型如下.

Most commonly CNN is used when there are images as data. However, I have seen that CNN are sometines used for timeseries. Therefore, I tried both LSTM and CNN models seperately for my timeseries classification problem. My two models are as follows.

LSTM:

model = Sequential()
model.add(LSTM(200, input_shape=(25,3)))
model.add(Dense(100))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

美国有线电视新闻网:

model = Sequential()
model.add(Conv1D(200, kernel_size=3, input_shape=(25,3)))
model.add(Conv1D(200, kernel_size=2))
model.add(GlobalMaxPooling1D())
model.add(Dense(100))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

我认为 LSTM 和 CNN 具有独特的特征,在我的预测中将这两者结合起来会产生更好的结果.但是,我正在努力寻找适合我的问题的合适资源.

I think LSTM and CNN has there unique characteristics and combining these two in my prediction will produce better results. However, I am struggling to find a suitable resource that suits my problem.

是否可以针对我的问题执行此操作?如果是这样,我该怎么做?它会产生更好的结果吗?

Is it possible to do this for my problem? If so how I can do it? Will it produce better results?

如果需要,我很乐意提供更多详细信息.

I am happy to provide more details if needed.

我的问题设置如下.我有一个包含大约 5000 个数据点的数据集.每个数据点有 3 个大小正好为 25 的时间序列数据.我标记的数据是 10(即二进制分类).更具体地说,我的数据集如下所示.

My problem setting is as follows. I have a dataset with about 5000 data points. Each data point has 3 time-series data that are exactly 25 in size. My labeled data is 1 or 0 (i.e. binary classification). More specifically my dataset looks as follows.

node, time-series1, time_series2, time_series3, Label
n1, [1.2, 2.5, 3.7, 4.2, ... 5.6, 8.8], [6.2, 5.2, 4.7, 3.2, ... 2.6, 1.8], [1.0, 2.8, 3.9, 4.1, ... 5.2, 8.6] …, 1
n2, [5.2, 4.5, 3.7, 2.2, ... 1.6, 0.8], [8.2, 7.5, 6.7, 5.2, ... 4.6, 1.8], …, [1.2, 2.5, 3.7, 4.2, ... 5.2, 8.5] 0
and so on.

我将这些数据输入到我的 LSTM 和 CNN 模型中.

I input these data to my LSTM and CNN models.

推荐答案

你有没有试过一层一层地放?这听起来很标准...

Have you tried to just put one layer after another? This sounds pretty standard...

model = Sequential()
model.add(Conv1D(200, kernel_size=3, activation = useSomething, input_shape=(25,3)))
model.add(LSTM(200))
model.add(Dense(100))
model.add(Dense(1, activation='sigmoid'))

你想反其道而行之吗?

model = Sequential()
model.add(LSTM(200, return_sequences=True, input_shape=(25,3)))
model.add(Conv1D(200, kernel_size=3, activation = useSomething))
model.add(GlobalMaxPooling1D())
model.add(Dense(100))
model.add(Dense(1, activation='sigmoid'))

你想要一个巨大的模型吗?

Do you want a huge model?

model = Sequential()
model.add(Conv1D(15, kernel_size=3, activation = useSomething, input_shape=(25,3)))
model.add(LSTM(30, return_sequences=True))
model.add(Conv1D(70, kernel_size=3, activation = useSomething))
............
model.add(LSTM(100))
model.add(Dense(100))
model.add(Dense(1, activation='sigmoid'))

<小时>

尝试很多事情:


Try many things:

  • 转换,LSTM
  • LSTM、转化率
  • 转换、转换、..、转换、LSTM、...、LSTM
  • LSTM、LSTM、...、Conv、Conv、....
  • C, L, C, L, C, L, ....
  • L、C、L、C、L、C、......
  • C、C、L、L、C、C、......

双面模型?

inputs = Input((25,3))

side1 = Bidirectional(LSTM(100, return_sequences=True))(inputs) #200 total units
side2 = Conv1D(200, activation = 'tanh', padding = 'same')(inputs) #same activation 
                                                                   #same length

merged = Add()([side1, side2]) 
     #or Concatenate()([side1, side2]) if different number of units/channels/features

outputs = Conv1D(200)(merged)
outputs = GlobalMaxPooling1D()(outputs)
outputs = Dense(100)(outputs)
outputs = Dense(1, activation='sigmoid')(outputs)

model = Model(inputs, outputs)

这篇关于如何在时间序列分类中结合 LSTM 和 CNN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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