File size: 2,507 Bytes
7ab79fb
 
08225cd
 
 
7ab79fb
 
 
 
 
 
 
 
 
 
 
5293c01
 
7ab79fb
 
 
5293c01
 
 
 
 
7ab79fb
 
 
d13a277
 
 
 
 
 
 
 
 
 
 
 
 
7ab79fb
 
 
 
 
d13a277
 
 
 
 
 
7ab79fb
 
 
 
 
d13a277
 
 
 
 
 
 
7ab79fb
 
 
 
 
d13a277
 
 
 
 
 
 
7ab79fb
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
import streamlit as st
import pandas as pd
from src.data.utils import *
from src.visualization.visualize import *
from src.features.build_features import *


def main():

    st.title("Time Series Decomposition Demo")

    st.header("Data")

    sample_data_selected = st.selectbox(
        'Select sample data:', data_set_options)

    data, graph_data = import_sample_data(
        sample_data_selected, data_set_options)

    show_inputted_dataframe(data)

    with st.expander("Box Plot:"):
        time_series_box_plot(graph_data)

    with st.expander("Dist Plot (histogram and violin plot):"):
        time_series_violin_and_box_plot(data)

    st.header("Time series decomposition")

    [decomposition, selected_model_type] = decompose_time_series(data)

    if selected_model_type == model_types[0]:
        st.subheader('Additive Model')
        st.latex(r'''
        Y[t] = T[t]+S[t]+e[t]
        ''')

    if selected_model_type == model_types[1]:
        st.subheader('Multiplicative Model')
        st.latex(r'''
        Y[t] = T[t] \times S[t] \times e[t]
        ''')

    standard_decomposition_plot(decomposition)

    [trend, seasonal, residual] = extract_trend_seasonal_resid(decomposition)

    with st.expander("Time series Line Plot (Y[t])"):
        time_series_line_plot(data)

    st.latex(r'''=''')

    with st.expander("Trend Plot (T[t])"):
        st.write('The trend component of the data series.')
        st.write('Trend: secular variation(long-term, non-periodic variation)')

        time_series_line_plot(trend)

    if selected_model_type == model_types[0]:
        st.latex(r'''+''')

    if selected_model_type == model_types[1]:
        st.latex(r'''\times''')

    with st.expander("Seasonality Plot (S[t])"):
        st.write('The seasonal component of the data series.')
        st.write(
            'Seasonality: Periodic fluctuations (often at short-term intervals less than a year).')
        time_series_line_plot(seasonal)

    if selected_model_type == model_types[0]:
        st.latex(r'''+''')

    if selected_model_type == model_types[1]:
        st.latex(r'''\times''')

    with st.expander("Residual Plot (e[t])"):
        st.write('The residual component of the data series.')
        st.write('Residual: What remains after the other components have been removed (describes random, irregular influences).')
        st.write(f'Residual mean: {residual.mean():.4f}')
        time_series_scatter_plot(residual)


if __name__ == "__main__":
    main()