Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import plotly.express as px | |
| from statsforecast import StatsForecast | |
| from statsforecast.models import seasonal_naive, auto_arima | |
| st.title('Forecasting time series') | |
| uploaded_file = st.file_uploader("Choose a CSV file", accept_multiple_files=False) | |
| if uploaded_file is not None: | |
| dataframe = pd.read_csv(uploaded_file) | |
| st.write(dataframe) | |
| series = st.text_input("Write the name of the variable you want to forecast") | |
| date = st.text_input("Write the first date") | |
| freq = st.text_input("Write the frequency") | |
| horizons = st.text_input("Write the number of horizons") | |
| if series is not None: | |
| series_train = pd.DataFrame( | |
| { | |
| 'ds': pd.date_range(start=date, periods=dataframe.shape[0], freq=freq), | |
| 'y': dataframe[series].values | |
| }, | |
| index=pd.Index([0] * dataframe.shape[0], name='unique_id') | |
| ) | |
| fig = px.line(series_train, x='ds', y='y', title=f'{series}') | |
| st.plotly_chart(fig) | |
| fcst = StatsForecast( | |
| series_train, | |
| models=[(auto_arima, 12), (seasonal_naive, 12)], | |
| freq=freq, | |
| n_jobs=1 | |
| ) | |
| forecasts = fcst.forecast(horizons, level=(80, 95)) | |