Update inference.py
Browse files- inference.py +20 -20
inference.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import pickle
|
| 3 |
-
from datetime import datetime
|
| 4 |
-
|
| 5 |
-
def predict_expense(input_date_str):
|
| 6 |
-
"""Predicts the expense for the given date."""
|
| 7 |
-
|
| 8 |
-
# Load the model
|
| 9 |
-
with open("expense_forecaster_model.pkl", "rb") as model_file:
|
| 10 |
-
model = pickle.load(model_file)
|
| 11 |
-
|
| 12 |
-
# Preprocess input (convert date to numerical feature)
|
| 13 |
-
input_date = pd.to_datetime(input_date_str)
|
| 14 |
-
# Use the minimum date from your training data (2024-01-01) as a reference point
|
| 15 |
-
min_date = pd.to_datetime("2024-01-01")
|
| 16 |
-
numerical_date = (input_date - min_date) / pd.Timedelta(days=30)
|
| 17 |
-
|
| 18 |
-
# Make prediction
|
| 19 |
-
prediction = model.predict(pd.DataFrame({"ds": [numerical_date]}))
|
| 20 |
-
|
| 21 |
return prediction[0]
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import pickle
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
def predict_expense(input_date_str):
|
| 6 |
+
"""Predicts the expense for the given date."""
|
| 7 |
+
|
| 8 |
+
# Load the model
|
| 9 |
+
with open("model/expense_forecaster_model.pkl", "rb") as model_file:
|
| 10 |
+
model = pickle.load(model_file)
|
| 11 |
+
|
| 12 |
+
# Preprocess input (convert date to numerical feature)
|
| 13 |
+
input_date = pd.to_datetime(input_date_str)
|
| 14 |
+
# Use the minimum date from your training data (2024-01-01) as a reference point
|
| 15 |
+
min_date = pd.to_datetime("2024-01-01")
|
| 16 |
+
numerical_date = (input_date - min_date) / pd.Timedelta(days=30)
|
| 17 |
+
|
| 18 |
+
# Make prediction
|
| 19 |
+
prediction = model.predict(pd.DataFrame({"ds": [numerical_date]}))
|
| 20 |
+
|
| 21 |
return prediction[0]
|