Skip to main content

A Python tool to forecast GA data using several popular timeseries models

Project description

ForecastGA

A Python tool to forecast GA data using several popular timeseries models.

Open In Colab

About

Welcome to ForecastGA

ForecastGA is a tool that combines a couple of popular libraries, Atspy and googleanalytics, with a few enhancements.

  • The models are made more intuitive to upgrade and add by having the tool logic separate from the model training and prediction.
  • When calling am.forecast_insample(), any kwargs included (e.g. learning_rate) are passed to the train method of the model.
  • Google Analytics profiles are specified by simply passing the URL (e.g. https://analytics.google.com/analytics/web/?authuser=2#/report-home/aXXXXXwXXXXXpXXXXXX).
  • You can provide a data dict with GA config options or a Pandas Series as the input data.
  • Multiple log levels.
  • Auto GPU detection (via Torch).
  • List all available models, with descriptions, by calling forecastga.print_model_info().
  • Google API info can be passed in the data dict or uploaded as a JSON file named identity.json.
  • Created a companion Google Colab notebook to easily run on GPU.
  • A handy plot function for Colab, forecastga.plot_colab(forecast_in, title="Insample FOrecast", dark_mode=True) that formats nicely and also handles Dark Mode!

To use:

Find Model Info:

forecastga.print_model_info()

Initialize Model:

Google Analytics:
data = { 'client_id': '<google api client_id>',
         'client_secret': '<google api client_secret>',
         'identity': '<google api identity>',
         'ga_start_date': '2018-01-01',
         'ga_end_date': '2019-12-31',
         'ga_metric': 'sessions',
         'ga_segment': 'organic traffic',
         'ga_url': 'https://analytics.google.com/analytics/web/?authuser=2#/report-home/aXXXXXwXXXXXpXXXXXX',
         'omit_values_over': 2000000
        }

model_list = ["TATS", "TBATS1", "TBATP1", "TBATS2", "ARIMA"]
am = forecastga.AutomatedModel(data , model_list=model_list, forecast_len=30 )
Pandas DataFrame:
data = pd.read_csv('ts.csv').sessions

model_list = ["TATS", "TBATS1", "TBATP1", "TBATS2", "ARIMA"]
am = forecastga.AutomatedModel(data , model_list=model_list, forecast_len=30 )

Forecast Insample:

forecast_in, performance = am.forecast_insample()

Forecast Outsample:

forecast_out = am.forecast_outsample()

Ensemble Performance:

all_ensemble_in, all_ensemble_out, all_performance = am.ensemble(forecast_in, forecast_out)

Pretty Plot in Google Colab

forecastga.plot_colab(forecast_in, title="Insample FOrecast", dark_mode=True)

Installation

Windows users may need to manually install the two items below via conda :

  1. conda install pystan
  2. conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
  3. !pip install --upgrade git+https://github.com/jroakes/ForecastGA.git

otherwise, !pip install --upgrade git+https://github.com/jroakes/ForecastGA.git

This repo support GPU training. Below are a few libraries that may have to be manually installed to support. pip install --upgrade mxnet-cu101==1.7.0

Acknowledgements

  1. Majority of forecasting code taken from https://github.com/firmai/atspy and refactored heavily.
  2. Google Analytics based off of: https://github.com/debrouwere/google-analytics

Contribute

The goal of this repo is to grow the list of available models to test. If you would like to contribute one please read on. Feel free to have fun naming your models.

  1. Fork the repo.
  2. In the /src/forecastga/models folder there is a model called template.py. You can use this as a template for creating your new model. All available variables are there. Forecastga ensures each model has the right data and calls only the train and forecast methods for each model. Feel free to add additional methods that your model requires.
  3. Edit the /src/forecastga/models/__init__.py file to add your model's information. Follow the format of the other entries. Forecastga relies on loc to find the model and class to find the class to use.
  4. Edit requirments.txt with any additional libraries needed to run your model. Keep in mind that this repo should support GPU training if available and some libraries have separate GPU-enabled versions.
  5. Issue a pull request.

If you enjoyed this tool consider buying me some beer at: Paypalme

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

ForecastGA-0.1.5.tar.gz (49.6 kB view details)

Uploaded Source

Built Distribution

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

ForecastGA-0.1.5-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file ForecastGA-0.1.5.tar.gz.

File metadata

  • Download URL: ForecastGA-0.1.5.tar.gz
  • Upload date:
  • Size: 49.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Windows/10

File hashes

Hashes for ForecastGA-0.1.5.tar.gz
Algorithm Hash digest
SHA256 08010764759a13b77af3e6232d65272adcc99349d5c094cb0893f3c776bd6fc9
MD5 6a4db0c11d3970464c5cd8ca3cf46933
BLAKE2b-256 40c631830cd8bafdfa21131aad9d7d3c7ae122658378dd7543b67f7ddf5dd11f

See more details on using hashes here.

File details

Details for the file ForecastGA-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: ForecastGA-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 61.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Windows/10

File hashes

Hashes for ForecastGA-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4529ee5fdfdcb92b10473aadc7ab5134c06bff9f5beda28f424f1f09bc0eb384
MD5 6849a7f92fed95dfa9d7b0fb8a45ceb6
BLAKE2b-256 eac58bac60bdcc8e431d84df090d2d00841285711e186a8ad864e55eac44aa32

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