Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
from prophet import Prophet
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
# Prepare data for Prophet
|
| 8 |
def prepare_prophet_data(usage_series):
|
|
@@ -13,19 +12,19 @@ def prepare_prophet_data(usage_series):
|
|
| 13 |
'ds': dates,
|
| 14 |
'y': usage_series
|
| 15 |
})
|
| 16 |
-
prophet_df['cap'] =
|
| 17 |
prophet_df['floor'] = 0
|
| 18 |
return prophet_df
|
| 19 |
|
| 20 |
-
# Train or update Prophet model
|
| 21 |
def train_model_with_usage(usage_series):
|
| 22 |
-
print("Training with changepoint_prior_scale=0.
|
| 23 |
prophet_df = prepare_prophet_data(usage_series)
|
| 24 |
model = Prophet(
|
| 25 |
yearly_seasonality=False,
|
| 26 |
weekly_seasonality=True,
|
| 27 |
daily_seasonality=True,
|
| 28 |
-
changepoint_prior_scale=0.
|
| 29 |
growth='logistic'
|
| 30 |
)
|
| 31 |
model.fit(prophet_df)
|
|
@@ -34,11 +33,11 @@ def train_model_with_usage(usage_series):
|
|
| 34 |
# Function to make forecasts
|
| 35 |
def make_forecast(model, periods):
|
| 36 |
future = model.make_future_dataframe(periods=periods)
|
| 37 |
-
future['cap'] =
|
| 38 |
future['floor'] = 0
|
| 39 |
forecast = model.predict(future)
|
| 40 |
daily_forecasts = forecast['yhat'].tail(periods).tolist()
|
| 41 |
-
print(f"Daily forecasts for {periods} days:", [round(y) for y in daily_forecasts]) # Debug
|
| 42 |
return round(sum(max(0, y) for y in daily_forecasts)) # Clip negative values
|
| 43 |
|
| 44 |
# Function to validate input
|
|
@@ -70,7 +69,7 @@ def main():
|
|
| 70 |
if error:
|
| 71 |
st.error(error)
|
| 72 |
return
|
| 73 |
-
|
| 74 |
|
| 75 |
try:
|
| 76 |
model = train_model_with_usage(usage_list)
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from prophet import Prophet
|
| 4 |
from datetime import datetime, timedelta
|
|
|
|
| 5 |
|
| 6 |
# Prepare data for Prophet
|
| 7 |
def prepare_prophet_data(usage_series):
|
|
|
|
| 12 |
'ds': dates,
|
| 13 |
'y': usage_series
|
| 14 |
})
|
| 15 |
+
prophet_df['cap'] = 30 # Lowered to 30
|
| 16 |
prophet_df['floor'] = 0
|
| 17 |
return prophet_df
|
| 18 |
|
| 19 |
+
# Train or update Prophet model
|
| 20 |
def train_model_with_usage(usage_series):
|
| 21 |
+
print("Training with changepoint_prior_scale=0.001, usage:", usage_series) # Debug to logs
|
| 22 |
prophet_df = prepare_prophet_data(usage_series)
|
| 23 |
model = Prophet(
|
| 24 |
yearly_seasonality=False,
|
| 25 |
weekly_seasonality=True,
|
| 26 |
daily_seasonality=True,
|
| 27 |
+
changepoint_prior_scale=0.001, # Lowered to 0.001
|
| 28 |
growth='logistic'
|
| 29 |
)
|
| 30 |
model.fit(prophet_df)
|
|
|
|
| 33 |
# Function to make forecasts
|
| 34 |
def make_forecast(model, periods):
|
| 35 |
future = model.make_future_dataframe(periods=periods)
|
| 36 |
+
future['cap'] = 30
|
| 37 |
future['floor'] = 0
|
| 38 |
forecast = model.predict(future)
|
| 39 |
daily_forecasts = forecast['yhat'].tail(periods).tolist()
|
| 40 |
+
print(f"Daily forecasts for {periods} days:", [round(y) for y in daily_forecasts]) # Debug to logs
|
| 41 |
return round(sum(max(0, y) for y in daily_forecasts)) # Clip negative values
|
| 42 |
|
| 43 |
# Function to validate input
|
|
|
|
| 69 |
if error:
|
| 70 |
st.error(error)
|
| 71 |
return
|
| 72 |
+
print("Input usage series:", usage_list) # Debug to logs
|
| 73 |
|
| 74 |
try:
|
| 75 |
model = train_model_with_usage(usage_list)
|