facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.09k stars 4.49k forks source link

Prophet unable to learn Conditional monthly seasonality #2408

Open deepanshu650 opened 1 year ago

deepanshu650 commented 1 year ago

Hi,

I have a 5 year daily level time series data of a business metric having weekly, yearly and monthly seasonality (the metric at start of month is highest and it keeps on falling as month progresses).

We were using standard 30.5 period to learn monthly seasonality, but it turns out that as the data progresses the month start peak is getting shifted every time feb comes (feb being 28/29 days and seasonality period used is 30.5). The month start peak from march onwards will get shifted to 4th or 5th. Similar to this issue #1372 . (We have flags at month start and month end as suggested in this thread)

To rectify this issue, we tried conditional monthly seasonality i.e having different monthly seasonality for months having different no of days.

So in total added 4 different conditional monthly seasonality instead of 1 normal monthly, based on whether the month is 28, 29 , 30 or 31 day. Similarly created 2 conditional yearly seasonality based on whether year is 365 or 366 days long.

But model was not able to learn these new monthly pattern and it performed very poor as compared to 30.5 seasonality period.

Attaching the seasonality components learnt by model (the component should start from highest and decrease as month progresses)

image image

Please let me know if there is something wrong in this idea and in general what are the best practice to handle monthly seasonality.

deepanshu650 commented 1 year ago

@tcuongd, @bletham any inputs would be appreciated.

xueshanzhizhi commented 5 months ago

I got the same problem.!It seems is the limit of this algorithm. If there is any good solution let me know.

vanjasmailovic commented 2 months ago

@deepanshu650 could you provide a plot of the original data, since it would make it easier to visualize? Perhaps a goodness-of-fit metric would be useful too to understand just how badly (or well) Prophet is performing here.

Consulting GPT4, couple notable points that I'm wondering about:

The Fourier series method used in Prophet, which allows for flexibility in the seasonality component, helps mitigate the impact of anomalies like February's unique length. The Fourier series can adjust the amplitude and phase of the seasonal cycle throughout the year, creating a smoother and more adaptive fit to the data.

When you specify a seasonal component in Prophet, such as monthly or biweekly seasonality, you also specify a fourier_order. This order determines how many sine and cosine pairs are used to model the seasonality. A higher fourier_order allows the Fourier series to capture more complex patterns, because it can fit more detailed fluctuations.

The Fourier series doesn't just rigidly apply a standard wave form; it adapts based on the data provided. For example, even though February's length varies, the impact of this variance on sales or weather patterns can be smoothed out over the broader seasonal trends captured by the Fourier series.

By using Fourier series, Prophet doesn’t need to explicitly know that February is shorter; it simply needs to recognize and adapt to the patterns present in the data across different times of the year. The flexibility of Fourier series to approximate and adapt to underlying seasonal trends without rigid constraints on the specifics of each month is a key strength in handling real-world time series data.

...nothing new, but it sounds like Prophet should not fail miserably on your use case? Am I correct in assuming you're trying to have it fit better, but that it's already fitting "decently" for more general applications?

deepanshu650 commented 1 month ago

hey @xueshanzhizhi , @vanjasmailovic We have written a detailed blog post for this issue and how we tackled it over here . Hope this will be helpful for any future reference.