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


Using TensorFlow backend.

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]:
(1, 256, 1)

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)


Epoch 1/5
1/1 [==============================] - 0s 142ms/step - loss: 0.4775
Epoch 2/5
1/1 [==============================] - 0s 133ms/step - loss: 0.4722
Epoch 3/5
1/1 [==============================] - 0s 140ms/step - loss: 0.4670
Epoch 4/5
1/1 [==============================] - 0s 157ms/step - loss: 0.4618
Epoch 5/5
1/1 [==============================] - 0s 133ms/step - loss: 0.4566
Out[25]:
<keras.callbacks.History at 0x7f1023579cf8>

In [26]:
pred = model.predict(x)[0]

In [27]:
plt.plot(pred)


Out[27]:
[<matplotlib.lines.Line2D at 0x7f1023486c50>]

In [10]:
plt.plot(y[0])


Out[10]:
[<matplotlib.lines.Line2D at 0x7f105c3c6cf8>]