DataScienceGuild/ARIMA_test
1
1# Import necessary libraries2import streamlit as st3import pandas as pd4from pmdarima import auto_arima5import matplotlib.pyplot as plt6 7# Title of the Streamlit app8st.title('Auto ARIMA Time Series Analysis')9 10# Upload CSV data11uploaded_file = st.file_uploader("Choose a CSV file", type='csv')12 13if uploaded_file is not None:14 # Read the uploaded CSV file with pandas15 df = pd.read_csv(uploaded_file)16 17 # Convert timestamp column to datetime format and set it as index 18 df['timestamp'] = pd.to_datetime(df['timestamp'])19 df.set_index('timestamp', inplace=True)20 21 # Perform Auto ARIMA analysis on value column22 model = auto_arima(df['value'], trace=True, error_action='ignore', suppress_warnings=True)23 24 # Fit the model and get predictions for next 10 periods 25 model.fit(df['value'])26 predictions = model.predict(n_periods=10)27 28 # Display model summary in Streamlit app 29 st.write(model.summary())30 31 # Create a plot with Matplotlib and display it in Streamlit app 32 fig, ax = plt.subplots()33 34 ax.plot(df.index, df['value'], label='Original')35 36 prediction_index = pd.date_range(start=df.index[-1], periods=11)[1:]37 38 ax.plot(prediction_index, predictions, label='Predicted')39 40 plt.title('Value vs Timestamp')41 42 plt.legend()43 44 st.pyplot(fig)45 46 # Create a plot with Matplotlib and display it in Streamlit app 47 fig2, ax2 = plt.subplots()48 49 ax2.plot(df.index, df['value'], label='Original')50 51 prediction_index = pd.date_range(start=df.index[-1], periods=11)[1:]52 53 # ax2.plot(prediction_index, predictions, label='Predicted')54 55 plt.title('Value vs Timestamp original only')56 57 plt.legend()58 59 st.pyplot(fig2)