Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- arima.py +37 -0
- arima_model.pkl +3 -0
arima.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
st.title("Future crime pattern prediction ")
|
| 7 |
+
|
| 8 |
+
# Load the trained ARIMA model
|
| 9 |
+
with open(r"C:\Users\hp\Desktop\project\model\arima\arima_model.pkl", 'rb') as f:
|
| 10 |
+
model_fit = pickle.load(f)
|
| 11 |
+
|
| 12 |
+
# Define number of future periods for forecasting
|
| 13 |
+
future_steps = st.number_input("Enter number of months to forecast:", value=12, min_value=1, step=1)
|
| 14 |
+
#start_date_input = st.date_input("Enter start date for the forecast:", value=pd.Timestamp.today())
|
| 15 |
+
|
| 16 |
+
# Convert the user input date to a pandas Timestamp for compatibility
|
| 17 |
+
start_date = pd.to_datetime("2024-03-2")
|
| 18 |
+
|
| 19 |
+
# Forecast future crime patterns
|
| 20 |
+
future_forecast = model_fit.forecast(steps=future_steps)
|
| 21 |
+
|
| 22 |
+
# Get the dates for the forecasted period
|
| 23 |
+
future_dates = pd.date_range(start=start_date, periods=future_steps + 1, freq='ME')[1:]
|
| 24 |
+
# Plot forecasted values
|
| 25 |
+
plt.figure(figsize=(10, 6))
|
| 26 |
+
plt.plot(future_dates, future_forecast, label="Forecast")
|
| 27 |
+
#plt.fill_between(future_dates, conf_int[:, 0], conf_int[:, 1], color='gray', alpha=0.3, label='95% Confidence Interval')
|
| 28 |
+
plt.legend()
|
| 29 |
+
plt.title("Future Crime Forecast")
|
| 30 |
+
plt.xlabel("Date")
|
| 31 |
+
plt.ylabel("Predicted Crime Count")
|
| 32 |
+
st.pyplot(plt)
|
| 33 |
+
|
| 34 |
+
# Display forecasted values
|
| 35 |
+
st.write(f"Forecasted values for the next {future_steps} months:")
|
| 36 |
+
st.write(future_forecast)
|
| 37 |
+
|
arima_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a0dc6d9b51cb4a8dccddc7b865981b7d140392f975d8818efaecbac3426cf18
|
| 3 |
+
size 724531
|