2

I have a similar problem like the one from this question: forecasting values for each category using Prophet in python I want to make a prediction for multiple items based on key pcodeid so for every pcodeid I need a separate prediction.

I changed my code to match the code from the best answer from the link above but I keep receiving the error.

Part of my data (the whole dataset is monthly data for 4 years and for 50 pcodes):

ds     PcodeID        y
2015-01-01  AUSTRALIA-P8205  10.36
2015-01-01  AUSTRALIA-P8206  2.06
2015-01-01  AUSTRALIA-P8208  7.1
2015-01-01  AUSTRALIA-P8211  39.76
2015-01-01  AUSTRALIA-P8212  0.61
2015-01-01  AUSTRALIA-P8220  10.38
2015-01-01  AUSTRALIA-P8223  10.35
2015-01-01  AUSTRALIA-P8227  2.99
2015-01-01  AUSTRALIA-P8228  2.99
2015-01-01  AUSTRALIA-P8233  0.28
2015-01-01  AUSTRALIA-P8238  4544
2015-01-01  AUSTRALIA-P8242  894.6
2015-01-01  AUSTRALIA-P8247  7.53
2015-02-01  AUSTRALIA-P8250  194.18
2015-02-01  AUSTRALIA-P8268  6476.96

my code:

def get_prediction(df):
    prediction = {}
    df2 = df.rename(columns={'PcodeID' : 'pcodeid'})
    list_pcodeid = df2.pcodeid.unique()
    
    for pcodeid in list_pcodeid:
        pcodeid_df = df2.loc[df2['pcodeid'] == pcodeid]
        # set the uncertainty interval to 95% (the Prophet default is 80%)
        my_model = Prophet()
        my_model.fit(pcodeid_df)
        future_dates = my_model.make_future_dataframe(periods=12, freq='MS')
        prediction = my_model.predict(future_dates)
        prediction[pcodeid] = prediction
    return prediction

I keep receiving an error for line 7 "pcodeid is not defined". The guy from the solution under the link commented that it worked perfectly for him. How should I define the pcodeid to work as described in the question from the link?

pppery
  • 3,731
  • 22
  • 33
  • 46
woliwia
  • 21
  • 3

0 Answers0