https://github.com/nixtla logo
#mlforecast
Title
# mlforecast
i

Isaac

08/11/2023, 2:16 PM
Is there a plan to add an equivalent of
forecast_fitted_values
to MLForecast?
I've written a function that I think performs the same operations in the meantime:
Copy code
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
j

José Morales

08/11/2023, 8:05 PM
Hey. We will implement something soon which will do something like this
🙌 1