In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import keras
from keras.models import Sequential
from keras.layers import Dense, LSTM
from keras.utils import to_categorical
In [3]:
x = np.sin(np.arange(0, 4*np.pi, np.pi/64)).reshape(1, -1, 1)
In [4]:
y = np.append(x[:, 1:], [0]).reshape(1, -1, 1)
In [5]:
y.shape
Out[5]:
In [12]:
model = Sequential()
model.add(LSTM(10, input_shape=(None, 1), return_sequences=True))
model.add(Dense(1, activation='tanh'))
model.compile(loss='mse', optimizer='adam')
In [25]:
model.fit(x, y, epochs=5)
Out[25]:
In [26]:
pred = model.predict(x)[0]
In [27]:
plt.plot(pred)
Out[27]:
In [10]:
plt.plot(y[0])
Out[10]: