Skip to main content

Mozilla simpleprophet forecast framework.

Project description

simpleprophet KPI forecasting models and tools

This directory contains the simpleprophet forecast models and accompanying tools. The simpleprophet models prioritize simplicity and stability, adding complexity and "bendiness" only when it significantly improves model performance on a holdback period.

Setup

You will need a python environment with fbprophet and a few other dependencies installed. We provide a Docker image that can be pulled from GCR and run interactively like:

GOOGLE_APPLICATION_CREDENTIALS=/path/to/creds.json
docker run -it \
  -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/key.json \
  -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/key.json:ro \
  --entrypoint python \
  gcr.io/moz-fx-data-forecasting/simpleprophet

Or you can make code updates and build the image locally:

docker build . --tag simpleprophet
docker run -it \
  -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/key.json \
  -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/key.json:ro \
  --entrypoint python \
  simpleprophet

If you want to produce a local environment outside docker, you can create an appropriate Conda environment via conda env create -f environment.yml. To create an environment outside Conda, see the fbprophet installation instructions and then use pip install -r requirements.txt to install remaining dependencies.

Usage

The functions for running the forecasting pipeline are in pipeline.py. The update_table function can be run daily to add rows to the output table as necessary to incorporate newly available metrics data. The replace_table function will clear the output table and regenerate it from scratch.

For model-building the code in modeling.py may be useful. It includes a function to evaluate a model on a holdout set and provide some useful visualizations.

The validations.py file contains code that produces plots to evaluate model performance and validate the model behavior over time is reasonable. It can also be used to compare multiple models.

Modeling Strategy

The models.py file contains the production model specifications. The models were developed by Jesse McCrosky using the fbprophet framework. The guiding modeling philosophy was to be guided by simplicity and intuitive fit, while informing the modeling process using conventional types of quantitative evidence.

The evaluation of a forecast is fundamentally multi-dimensional. As well as the competing objectives of stability, accuracy, and non-bias, each of these objectives can be evaluated on multiple time horizons. This complexity makes a pure machine learning optimization approach extremely complex.

As an alternative, I chose to fit the models somewhat intuitively. Parameter sets were explored iteratively and each iteration was evaluated visually to see if the model components (seasonality and trend) seemed to fit the observed actuals. Once a reasonable parameter space was defined, the modeling process proceeded to evaluate holdout set metrics and other quantitative evaluations on a set of models. Simpler models were preferred and complexity was only added when clearly justified by the quantitative evidence.

A few relevant model characteristics:

  • Due to the "smoothed" nature of MAU as a metric, yearly seasonality was adequate to capture all holiday effects except for Easter, which was included as a model component.
  • We select a start date for the training data based on the point where the metric appears to have reached a somewhat steady state in its development - the first weeks of most metrics are quite atypically and their use for training would not be helpful.
  • Similarly, some product metrics have "anomalies" - periods during which the metric value was highly atypical, usually due to a data problem. These periods were excluded from training data.
  • The appropriate start dates and anomaly periods were determined through manual examination of metric plots.

Deploying

To deploy to PyPI, admins on the repo can make a new release following semver (0.1.0, for example), which will trigger a CircleCI build that publishes a new package to PyPI with that tag name as the version.


For more information, contact jmccrosky@mozilla.com

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

simpleprophet-1.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

simpleprophet-1.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file simpleprophet-1.1.tar.gz.

File metadata

  • Download URL: simpleprophet-1.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for simpleprophet-1.1.tar.gz
Algorithm Hash digest
SHA256 e2d7cbe351d872c4493b6ab079f08465e18197c36d98ffb2372759d2e2941266
MD5 99fae15be82d148225e6522cd52c263b
BLAKE2b-256 17e893d35ab93c336c77113748d27b5dde921be0412e062709301450dcc69512

See more details on using hashes here.

File details

Details for the file simpleprophet-1.1-py3-none-any.whl.

File metadata

  • Download URL: simpleprophet-1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for simpleprophet-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7dd5710396374229bc5c5e126c14e93f68a4e296fc307cff381471f2914f5fc
MD5 a06c1e8c9bd8671ced3b6a5032a37b75
BLAKE2b-256 5732aa87e523d98b24d9c86a2f41f9563186ba388c2000a8cbbb381d1c79cb1e

See more details on using hashes here.

Supported by

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