I am trying to find an anomaly in Time series with the LSTM. And I am still wondering, what should be the right architecture, timesteps, batch-size, sliding or non-sliding windows for finding an anomaly based on time series past behaviour
from numpy import array
from keras.models import Sequential, Model
from keras.layers import Input, Dense, LSTM,
RepeatVector,TimeDistributed
from keras import optimizers
from keras.callbacks import EarlyStopping
X = array([0.1, 0.2, 0.3, 0.4, 25, 0.5, 0.6, 0.7])
X_train = X.reshape(1, 8, 1)
y = X.reshape(1, 8)
model = Sequential()
model.add(LSTM(4, input_shape=(8, 1), return_sequences=True))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mean_squared_error', optimizer='adam')
print(model.summary())
history = model.fit(X_train, y, epochs=500, batch_size=1, verbose=2)
result = model.predict(X_train, batch_size=1, verbose=0)
It give me an output of
[0.11906812, 0.19180197, 0.30324116, 0.14811686, 25.3771758 ,
0.52173275, 0.61532116, 0.7421335]
It is not looking like an anomaly sign to me. Is stateful a better way to find anomaly based on past behaviour? Even a normal Gaussian distribution can easily tell me the anomaly here, but it won't take the time effect