Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from pmdarima import auto_arima
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
|
| 7 |
+
# Title of the Streamlit app
|
| 8 |
+
st.title('Auto ARIMA Time Series Analysis')
|
| 9 |
+
|
| 10 |
+
# Upload CSV data
|
| 11 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type='csv')
|
| 12 |
+
|
| 13 |
+
if uploaded_file is not None:
|
| 14 |
+
# Read the uploaded CSV file with pandas
|
| 15 |
+
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 column
|
| 22 |
+
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)
|