-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhome.py
78 lines (62 loc) · 2.38 KB
/
home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import pandas as pd
from orion import Orion
from utils import plot
from tensorflow.keras.utils import plot_model
import warnings
st.set_option('client.showErrorDetails', False)
st.set_option('deprecation.showPyplotGlobalUse', False)
warnings.filterwarnings("ignore")
@st.cache(allow_output_mutation=True)
def preprocess_data(data_file):
data = pd.read_csv(data_file, usecols=['Date', 'No. of Trades'], parse_dates=['Date'])
data.rename(columns={'No. of Trades': 'value', 'Date': 'timestamp'}, inplace=True)
data.sort_values(by='timestamp', inplace=True)
data.timestamp = (data.timestamp - pd.Timestamp("1970-01-01")) // pd.Timedelta("1s")
data = data[data.timestamp > 1640975400]
return data
@st.cache(allow_output_mutation=True)
def run_orion(data, epochs):
known_anomalies = pd.DataFrame({
'start': [1648751400],
'end': [1661970599]
})
hyperparameters = {
"mlprimitives.custom.timeseries_preprocessing.rolling_window_sequences#1": {
'target_column': 0,
'window_size': 100
},
'keras.Sequential.LSTMSeq2Seq#1': {
'epochs': epochs,
'verbose': True,
'window_size': 100,
'input_shape': [100, 1],
'target_shape': [100, 1]
}
}
orion = Orion(
pipeline='lstm_autoencoder',
hyperparameters=hyperparameters
)
anomalies = orion.fit_detect(data)
return anomalies, known_anomalies
def train(data_file, epochs) -> None:
data = preprocess_data(data_file)
anomalies, known_anomalies = run_orion(data, epochs)
plotImg = plot(data, 'Sharpline Broadcast Ltd. (543341)', anomalies=[anomalies, known_anomalies])
return anomalies, plotImg
st.set_page_config(layout="wide")
st.markdown("# <div style=\"text-align: center;\">Anomalies Detection</div>", unsafe_allow_html=True)
" "
" "
# Input file uploader for dataset
rawData = st.file_uploader("Add dataset")
# Epochs size slider
epochs = st.slider('Number of epochs?', 1, 15, 5)
# Button for training
__, col1, __ = st.columns([2,1,2])
if col1.button('Train🚂', use_container_width = True):
anomalies, plotImg = train(rawData, epochs)
__, col2, __ = st.columns([1,2,1])
col2.dataframe(anomalies, use_container_width = True)
st.pyplot(plotImg, True)