Skip to content

Instantly share code, notes, and snippets.

@thomashandorf
Created December 18, 2023 08:34
Show Gist options
  • Save thomashandorf/7b7b69d7df2263d2496129761fe1e5df to your computer and use it in GitHub Desktop.
Save thomashandorf/7b7b69d7df2263d2496129761fe1e5df to your computer and use it in GitHub Desktop.
BigQuery ML ARIMA Model on GA4 purchase data
CREATE OR REPLACE MODEL `your-project.arima_test.purchase_forecast`
OPTIONS(model_type='ARIMA_PLUS', time_series_timestamp_col='date', time_series_data_col='daily_purchases')
AS
SELECT
PARSE_DATE('%Y%m%d', event_date) as date,
COUNTIF(event_name = 'purchase') as daily_purchases
FROM
`bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE
_TABLE_SUFFIX BETWEEN '20201101' AND '20211231'
GROUP BY
date
order by date;
SELECT
*
FROM
ML.FORECAST(MODEL `your-project.arima_test.purchase_forecast`, STRUCT(90 AS horizon));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment