prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Calling `cross_validation(model)` without `model.fit` throws AttributeError

Open ivanmkc opened this issue 2 years ago • 1 comments

Calling cross_validation(model) without calling model.fit first throws AttributeError.

[def cross_validation(model, horizon, period=None, initial=None, parallel=None, cutoffs=None):]()
...
    df = model.history.copy().reset_index(drop=True]()
    
    AttributeError: 'NoneType' object has no attribute 'copy']()
  1. If fit is required to be run before cross_validation, I would expect an appropriate error to be thrown with an actionable fix by the user.
  2. Assuming that the assumption in 1) is true, why does fit have to be called first? As I understand, fit uses the entire history to fit the model. Even though cross_validation purports to fit using each fold, it's not obvious from the API that the preceding fit procedure won't cause temporal leakage.

ivanmkc avatar Mar 07 '22 04:03 ivanmkc

For 1), I agree that there should be a clearer error message, thanks @jul-carras !

For 2), it does seem unintuitive at first (typically the ML workflow is train on subset -> validate -> fit on entire history), but it seems the cross_validation function was designed to:

  • Only take a model argument and not a dataframe argument.
  • Pick the largest seasonal period in the data. When the end user instantiates a Prophet() object, they may not set seasonalities yet, and these may be inferred later during the fitting process. We can probably scope out a clearer API but just need to keep those two things in mind.

tcuongd avatar May 22 '22 17:05 tcuongd