ForecastGA is a Python tool to forecast Google Analytics data using several popular time series models.

Overview

ForecastGA

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

Open In Colab

Logo for ForecastGA

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!

Models Available

  • ARIMA : Automated ARIMA Modelling
  • Prophet : Modeling Multiple Seasonality With Linear or Non-linear Growth
  • ProphetBC : Prophet Model with Box-Cox transform of the data
  • HWAAS : Exponential Smoothing With Additive Trend and Additive Seasonality
  • HWAMS : Exponential Smoothing with Additive Trend and Multiplicative Seasonality
  • NBEATS : Neural basis expansion analysis (now fixed at 20 Epochs)
  • Gluonts : RNN-based Model (now fixed at 20 Epochs)
  • TATS : Seasonal and Trend no Box Cox
  • TBAT : Trend and Box Cox
  • TBATS1 : Trend, Seasonal (one), and Box Cox
  • TBATP1 : TBATS1 but Seasonal Inference is Hardcoded by Periodicity
  • TBATS2 : TBATS1 With Two Seasonal Periods

How To Use

Find Model Info:

forecastga.print_model_info()

Initialize Model:

Google Analytics:
data = { 'client_id': '',
         'client_secret': '',
         '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:
# CSV with columns: Date and Sessions
df = pd.read_csv('ga_sessions.csv')
df.Date = pd.to_datetime(df.Date)
df = df.set_index("Date")
data = df.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 -c pytorch
  3. !pip install --upgrade git+https://github.com/jroakes/ForecastGA.git

otherwise, pip install --upgrade forecastga

This repo support GPU training. Below are a few libraries that may have to be manually installed to support.

pip install --upgrade mxnet-cu101
pip install --upgrade torch 1.7.0+cu101

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
  3. Thanks to richardfergie for the addition of the Prophet Box-Cox model to control negative predictions.

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

Owner
JR Oakes
Hacker, SEO, NC State fan, co-organizer of Raleigh and RTP Meetups, as well as @sengineland author. Tweets are my own.
JR Oakes
simple way to build the declarative and destributed data pipelines with python

unipipeline simple way to build the declarative and distributed data pipelines. Why you should use it Declarative strict config Scaffolding Fully type

aliaksandr-master 0 Jan 26, 2022
Flexible HDF5 saving/loading and other data science tools from the University of Chicago

deepdish Flexible HDF5 saving/loading and other data science tools from the University of Chicago. This repository also host a Deep Learning blog: htt

UChicago - Department of Computer Science 255 Dec 10, 2022
Analytical view of olist e-commerce in Brazil

Analysis of E-Commerce Public Dataset by Olist The objective of this project is to propose an analytical view of olist e-commerce in Brazil. For this

Gurpreet Singh 1 Jan 11, 2022
Create HTML profiling reports from pandas DataFrame objects

Pandas Profiling Documentation | Slack | Stack Overflow Generates profile reports from a pandas DataFrame. The pandas df.describe() function is great

10k Jan 01, 2023
An experimental project I'm undertaking for the sole purpose of increasing my Python knowledge

5ePy is an experimental project I'm undertaking for the sole purpose of increasing my Python knowledge. #Goals Goal: Create a working, albeit lightwei

Hayden Covington 1 Nov 24, 2021
An Integrated Experimental Platform for time series data anomaly detection.

Curve Sorry to tell contributors and users. We decided to archive the project temporarily due to the employee work plan of collaborators. There are no

Baidu 486 Dec 21, 2022
Renato 214 Jan 02, 2023
2019 Data Science Bowl

Kaggle-2019-Data-Science-Bowl-Solution - Here i present my solution to kaggle 2019 data science bowl and how i improved it to win a silver medal in that competition.

Deepak Nandwani 1 Jan 01, 2022
Describing statistical models in Python using symbolic formulas

Patsy is a Python library for describing statistical models (especially linear models, or models that have a linear component) and building design mat

Python for Data 866 Dec 16, 2022
Scraping and analysis of leetcode-compensations page.

Leetcode compensations report Scraping and analysis of leetcode-compensations page.

utsav 96 Jan 01, 2023
A utility for functional piping in Python that allows you to access any function in any scope as a partial.

WithPartial Introduction WithPartial is a simple utility for functional piping in Python. The package exposes a context manager (used with with) calle

Michael Milton 1 Oct 26, 2021
Accurately separate the TLD from the registered domain and subdomains of a URL, using the Public Suffix List.

tldextract Python Module tldextract accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and s

John Kurkowski 1.6k Jan 03, 2023
Python Package for DataHerb: create, search, and load datasets.

The Python Package for DataHerb A DataHerb Core Service to Create and Load Datasets.

DataHerb 4 Feb 11, 2022
Two phase pipeline + StreamlitTwo phase pipeline + Streamlit

Two phase pipeline + Streamlit This is an example project that demonstrates how to create a pipeline that consists of two phases of execution. In betw

Rick Lamers 1 Nov 17, 2021
Project under the certification "Data Analysis with Python" on FreeCodeCamp

Sea Level Predictor Assignment You will anaylize a dataset of the global average sea level change since 1880. You will use the data to predict the sea

Bhavya Gopal 3 Jan 31, 2022
Python data processing, analysis, visualization, and data operations

Python This is a Python data processing, analysis, visualization and data operations of the source code warehouse, book ISBN: 9787115527592 Descriptio

FangWei 1 Jan 16, 2022
Pandas on AWS - Easy integration with Athena, Glue, Redshift, Timestream, QuickSight, Chime, CloudWatchLogs, DynamoDB, EMR, SecretManager, PostgreSQL, MySQL, SQLServer and S3 (Parquet, CSV, JSON and EXCEL).

AWS Data Wrangler Pandas on AWS Easy integration with Athena, Glue, Redshift, Timestream, QuickSight, Chime, CloudWatchLogs, DynamoDB, EMR, SecretMana

Amazon Web Services - Labs 3.3k Jan 04, 2023
Advanced Pandas Vault — Utilities, Functions and Snippets (by @firmai).

PandasVault ⁠— Advanced Pandas Functions and Code Snippets The only Pandas utility package you would ever need. It has no exotic external dependencies

Derek Snow 374 Jan 07, 2023
Pizza Orders Data Pipeline Usecase Solved by SQL, Sqoop, HDFS, Hive, Airflow.

PizzaOrders_DataPipeline There is a Tony who is owning a New Pizza shop. He knew that pizza alone was not going to help him get seed funding to expand

Melwin Varghese P 4 Jun 05, 2022
We're Team Arson and we're using the power of predictive modeling to combat wildfires.

We're Team Arson and we're using the power of predictive modeling to combat wildfires. Arson Map Inspiration There’s been a lot of wildfires in Califo

Jerry Lee 3 Oct 17, 2021