final-project / prediction.py
mukhlishr's picture
Update prediction.py
209ef81
raw
history blame
1.26 kB
import streamlit as st
import numpy as np
import pandas as pd
import pickle
from statsmodels.tsa.arima.model import ARIMA
from datetime import datetime
st.set_page_config(
page_title = 'Forecasting',
layout = 'wide',
initial_sidebar_state='expanded'
)
with open('mod_train.pkl', 'rb') as file_1:
mod_train = pickle.load(file_1)
# bikin fungsi
def run():
with st.form(key='Forecasting'):
year = st.selectbox('Year', (2023,2024), index=0)
month = st.selectbox('Month', (1,2,3,4,5,6,7,8,9,10,11,12), index=3)
st.markdown('---')
submitted = st.form_submit_button('Predict')
data_inf = {
'year' : year,
'month': month
}
data_inf = pd.DataFrame([data_inf])
data_inf['date'] = data_inf.apply(lambda x: datetime(x[0], x[1], 1), axis=1)
data_inf.drop(['year','month'], axis=1, inplace=True)
data_inf=data_inf.set_index('date')
#st.dataframe(data_inf)
if submitted:
#Predict Inference data
y_pred_test=mod_train.predict(start=data_inf.index[0],end=data_inf.index[-1])
y_pred_test=pd.DataFrame(y_pred_test)
y_pred_test.columns=['quantity_predict']
st.write('# Forcasted quantity for that month is : ', y_pred_test)
if __name__ == '__main__':
run()