Isaac
08/11/2023, 2:16 PMforecast_fitted_values
to MLForecast?def get_in_sample_mlforecast(train_df, mfcster) -> pd.DataFrame:
"""Create in-sample predictions for MLForecast.
Arguments:
train_df (pd.DataFrame): Training data.
mfcster (MLForecast): Forecaster.
Returns:
pd.DataFrame: In-sample predictions.
"""
# Iterate through training dates.
train_dates = np.sort(train_df['ds'].unique())
def predict(date):
return (
mfcster.predict(
horizon=1,
new_data=train_df.query("ds <= @date"),
before_predict_callback=fill_with_zeros,
)
)
in_sample_df = pd.concat(
Parallel(n_jobs=12, timeout=99999)(
delayed(predict)(
date=date,
)
for date in train_dates[:-1]
),
ignore_index=True
)
return in_sample_df
José Morales
08/11/2023, 8:05 PM