File size: 725 Bytes
3ffdcac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import numpy as np
from joblib import load
model = load("model.pkl")
def forecast_consumables(usage_series, days):
forecast = []
current_series = usage_series.copy()
for _ in range(days):
# Prepare the input for prediction (last 60 days)
input_series = np.array(current_series[-60:]).reshape(1, -1)
# Predict the next day's usage
next_usage = model.predict(input_series)[0]
next_usage = max(0, int(next_usage)) # Ensure non-negative and integer
next_usage = min(next_usage, 100) # Cap at 100
forecast.append(next_usage)
# Append the predicted usage for the next iteration
current_series.append(next_usage)
return forecast |