Skip to main content

Multivariate forecasting using Facebook Prophet

Project description

Multi Prophet

Build Status PyPI version License: MIT

Multi Prophet is a procedure for forecasting time series data for multipe dependent variables based on Facebook Prophet package. If you have no prior experience with Facebook Prophet, check out their docs.

Multi Prophet does not train a single model with many outputs, it just wraps Facebook Prophet interface to support configuration and controll over multiple models. Multi Prophet has a very similar interface as Facebook Prophet.

The main difference is that return values of each method is a dictionary where each dependent value is a key, and the value is the return value of the linked Facebook Prophet model.

If Prophet return value is a data frame, then MultiProphet return value will be:

{"dependent_variable1": df1, "dependent_variable2": df2}

Installation

Multi Prophet is on PyPi. pip install multi-prophet

Getting started

Creating a basic model is almost the same as creating a Prophet model:

Prophet

# dataframe needs to have columns ds and y
from fbprophet import Prophet

m = Prophet()
m.fit(df)

future = m.create_future_dataframe(df)
forecast = m.predict(future)
m.plot(forecast)

Multi Prophet

# dataframe needs to have column ds, and it has y1 and y2 as dependent variables
from multi_prophet import MultiProphet

m = MultiProphet(columns=["y1", "y2"])
m.fit(df)

future = m.create_future_dataframe(df)
forecast = m.predict(future)
m.plot(forecast)

Adding country holidays

Prophet

m.add_country_holidays(country_name="US")

Multi Prophet

# For all dependent variables
m.add_country_holidays("US")

# For selected dependent variables
m.add_country_holidays("US", columns=["y1"])

Adding seasonality

Prophet

m.add_seasonality(name="monthly", period=30.5, fourier_order=5)

Multi Prophet

# For all dependent variables
m.add_seasonality(name="monthly", period=30.5, fourier_order=5)

# For selected dependent variables
m.add_seasonality(name="monthly", period=30.5, fourier_order=5, columns=["y1"])

Adding regressors

Prophet

m.add_regressor("Matchday")

Multi Prophet

# For all dependent variables
m.add_regressor("Matchday")

# For selected dependent variables
m.add_regressor("Matchday", columns=["y"])

Ploting results

Prophet

# Prophet
m.plot(forecast)
m.plot_components(forecast)

# With Plotly
from fbprophet.plot import plot_plotly, plot_components_plotly
import plotly.offline as py
py.init_notebook_mode()

fig = plot_plotly(m, forecast)
py.iplot(fig)

fig = plot_components_plotly(m, forecast)
py.iplot(fig)

Multi Prophet

m.plot(forecast)
m.plot_components(forecast)

# With Plotly
figures = m.plot(forecast, plotly=True)
for fig in figures.values():
    fig.show()

# or access by key
figures["y1"].show()

figures = m.plot_components(forecast, plotly=True)
for fig in figures.values():
    fig.show()

# or access by key
figures["y1"].show()

Facebook Prophet model configuration

Facebook Prophet supports a lot of configuration through kwargs. There are two ways to do it with Multi Prophet:

  1. Through kwargs just as with Facebook Prophet
    • Prophet
m = Prophet(growth="logistic")
m.fit(self.df, algorithm="Newton")
m.make_future_dataframe(7, freq="H")
m.add_regressor("Matchday", prior_scale=10)
* Multi Prophet
m = MultiProphet(columns=["y1", "y2"], growth="logistic")
m.fit(self.df, algorithm="Newton")
m.make_future_dataframe(7, freq="H")
m.add_regressor("Matchday", prior_scale=10)
  1. Configuration through constructor
# Same configuration for each dependent variable
m = MultiProphet(columns=["y1", "y2"],
                 growth="logistic",
                 weekly_seasonality=True,
                 n_changepoints=50)

# Different configuration for each model
config = {
    "y1": {"growth": "linear", "daily_seasonality": True},
    "y2": {"growth": "logistic", "weekly_seasonality": True}
}
m = MultiProphet(columns=["y1", "y2"], config=config)

# Adding regressors (dataframe has columns c1 and c2)
regressors = {
    "y1": [
        {"name": "c1", "prior_scale": 0.5},
        { "name": "c2", "prior_scale": 0.3}
    ],
    "y2": [{"name": "c2", "prior_scale": 0.3}]
}
m = MultiProphet(columns=["y1", "y2"], regressors=regressors)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multi-prophet-1.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multi_prophet-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file multi-prophet-1.0.1.tar.gz.

File metadata

  • Download URL: multi-prophet-1.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2

File hashes

Hashes for multi-prophet-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9160cf9c0591c0bd8a2f9d309e90bc252b2f845ce2554b57e0cbf17ab80044c4
MD5 e044554a17e10d67c8865bc9514a00f4
BLAKE2b-256 b9adc680315b9f9b1efbaa814e76bd6ebe307a028e2f5119b395124926f83e4b

See more details on using hashes here.

File details

Details for the file multi_prophet-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: multi_prophet-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2

File hashes

Hashes for multi_prophet-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9786a2500f1045a4898d76efd305e47c4b5de9fd8381fdd8af6132a364f52012
MD5 e1ca00ce6052ed8a10e16ded1a91ae6b
BLAKE2b-256 4aeec47d472c50975be5c7ccbf71bae081b105961c9126206881786f527466e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page