Skip to content

Instantly share code, notes, and snippets.

@joshreini1
Created May 15, 2023 19:47
Show Gist options
  • Save joshreini1/2681fc19148a5d1ce8f8008890866626 to your computer and use it in GitHub Desktop.
Save joshreini1/2681fc19148a5d1ce8f8008890866626 to your computer and use it in GitHub Desktop.
#standardSQL
SELECT
visitorID, #passthrough
Country,
Top_feature_attributions, # from ml.explain_predict
SUM(predicted_label) as total_predicted_purchases,
label #passthrough
FROM
ML.EXPLAIN_PREDICT(MODEL `bqml_tutorial.sample_model`, (
SELECT
IFNULL(device.operatingSystem, "") AS os,
device.isMobile AS is_mobile,
IFNULL(totals.pageviews, 0) AS pageviews,
IFNULL(geoNetwork.country, "") AS country
FROM
`bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE
_TABLE_SUFFIX BETWEEN '20170701' AND '20170801'))
GROUP BY country
ORDER BY total_predicted_purchases DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment