Hi <@U03UX9KR75W> Thanks for all your help! :slig...
# mlforecast
q
Hi @José Morales Thanks for all your help! 🙂 I'm trying to generate some conformal prediction intervals as follows:
Copy code
lgb_params = {
    'verbosity': -1,
    'learning_rate': 0.1,
    'num_leaves': 512,
    'objective': 'rmse',
    'num_iterations': 175
}

fcst = MLForecast(
    models={
        'avg': lgb.LGBMRegressor(**lgb_params)
    },
    freq=1,
    lags=[1,2,3,4,5,6],
    lag_transforms={
        1: [
            ExponentiallyWeightedMean(alpha=0.5), 
            RollingMean(window_size=2), 
            RollingMean(window_size=4), 
            RollingMean(window_size=6),
            RollingMean(window_size=12),
            RollingQuantile(window_size=2, p=0.5),
            RollingQuantile(window_size=4, p=0.5),
            RollingQuantile(window_size=6, p=0.5),
            RollingStd(window_size=2),
            RollingStd(window_size=4)
        ],
        2: [RollingMean(window_size=2)],
        4: [RollingMean(window_size=2)],
        6: [
            RollingMean(window_size=4),
            RollingMean(window_size=6),
            RollingStd(window_size=2),
        ]
    },
    num_threads=32
)
fcst.fit(
    transformed_df,
    prediction_intervals=PredictionIntervals(n_windows=20, h=5),
    fitted=True)
When I call predict() with the interval levels,
Copy code
predictions_w_intervals = fcst.predict(h=5, level=[80, 95])
predictions_w_intervals.head()
I get the following error:
Copy code
ValueError                                Traceback (most recent call last)
Cell In[53], line 1
----> 1 predictions_w_intervals = fcst.predict(h=5, level=[80, 95])
      2 predictions_w_intervals.head()

File /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages/mlforecast/forecast.py:743, in MLForecast.predict(self, h, before_predict_callback, after_predict_callback, new_df, level, X_df, ids)
    741             cs_df = self._cs_df
    742             n_series = self.ts.ga.n_groups
--> 743         forecasts = conformal_method(
    744             forecasts,
    745             cs_df,
    746             model_names=list(model_names),
    747             level=level_,
    748             cs_h=self.prediction_intervals.h,
    749             cs_n_windows=self.prediction_intervals.n_windows,
    750             n_series=n_series,
    751             horizon=h,
    752         )
    753 return forecasts

File /anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages/mlforecast/forecast.py:60, in _add_conformal_distribution_intervals(fcst_df, cs_df, model_names, level, cs_n_windows, cs_h, n_series, horizon)
     58 cuts.extend(1 - alpha / 200 for alpha in alphas)
     59 for model in model_names:
---> 60     scores = cs_df[model].to_numpy().reshape(cs_n_windows, n_series, cs_h)
     61     # restrict scores to horizon
     62     scores = scores[:, :, :horizon]

ValueError: cannot reshape array of size 383870 into shape (20,6036,5)
j
Which version are you using? I believe this is due to some series not having enough samples for the 20 windows, which should raise an error
q
mlforecast==0.13.0 yes, during training, some of the time series were omitted :/
is there a way to return all the
unique_id
that were omitted during training? i get the following message at the beginning of training:
Copy code
/anaconda/envs/azureml_py310_sdkv2/lib/python3.10/site-packages/utilsforecast/processing.py:737: UserWarning: The following series are too short for the window and will be dropped:
j
From 0.13.2 an error is raised. You can't use prediction intervals if some series can't produce scores
👍 1
q
i see!
got it
think we'll just go with dropna=False, for now. thanks @José Morales!!! 😄
👍 1
j
The lag_transforms that you're using also have a min_samples argument which you can set to 1 in order to not produce NaNs
🙌 1
q
oh i see! neat feature!