pkiage commited on
Commit
d13a277
1 Parent(s): f61ac84

feat: add model type options

Browse files
Files changed (2) hide show
  1. src/app.py +37 -5
  2. src/features/build_features.py +8 -1
src/app.py CHANGED
@@ -20,29 +20,61 @@ def main():
20
 
21
  show_inputted_dataframe(data)
22
 
23
- time_series_line_and_box(data)
 
24
 
25
  st.header("Time series decomposition")
26
 
27
- decomposition = decompose_time_series(data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  standard_decomposition_plot(decomposition)
30
 
31
  [trend, seasonal, residual] = extract_trend_seasonal_resid(decomposition)
32
 
33
- with st.expander("Trend Plot"):
 
 
 
 
 
34
  st.write('The trend component of the data series.')
35
  st.write('Trend: secular variation(long-term, non-periodic variation)')
36
 
37
  time_series_line_plot(trend)
38
 
39
- with st.expander("Seasonality Plot"):
 
 
 
 
 
 
40
  st.write('The seasonal component of the data series.')
41
  st.write(
42
  'Seasonality: Periodic fluctuations (often at short-term intervals less than a year).')
43
  time_series_line_plot(seasonal)
44
 
45
- with st.expander("Residual Plot"):
 
 
 
 
 
 
46
  st.write('The residual component of the data series.')
47
  st.write('Residual: What remains after the other components have been removed (describes random, irregular influences).')
48
  st.write(f'Residual mean: {residual.mean():.4f}')
 
20
 
21
  show_inputted_dataframe(data)
22
 
23
+ with st.expander("Box plot"):
24
+ time_series_box_plot(data)
25
 
26
  st.header("Time series decomposition")
27
 
28
+ [decomposition, selected_model_type] = decompose_time_series(data)
29
+
30
+ model_types = ['Additive', 'Multiplicative']
31
+
32
+ if selected_model_type == model_types[0]:
33
+ st.subheader('Additive Model')
34
+ st.latex(r'''
35
+ Y[t] = T[t]+S[t]+e[t]
36
+ ''')
37
+
38
+ if selected_model_type == model_types[1]:
39
+ st.subheader('Multiplicative Model')
40
+ st.latex(r'''
41
+ Y[t] = T[t] \times S[t] \times e[t]
42
+ ''')
43
 
44
  standard_decomposition_plot(decomposition)
45
 
46
  [trend, seasonal, residual] = extract_trend_seasonal_resid(decomposition)
47
 
48
+ with st.expander("Time series Line Plot (Y[t])"):
49
+ time_series_line_plot(data)
50
+
51
+ st.latex(r'''=''')
52
+
53
+ with st.expander("Trend Plot (T[t])"):
54
  st.write('The trend component of the data series.')
55
  st.write('Trend: secular variation(long-term, non-periodic variation)')
56
 
57
  time_series_line_plot(trend)
58
 
59
+ if selected_model_type == model_types[0]:
60
+ st.latex(r'''+''')
61
+
62
+ if selected_model_type == model_types[1]:
63
+ st.latex(r'''\times''')
64
+
65
+ with st.expander("Seasonality Plot (S[t])"):
66
  st.write('The seasonal component of the data series.')
67
  st.write(
68
  'Seasonality: Periodic fluctuations (often at short-term intervals less than a year).')
69
  time_series_line_plot(seasonal)
70
 
71
+ if selected_model_type == model_types[0]:
72
+ st.latex(r'''+''')
73
+
74
+ if selected_model_type == model_types[1]:
75
+ st.latex(r'''\times''')
76
+
77
+ with st.expander("Residual Plot (e[t])"):
78
  st.write('The residual component of the data series.')
79
  st.write('Residual: What remains after the other components have been removed (describes random, irregular influences).')
80
  st.write(f'Residual mean: {residual.mean():.4f}')
src/features/build_features.py CHANGED
@@ -1,9 +1,16 @@
1
  import statsmodels.api as sm
2
  import pandas as pd
 
 
 
3
 
4
 
5
  def decompose_time_series(data):
6
- return sm.tsa.seasonal_decompose(data)
 
 
 
 
7
 
8
 
9
  def extract_trend_seasonal_resid(decomposition):
 
1
  import statsmodels.api as sm
2
  import pandas as pd
3
+ import streamlit as st
4
+
5
+ model_types = ['Additive', 'Multiplicative']
6
 
7
 
8
  def decompose_time_series(data):
9
+ selected_model_type = st.radio(
10
+ 'Model type:', model_types)
11
+ decomposition = sm.tsa.seasonal_decompose(
12
+ data, model=selected_model_type.lower())
13
+ return [decomposition, selected_model_type]
14
 
15
 
16
  def extract_trend_seasonal_resid(decomposition):