Open In Colab

Multiplicative Seasonality#

By default NeuralProphet fits additive seasonalities, meaning the effect of the seasonality is added to the trend to get the forecast. This time series of the number of air passengers is an example of when additive seasonality does not work:

[1]:
if "google.colab" in str(get_ipython()):
    # uninstall preinstalled packages from Colab to avoid conflicts
    !pip uninstall -y torch notebook notebook_shim tensorflow tensorflow-datasets prophet torchaudio torchdata torchtext torchvision
    !pip install git+https://github.com/ourownstory/neural_prophet.git # may take a while
    #!pip install neuralprophet # much faster, but may not have the latest upgrades/bugfixes

import pandas as pd
from neuralprophet import NeuralProphet, set_log_level

set_log_level("ERROR")
[2]:
data_location = "https://raw.githubusercontent.com/ourownstory/neuralprophet-data/main/datasets/"
df = pd.read_csv(data_location + "air_passengers.csv")
[3]:
m = NeuralProphet()
metrics = m.fit(df, freq="MS")
m.set_plotting_backend("plotly-static")
[4]:
future = m.make_future_dataframe(df, periods=50, n_historic_predictions=len(df))
forecast = m.predict(future)
m.plot(forecast)
# m.plot_parameters()
../../_images/how-to-guides_feature-guides_season_multiplicative_air_travel_5_1.svg

This time series has a clear yearly cycle, but the seasonality in the forecast is too large at the start of the time series and too small at the end. In this time series, the seasonality is not a constant additive factor as assumed by NeuralProphet, rather it grows with the trend. This is multiplicative seasonality.

NeuralProphet can model multiplicative seasonality by setting seasonality_mode="multiplicative" in the input arguments:

[5]:
m = NeuralProphet(seasonality_mode="multiplicative")
metrics = m.fit(df, freq="MS")
m.set_plotting_backend("plotly-static")
[6]:
future = m.make_future_dataframe(df, periods=50, n_historic_predictions=len(df))
forecast = m.predict(future)
m.plot(forecast)
# m.plot_parameters()
../../_images/how-to-guides_feature-guides_season_multiplicative_air_travel_8_1.svg

The components figure will now show the seasonality as a percent of the trend:

[7]:
m.plot_components(forecast)
../../_images/how-to-guides_feature-guides_season_multiplicative_air_travel_10_0.svg

Note that the seasonality is only fit on data occuring at the start of the month. Thus, the plotted values for seasonality inbetween months may take on random values.

Settingseasonality_mode="multiplicative" will model all seasonalities as multiplicative, including custom seasonalities added with add_seasonality.