mlforecast icon indicating copy to clipboard operation
mlforecast copied to clipboard

MLForecast+Prediction Intervals+Transfer Learning

Open saad1912 opened this issue 2 years ago • 1 comments

What happened + What you expected to happen

I am trying to predict target components over prediction intervals using Transfer Learning approach. But I am getting below error:


ValueError Traceback (most recent call last) in <cell line: 2>() 1 levels = [20, 75,80, 95] ----> 2 forecasts = mlf.predict(7, level=levels, new_df=df3) 3 forecasts.head()

/usr/local/lib/python3.10/dist-packages/mlforecast/forecast.py in predict(self, h, before_predict_callback, after_predict_callback, new_df, level, X_df, ids) 706 if new_df is not None: 707 if level is not None: --> 708 raise ValueError( 709 "Prediction intervals are not supported in transfer learning." 710 )

ValueError: Prediction intervals are not supported in transfer learning. image

Versions / Dependencies

import mlforecast print(mlforecast.version)

0.15.0

Reproduction script

Y_df_M3, _, _ = M3.load(directory='./', group='Monthly') models = [lgb.LGBMRegressor(verbosity=-1)]

fcst = MLForecast( models=models, lags=range(1, 13), freq='MS', target_transforms=[Differences([1, 12])], ) fcst.fit(Y_df_M3); Y_df = pd.read_csv('https://datasets-nixtla.s3.amazonaws.com/air-passengers.csv', parse_dates=['ds'])

We define the train df.

Y_train_df = Y_df[Y_df.ds<='1959-12-31'] # 132 train Y_test_df = Y_df[Y_df.ds>'1959-12-31'] # 12 test

levels = [50, 80, 95] Y_hat_df = fcst.predict(h=12, level = levels, new_df=Y_train_df) Y_hat_df.head()


ValueError Traceback (most recent call last) in <cell line: 2>() 1 levels = [50, 80, 95] ----> 2 Y_hat_df = fcst.predict(h=12, level = levels, new_df=Y_train_df) 3 Y_hat_df.head()

/usr/local/lib/python3.10/dist-packages/mlforecast/forecast.py in predict(self, h, before_predict_callback, after_predict_callback, new_df, level, X_df, ids) 706 if new_df is not None: 707 if level is not None: --> 708 raise ValueError( 709 "Prediction intervals are not supported in transfer learning." 710 )

ValueError: Prediction intervals are not supported in transfer learning.

Issue Severity

High: It blocks me from completing my task.

saad1912 avatar Nov 25 '24 06:11 saad1912

Hi, I am encountering this issue too. Did you find a workarount ? Moreover, I really could'nt wrap my head around why is the model is refitted when doing a predict with new_df. Help needed pls!

Baptiste-ms avatar Jul 11 '25 16:07 Baptiste-ms