salsabilapl commited on
Commit
2b31d20
1 Parent(s): 5c2e636

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -17
app.py CHANGED
@@ -1,29 +1,44 @@
 
 
 
 
1
  from statsmodels.tsa.statespace.varmax import VARMAX
2
  import matplotlib.pyplot as plt
3
  import statsmodels.api as sm
4
- import pandas as pd
5
- import numpy as np
6
 
7
- import warnings
8
- warnings.filterwarnings('ignore')
9
 
10
- import streamlit as st
11
- import joblib
12
 
 
 
 
13
 
14
- fitted_model = joblib.load('modelling_all123.sav')
15
- predict=fitted_model.get_prediction(start=1401,end=1430, dynamic=True)
 
 
 
 
 
 
 
16
 
17
- predictions=predict.predicted_mean
 
 
18
 
19
- predictions
 
20
 
 
 
21
 
22
- predictions['Harga Bawang']=predictions['Harga Bawang'].round()
23
- predictions.columns=['Prediction Harga Bawang',
24
- 'Prediction T2M',
25
- 'Prediction WS10M_RANGE',
26
- 'Prediction PRECTOTCORR']
27
- predictions=predictions.abs()
28
 
29
- predictions
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
  from statsmodels.tsa.statespace.varmax import VARMAX
6
  import matplotlib.pyplot as plt
7
  import statsmodels.api as sm
 
 
8
 
9
+ # Load the pre-trained model
10
+ fitted_model = joblib.load('modelling_all123.sav')
11
 
12
+ # Streamlit App
13
+ st.title("Time Series Prediction Dashboard")
14
 
15
+ # Date Range Input
16
+ start_date = st.date_input("Select Start Date", pd.to_datetime('2024-01-01'))
17
+ end_date = st.date_input("Select End Date", pd.to_datetime('2024-01-30'))
18
 
19
+ # Make predictions based on user input
20
+ predict = fitted_model.get_prediction(start=start_date, end=end_date, dynamic=True)
21
+ predictions = predict.predicted_mean
22
+ predictions['Harga Bawang'] = predictions['Harga Bawang'].round()
23
+ predictions.columns = ['Prediction Harga Bawang',
24
+ 'Prediction T2M',
25
+ 'Prediction WS10M_RANGE',
26
+ 'Prediction PRECTOTCORR']
27
+ predictions = predictions.abs()
28
 
29
+ # Display Predictions Table
30
+ st.subheader("Predictions for the Selected Time Period")
31
+ st.write(predictions)
32
 
33
+ # Plotting Predictions
34
+ fig, ax = plt.subplots(figsize=(10, 6))
35
 
36
+ for column in predictions.columns:
37
+ ax.plot(predictions.index, predictions[column], label=column)
38
 
39
+ ax.set_xlabel("Time Period")
40
+ ax.set_ylabel("Predicted Values")
41
+ ax.set_title("Time Series Predictions")
 
 
 
42
 
43
+ # Show plot in Streamlit
44
+ st.pyplot(fig)