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.
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 namedidentity.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 ModellingProphet
: Modeling Multiple Seasonality With Linear or Non-linear GrowthProphetBC
: Prophet Model with Box-Cox transform of the dataHWAAS
: Exponential Smoothing With Additive Trend and Additive SeasonalityHWAMS
: Exponential Smoothing with Additive Trend and Multiplicative SeasonalityNBEATS
: Neural basis expansion analysis (now fixed at 20 Epochs)Gluonts
: RNN-based Model (now fixed at 20 Epochs)TATS
: Seasonal and Trend no Box CoxTBAT
: Trend and Box CoxTBATS1
: Trend, Seasonal (one), and Box CoxTBATP1
: TBATS1 but Seasonal Inference is Hardcoded by PeriodicityTBATS2
: TBATS1 With Two Seasonal Periods
How 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:
# 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 :
conda install pystan
conda install pytorch -c pytorch
!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
- Majority of forecasting code taken from https://github.com/firmai/atspy and refactored heavily.
- Google Analytics based off of: https://github.com/debrouwere/google-analytics
- 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.
- Fork the repo.
- In the
/src/forecastga/models
folder there is a model calledtemplate.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 thetrain
andforecast
methods for each model. Feel free to add additional methods that your model requires. - Edit the
/src/forecastga/models/__init__.py
file to add your model's information. Follow the format of the other entries. Forecastga relies onloc
to find the model andclass
to find the class to use. - 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. - Issue a pull request.
If you enjoyed this tool consider buying me some beer at: Paypalme
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ForecastGA-0.1.16.tar.gz
.
File metadata
- Download URL: ForecastGA-0.1.16.tar.gz
- Upload date:
- Size: 50.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.7.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6072886fd8e2c6d09b0470dce21035477576b76a5d5ef4131017bb469b031429 |
|
MD5 | d55f07ef635ca8da6f4a3cf16924d169 |
|
BLAKE2b-256 | c6a6f12c5d33f1f64ddd68dc0bc838409d0908ffdb4a0976b61d0a25fbd49bbc |
File details
Details for the file ForecastGA-0.1.16-py3-none-any.whl
.
File metadata
- Download URL: ForecastGA-0.1.16-py3-none-any.whl
- Upload date:
- Size: 63.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.7.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38a62161646b3507a37b41bcf5db57db60900b79029f62113df2bc15f5123850 |
|
MD5 | 29ca84285d1203cc6491ec5c1f87d758 |
|
BLAKE2b-256 | 41803c18c89f0e3eab7bc419564a060f4a4a9bcc5d35500a9a47563f0a4abf9c |