-
Notifications
You must be signed in to change notification settings - Fork 435
/
lstmaccuracy.py
32 lines (23 loc) · 1.18 KB
/
lstmaccuracy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
leng=3
data = [[i+j for j in range(leng)] for i in range(100)]
data = np.array(data, dtype=np.float32)
target = [[i+j+1 for j in range(leng)] for i in range(1,101)]
target = np.array(target, dtype=np.float32)
data = data.reshape(100, 1, leng)/200
target = target.reshape(100,1,leng)/200
# Build Model
model = Sequential()
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.add(LSTM(leng, input_shape=(1, leng),return_sequences=True,activation='sigmoid'))
model.compile(loss='mse', optimizer='adam',metrics=['accuracy'])
model.fit(data, target, nb_epoch=10000, batch_size=50,validation_data=(data,target))
predict = model.predict(data)