major overhaul of forecast pipeline #21

Merged
foefl merged 15 commits from prediction_to_future into main 2025-04-16 09:24:34 +00:00
Showing only changes of commit 104adaf2c5 - Show all commits

View File

@ -223,7 +223,7 @@ def _process_sales(
future_dates = pd.date_range(
start=last_date + pd.DateOffset(months=1), periods=6, freq="MS"
)
forecast = pd.DataFrame({"datum": future_dates.strftime("%m.%Y")}).set_index("datum")
forecast = pd.DataFrame({"datum": future_dates}).set_index("datum")
# Randomized Search
kfold = KFold(n_splits=5, shuffle=True)
@ -255,8 +255,8 @@ def _process_sales(
# print("dates: ", dates)
# ?? --- new: use monthly basis for time windows
# baseline: 3 years - 36 months
starting_date = datetime.datetime.now() - relativedelta(months=36)
# starting_date = dates.max() - relativedelta(months=36)
# starting_date = datetime.datetime.now() - relativedelta(months=36)
starting_date = dates.max() - relativedelta(months=36)
start_index = next(
(i for i, date in enumerate(dates) if date >= starting_date), len(dates) - 1
)
@ -319,6 +319,9 @@ def _process_sales(
)
y_future = best_estimator.predict(X_future) # type: ignore
forecast["vorhersage"] = y_future
forecast["jahr"] = forecast.index.year # type: ignore
forecast["monat"] = forecast.index.month # type: ignore
forecast = forecast.reset_index(drop=True)
best_score_mae = best_score_mae if not math.isinf(best_score_mae) else None