update
Browse files
app.py
CHANGED
|
@@ -3,10 +3,21 @@ from huggingface_hub import from_pretrained_keras
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import json
|
|
|
|
| 6 |
|
| 7 |
f = open('scaler.json')
|
| 8 |
scaler = json.load(f)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def normalize_data(data):
|
| 11 |
df_test_value = (data - scaler["mean"]) / scaler["std"]
|
| 12 |
return df_test_value
|
|
@@ -27,7 +38,7 @@ def get_anomalies(df_test_value):
|
|
| 27 |
test_mae_loss = test_mae_loss.reshape((-1))
|
| 28 |
|
| 29 |
# Detect all the samples which are anomalies.
|
| 30 |
-
anomalies = test_mae_loss > threshold
|
| 31 |
return anomalies
|
| 32 |
|
| 33 |
def plot_anomalies(df_test_value, data, anomalies):
|
|
@@ -59,9 +70,8 @@ gr.inputs.File(label="csv file"),
|
|
| 59 |
outputs=['plot'],
|
| 60 |
examples=["art_daily_jumpsup.csv"], title="Anomaly detection of timeseries data",
|
| 61 |
description = "Anomaly detection of timeseries data.",
|
| 62 |
-
article = "Space by: <a href=\"https://www.linkedin.com/in/olohireme-ajayi/\">Reme Ajayi</a> /n Keras Example by <a href=\"https://github.com/pavithrasv/\"> Pavithra Vijay</a>"
|
| 63 |
|
| 64 |
-
)
|
| 65 |
|
| 66 |
|
| 67 |
iface.launch()
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
import json
|
| 6 |
+
from matplotlib import pyplot as plt
|
| 7 |
|
| 8 |
f = open('scaler.json')
|
| 9 |
scaler = json.load(f)
|
| 10 |
|
| 11 |
+
TIME_STEPS = 288
|
| 12 |
+
|
| 13 |
+
# Generated training sequences for use in the model.
|
| 14 |
+
def create_sequences(values, time_steps=TIME_STEPS):
|
| 15 |
+
output = []
|
| 16 |
+
for i in range(len(values) - time_steps + 1):
|
| 17 |
+
output.append(values[i : (i + time_steps)])
|
| 18 |
+
return np.stack(output)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def normalize_data(data):
|
| 22 |
df_test_value = (data - scaler["mean"]) / scaler["std"]
|
| 23 |
return df_test_value
|
|
|
|
| 38 |
test_mae_loss = test_mae_loss.reshape((-1))
|
| 39 |
|
| 40 |
# Detect all the samples which are anomalies.
|
| 41 |
+
anomalies = test_mae_loss > scaler["threshold"]
|
| 42 |
return anomalies
|
| 43 |
|
| 44 |
def plot_anomalies(df_test_value, data, anomalies):
|
|
|
|
| 70 |
outputs=['plot'],
|
| 71 |
examples=["art_daily_jumpsup.csv"], title="Anomaly detection of timeseries data",
|
| 72 |
description = "Anomaly detection of timeseries data.",
|
| 73 |
+
article = "Space by: <a href=\"https://www.linkedin.com/in/olohireme-ajayi/\">Reme Ajayi</a> /n Keras Example by <a href=\"https://github.com/pavithrasv/\"> Pavithra Vijay</a>")
|
| 74 |
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
iface.launch()
|