一.Python代码
#!/usr/bin/env python3
# encoding: utf-8
'''
@file: Keras_RNN.py
@time: 2020/6/21 0021 11:10
@author: Jack
@contact: jack18588951684@163.com
'''
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input, Dense
from keras.layers.recurrent import LSTM
visible = Input(shape=(100, 1))
hidden1 = LSTM(10)(visible)
hidden2 = Dense(10, activation='relu')(hidden1)
output = Dense(1, activation='sigmoid')(hidden2)
model = Model(inputs=visible, outputs=output)
model.summary()
plot_model(model, to_file='recurent_neural_network.png')
二.代码说明
代码用Keras定义一个用于序列分类的长短期记忆递归神经网络,该模型需要100个时间步长作为输入,该模型用单个LSTM隐藏层从序列中提取特征,然后用全连接层解释LSTM输出,最后用输出层进行二分类预测。
三.结果输出