stateful=True, reset . reset , stateful=False.
, :
for e in epoch:
for m in X.shape[0]:
for n in X.shape[1]:
, X
(m samples, n sequences, k features)
(batch size, number of timesteps, number of features)
, :
for n in X.shape[1]
,
for m in X.shape[0]
keras, ( , reset ). , reset , .
( ):
batch_size = 1
model = Sequential()
model.add(LSTM(16, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True))
model.add(Dense(y.shape[1], activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
for i in range(300):
model.fit(X, y, epochs=1, batch_size=batch_size, verbose=2, shuffle=False)
model.reset_states()