Home > other >  Error in Data frame definition while Multiple TS Stat Forecasting in Python
Error in Data frame definition while Multiple TS Stat Forecasting in Python

Time:10-06

I was trying to replicate this code for stat forecasting in python, I came across an odd error "name 'forecasts' is not defined" which is quite strange as I was able to replicate the code without any errors before.

The difference here from this to the reference code (which is given in the link below and the code which I was successfully able to implement), I am not using a training set and extracting the last 6 months for evaluation and instead I am using the entire training data for creating a stat forecast.

Eg: If my time series data was till Sept-22, I wanted to give the entire data till Sept-22 as the training set for my stat model and previous the training data had time series till March-22 and the rest 6 months was test. But now there are Errors which I am not able to understand why as the logic is same?

Attached is the simplified data frame used for the calculation:

{'Key': {0: 65162552161356, 1: 65162552635756, 2: 65162552843456, 3: 65162552842856, 4: 65162552736856}, '2021-04-01': {0: 31, 1: 0, 2: 281, 3: 207, 4: 55}, '2021-05-01': {0: 25, 1: 0, 2: 72, 3: 104, 4: 6}, '2021-06-01': {0: 16, 1: 0, 2: 108, 3: 32, 4: 14}, '2021-07-01': {0: 8, 1: 0, 2: 107, 3: 78, 4: 10}, '2021-08-01': {0: 21, 1: 0, 2: 80, 3: 40, 4: 9}, '2021-09-01': {0: 24, 1: 0, 2: 40, 3: 73, 4: 3}, '2021-10-01': {0: 13, 1: 0, 2: 36, 3: 79, 4: 11}, '2021-11-01': {0: 59, 1: 0, 2: 65, 3: 139, 4: 14}, '2021-12-01': {0: 51, 1: 0, 2: 41, 3: 87, 4: 10}, '2022-01-01': {0: 2, 1: 0, 2: 43, 3: 47, 4: 6}, '2022-02-01': {0: 0, 1: 0, 2: 0, 3: 63, 4: 3}, '2022-03-01': {0: 0, 1: 0, 2: 16, 3: 76, 4: 18}, '2022-04-01': {0: 0, 1: 0, 2: 37, 3: 32, 4: 8}, '2022-05-01': {0: 0, 1: 0, 2: 106, 3: 96, 4: 40}, '2022-06-01': {0: 0, 1: 0, 2: 101, 3: 75, 4: 16}, '2022-07-01': {0: 0, 1: 0, 2: 60, 3: 46, 4: 14}, '2022-08-01': {0: 0, 1: 0, 2: 73, 3: 91, 4: 13}, '2022-09-01': {0: 0, 1: 0, 2: 19, 3: 17, 4: 2}}

Here is the link for reference : enter image description here

Can anyone let me know what is it that I am doing wrong? It would be very much appreciated.

CodePudding user response:

The problem arises because of the Croston family. I have opened an issue to solve the problem. In the meantime, skipping those models works.

models = [
    adida,
    #croston_classic,
    #croston_sba,
    #croston_optimized,
    historic_average,
    imapa,
    naive,
    random_walk_with_drift,
    (seasonal_exponential_smoothing, seasonality, 0.2),
    (seasonal_naive, seasonality),
    (seasonal_window_average, seasonality, 2 * seasonality),
    (ses, 0.1),
    (tsb, 0.3, 0.2),
    (window_average, 2 * seasonality)
    ]
fcst = StatsForecast(df=df, models=models, freq='MS', n_jobs=cpu_count())
fcst.forecast(6)
  • Related