Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #243 #245

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions examples/timeseries/timeseries_anomaly_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@

We will use the following data for training.
"""

df_small_noise.plot(legend=False)
fig, ax = plt.subplots()
df_small_noise.plot(legend=False, ax=ax)
plt.show()

"""
### Timeseries data with anomalies

We will use the following data for testing and see if the sudden jump up in the
data is detected as an anomaly.
"""

df_daily_jumpsup.plot(legend=False)
fig, ax = plt.subplots()
df_daily_jumpsup.plot(legend=False, ax=ax)
plt.show()

"""
## Prepare training data
Expand Down Expand Up @@ -170,6 +172,7 @@ def create_sequences(values, time_steps=TIME_STEPS):
plt.plot(history.history["loss"], label="Training Loss")
plt.plot(history.history["val_loss"], label="Validation Loss")
plt.legend()
plt.show()

"""
## Detecting anomalies
Expand Down Expand Up @@ -211,7 +214,6 @@ def create_sequences(values, time_steps=TIME_STEPS):

# Checking how the first sequence is learnt
plt.plot(x_train[0])
plt.show()
plt.plot(x_train_pred[0])
plt.show()

Expand All @@ -227,7 +229,9 @@ def normalize_test(values, mean, std):


df_test_value = (df_daily_jumpsup - training_mean) / training_std
df_test_value.plot(legend=False)
fig, ax = plt.subplots()
df_test_value.plot(legend=False, ax=ax)
plt.show()

# Create sequences from test values.
x_test = create_sequences(df_test_value.values)
Expand Down Expand Up @@ -284,5 +288,7 @@ def normalize_test(values, mean, std):
"""

df_subset = df_daily_jumpsup.iloc[anomalous_data_indices]
ax = df_daily_jumpsup.plot(legend=False)
fig, ax = plt.subplots()
df_daily_jumpsup.plot(legend=False, ax=ax)
df_subset.plot(legend=False, ax=ax, color="r")
plt.show()