Предсказание lstm autoencoder всегда начинается с нуля - PullRequest
0 голосов
/ 01 июля 2018

Я пытаюсь создать автоматический кодер LSTM, чтобы найти аномалии в наборе сигналов. Автоэнкодер, кажется, работает хорошо, за исключением начала кривых. В начале все восстановленные кривые начинаются с нуля. Фактически ноль здесь - среднее значение каждой кривой, поскольку я стандартизировал их. Посмотрите на это изображение

Пример оригинальной и реконструированной кривой

И это происходит для всех кривых. Тренировочные кривые выглядят так

Тренировочные кривые

Что мне здесь не хватает?

Автоэнкодер построен с использованием Keras следующим образом

input_dim = 1
latent_dim = 50
array_length = lstm_df.shape[1]

inputs = Input(shape=(array_length, input_dim))
# encoding
encoded = LSTM(latent_dim, return_sequences=True )(inputs)
decoded = LSTM(input_dim, return_sequences=True, activation='linear'(encoded)
# I also tried the default activation (tanh) here

sequence_autoencoder = Model(inputs, decoded)
sequence_autoencoder.compile(optimizer='rmsprop', loss='mean_squared_error')
# I also tried 'adam' optimizer

# And trained as follows

epochs = 80
history = sequence_autoencoder.fit(lstm_df.values.reshape(lstm_df.shape[0], array_length, input_dim), 
                                   lstm_df.values.reshape(lstm_df.shape[0], array_length, input_dim),
                                   verbose=True,
                                   epochs=epochs,
                                   batch_size=32,
                                   shuffle=True)
# Prediction
prediction = sequence_autoencoder.predict(test.values.reshape(test.shape[0], array_length, input_dim))
mse = np.power(test.values - prediction.reshape(test.shape), 2).mean(1)
error_df = pd.DataFrame({'reconstruction error': -mse.ravel()}, index=test.index)
# I am inverting the mse to stick to the convention, the smaller the more outlier 

outliers_fraction = .2

no_of_anomalies = int(len(error_df) * outliers_fraction)
anomolus_ids = error_df.sort_values('reconstruction error').head(no_of_anomalies).index

данные о поездах и тестах загружаются здесь https://github.com/h2oai/h2o-2/tree/master/smalldata/anomaly

ecg_discord_train.csv и ecg_discord_test.csv

...