In [9]:
from keras.models import Sequential
from keras.layers import LSTM, Dense, Activation
from keras.optimizers import SGD
In [6]:
model = Sequential()
model.add(LSTM(5, input_shape=(2, 1)))
model.add(Dense(1))
model.add(Activation('sigmoid'))
In [7]:
model.compile(optimizer='sgd', loss='mse')
In [10]:
algorithm = SGD(lr=0.1, momentum=0.3)
model.compile(optimizer=algorithm, loss='mse')
In [11]:
model.compile(optimizer='sgd', loss='mean_squared_error', metrics=['accuracy'])
In [18]:
import numpy as np
data = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
In [19]:
data
Out[19]:
In [20]:
# (1 sample, 10 time steps, 1 feature) のテンソルに変換
data = data.reshape((1, 10, 1))
In [21]:
data.shape
Out[21]:
In [22]:
data = np.array([
[0.1, 1.0],
[0.2, 0.9],
[0.3, 0.8],
[0.4, 0.7],
[0.5, 0.6],
[0.6, 0.5],
[0.7, 0.4],
[0.8, 0.3],
[0.9, 0.2],
[1.0, 0.1]
])
In [23]:
data.shape
Out[23]:
In [24]:
# (1 sample, 10 timesteps, 2 features) のテンソルに変換
data = data.reshape(1, 10, 2)
In [25]:
data.shape
Out[25]:
In [ ]: