AjaykumarPilla commited on
Commit
3ffdcac
·
verified ·
1 Parent(s): 4c8a027

Upload forecast_engine.py

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