Hi everyone, I'm trying to use the PredictionInter...
# general
l
Hi everyone, I'm trying to use the PredictionIntervals on MLForecast. But I keep getting this error:
Copy code
mlf.fit(
    train_df,
    prediction_intervals=PredictionIntervals(n_windows=2, h=horizon),
)

Unexpected exception formatting exception. Falling back to standard exception
Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/tmp/ipykernel_33/4086377508.py", line 1, in <module>
    mlf.fit(
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/utils.py", line 186, in inner
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/forecast.py", line 376, in fit
    X = prep[self.ts.features_order_]
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/forecast.py", line 308, in _conformity_scores
    h: int = 1,
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/utils.py", line 186, in inner
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/forecast.py", line 685, in cross_validation
    keep_last_n=self.ts.keep_last_n,
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/utils.py", line 186, in inner
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/forecast.py", line 489, in predict
    self._cs_df: Optional[DataFrame] = None
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/core.py", line 575, in predict
    self.curr_dates = self.curr_dates[self._idxs]
  File "/opt/conda/lib/python3.10/site-packages/mlforecast/core.py", line 505, in _predict_recursive
    )
UnboundLocalError: local variable 'preds' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2144, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1435, in structured_traceback
    return FormattedTB.structured_traceback(
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1326, in structured_traceback
    return VerboseTB.structured_traceback(
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1173, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 1088, in format_exception_as_a_whole
    frames.append(self.format_record(record))
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 970, in format_record
    frame_info.lines, Colors, self.has_colors, lvals
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/ultratb.py", line 792, in lines
    return self._sd.lines
  File "/opt/conda/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/opt/conda/lib/python3.10/site-packages/stack_data/core.py", line 734, in lines
    pieces = self.included_pieces
  File "/opt/conda/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/opt/conda/lib/python3.10/site-packages/stack_data/core.py", line 681, in included_pieces
    pos = scope_pieces.index(self.executing_piece)
  File "/opt/conda/lib/python3.10/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/opt/conda/lib/python3.10/site-packages/stack_data/core.py", line 660, in executing_piece
    return only(
  File "/opt/conda/lib/python3.10/site-packages/executing/executing.py", line 116, in only
    raise NotOneValueFound('Expected one value, found 0')
executing.executing.NotOneValueFound: Expected one value, found 0
j
Hey. Which version of mlforecast are you using?
l
Hi again José, I'm using 0.11.7
j
It's a bit weird, the lines don't match. It says line 505 in
_predict_recursive
, but line 505 is in fit_transform. The place I could see that error happening is here but
preds
is assigned on the first iteration. Are you able to reproduce this error with synthetic data?