Prepare and test your skills
Prepare and test your skills
Implementing prediction mechanisms with BigQuery ML (opens in a new tab) means training, evaluating, and running inference directly inside BigQuery without moving data to another system. Data flows from BigQuery tables into the trained model, and prediction results flow back into BigQuery tables where they can be queried with GoogleSQL. You can work with BigQuery ML through the Google Cloud console, the bq command-line tool, the REST API, or Colab Enterprise notebooks, so analysts can use existing SQL tools and skills.
Batch inference inside BigQuery ML is the process of generating predictions for many rows at once where the data already lives. You can get inferences in two ways: request batch inferences directly from the model in BigQuery ML, or register the models directly with Model Registry (opens in a new tab) without exporting them from BigQuery ML or importing them into Model Registry. Tabular forecasting models support batch inference only, so they produce future values for a whole input set rather than one interactive result at a time. The batch job and the BigQuery tables it reads and writes must be in the same region, and the service account running the job depends on BigQuery permissions such as the BigQuery User role.
A typical batch workflow moves in a fixed order from preparation to output delivery:
Prediction tasks supported by BigQuery ML are the kinds of questions a trained model can answer with new data, including forecasting, anomaly detection, classification, and regression. Forecasting predicts future values in time-series data using models such as TimesFM, ARIMA_PLUS, and ARIMA_PLUS_XREG. Anomaly detection flags unusual points in that same time-series data, while classification assigns a category and regression predicts a numeric value. Explainable AI helps explain why a predictive model produced a result, and contribution analysis helps explain changes to key metrics in multi-dimensional data.
BigQuery ML also supports related analysis tasks that feed into predictions:
Because inference runs with GoogleSQL queries and notebooks let you use SQL and Python interchangeably, you can combine model outputs with AI or ML Python libraries in the same workflow.
Validating predictions against your data is the step where prediction quality is checked by comparing model outputs against known data. The BigqueryEvaluateModelJobOp (opens in a new tab) operator runs evaluation as a pipeline task, while related operators expose details such as confusion matrices, centroids, feature information, feature importance, advanced weights, and ARIMA coefficients and evaluation results. For classification, output includes predicted classes with confidence scores, and for regression, output includes the predicted value with lower and upper bounds. Feature attributions can also be returned to show how much each input feature contributed to a specific prediction.
Exam tip: The batch job and its BigQuery input and output tables must be in the same region, and do not name input columns response or status because those names are reserved for job results.
Using predictions in broader analysis workflows means storing predictions in BigQuery so later queries, dashboards, and pipelines can use them like any other table. Pipeline components orchestrate each operation as a repeatable task, where a downstream analysis step depends on the prediction step finishing first. The control plane for these workflows is the Google Cloud SDK set of BigQuery ML operators, including tasks for creating, evaluating, forecasting, detecting anomalies, explaining predictions and forecasts, and exporting or dropping models. Because predictions remain in BigQuery, data flows from the source table to the model to the predictions table to the next analysis query without leaving the warehouse trust boundary.
Prediction output is split so successful results and problems stay separate:
| Output | What it contains | How it is used |
|---|---|---|
| Predictions table | One row for every input row that was scored, with predicted classes and scores or predicted values and bounds | Queried in BigQuery for reports, filters, joins, and downstream analysis |
| Errors table | One row for each non-critical error, with an error code and message tied to the input row | Queried in BigQuery to find rows the model could not score and fix input problems |
Performing time-series forecasting and anomaly detection with BigQuery ML (opens in a new tab) means running batch inference tasks directly where timestamped data lives using SQL. Forecasting generates future values from ordered historical data, while anomaly detection flags values that deviate from the expected baseline. Both tasks use specialized time-series models and SQL functions, so no data movement or separate prediction service is required.
Time-series forecasting with BigQuery ML predicts future values from timestamped historical data using three supported models: TimesFM, ARIMA_PLUS, and ARIMA_PLUS_XREG. Data flows from BigQuery tables to the trained model through a SQL inference query, and forecast results flow back into BigQuery as a new result set. The workflow depends on the model staying with the data, which lets practitioners train, evaluate, and run inference from the console, bq tool, REST API, or notebooks. Forecasting queries configure temporal scope with parameters such as forecast horizon, which controls how many future points are generated, and confidence level, which controls the prediction interval around each forecasted value. Choose ARIMA_PLUS_XREG when the forecast depends on external regressors, and choose TimesFM or ARIMA_PLUS when the forecast depends only on the history of the time series itself.
Unsupervised anomaly detection with BigQuery ML identifies outliers without labeled examples of what counts as anomalous. Unsupervised detection is the right choice when the definition of anomalous is uncertain or no labeled training data exists, and it can run against training data or new serving data. For time-series data, the detection function depends on the model type, so the model and function must be matched correctly.
A decision tree that branches on labeled data, time-series versus IID rows, and model type to choose ML.PREDICT, AI.DETECT_ANOMALIES, or ML.DETECT_ANOMALIES.
| Model | Function | Use when |
|---|---|---|
TimesFM | AI.DETECT_ANOMALIES | The data is a time series |
ARIMA_PLUS | ML.DETECT_ANOMALIES | The data is a time series |
ARIMA_PLUS_XREG | ML.DETECT_ANOMALIES | The data is a time series with external regressors |
For independent and identically distributed random variables (IID), which are non-time-series rows treated as independent observations, ML.DETECT_ANOMALIES also detects anomalies but by a different mechanism:
Exam tip: TimesFM uses AI.DETECT_ANOMALIES, while ARIMA_PLUS and ARIMA_PLUS_XREG use ML.DETECT_ANOMALIES for the same time-series anomaly task.
Supervised anomaly detection with BigQuery ML treats anomaly detection as prediction with the ML.PREDICT function. Supervised detection applies when labeled data already identifies which rows are anomalies, so the model learns that mapping during training and then scores new serving data. Default settings in CREATE MODEL and the inference functions allow a basic model to be created and used without deep ML knowledge. Choose supervised detection with ML.PREDICT when labels exist, and choose unsupervised detection with AI.DETECT_ANOMALIES or ML.DETECT_ANOMALIES when labels do not exist.
The ML.PREDICT function works with the following supervised models:
Executing inference with a pre-trained BigQuery ML (opens in a new tab) model means applying a model that is already trained to new data to generate predictions, forecasts, or anomaly results. BigQuery ML performs batch inference inside BigQuery, so large sets of new rows are scored at once without moving data to another system. A trained model stays in a BigQuery dataset and reads input rows from a table or file, then results flow from the model to an output table or file for review and comparison with actual outcomes.
Batch inference with trained models is the process of scoring many new rows in one job using a trained BigQuery ML model. The model depends on new input data that has the same features used during training, and the inference job produces an output that adds a predicted value, forecasted value, or anomaly flag to each input row. Because the work runs where the data already lives, teams avoid export and import steps and keep one consistent copy of the data. You can get inferences in two ways: request batch inferences directly from the model in BigQuery ML, or register the models directly with Model Registry (opens in a new tab) without exporting them or importing them. Direct inference in BigQuery ML is the simplest path when scoring stays in SQL, while Model Registry is useful when the same model must also be managed alongside models outside BigQuery.
SQL-based inference in BigQuery ML uses GoogleSQL queries to apply a trained model to new data for common predictive tasks. The same workflow covers classification and regression, time-series forecasting, and time-series anomaly detection, with different model types producing different result shapes. Time-series forecasting and anomaly detection use TimesFM, ARIMA_PLUS, and ARIMA_PLUS_XREG models. Pipeline components orchestrate these same operations outside interactive SQL, including BigqueryForecastModelJobOp (opens in a new tab) for forecasts and BigqueryDetectAnomaliesModelJobOp for anomalies.
The three main inference results differ by question answered and output produced:
| Inference type | What it answers | What the output adds |
|---|---|---|
| Prediction | What category or value applies to each new row | A predicted label or numeric value for classification, regression, clustering, and recommendation models |
| Forecast | What future values a time series will have | Future time points with expected values from a time-series model |
| Anomaly detection | Which points do not follow the expected pattern | An anomaly flag or score for time-series rows that break from history |
Supplying new data for batch inference means providing input from BigQuery tables or from comma-separated values (CSV) objects stored in Cloud Storage. The output format does not need to match the input format, so a job can read a BigQuery table and write forecasting results to CSV in Cloud Storage, or read CSV files and write results to BigQuery. BigQuery source tables must be no larger than 100 GB, and a table in a different project requires granting the BigQuery Data Editor role to the service account. Time-series forecasts have an additional ordering rule where the forecast starts on the first row of a time series, ordered by time, with a null value in the target column, and null values must be continuous within that series.
CSV input in Cloud Storage has strict formatting and size rules. Each CSV source must meet the following requirements:
Storage Object Creator role to the service account when the bucket is in a different project.For CSV files an empty string is treated as null, while BigQuery supports null values natively.
Exam tip: A forecast begins at the first null target value in time order, and nulls cannot be mixed like 1, 2, null, 3, 4, null, null in one series.
Evaluation against actual outcomes is the step that compares predicted results against known true labels or values to judge model quality. An evaluation query runs the trained BigQuery ML model against a holdout or new dataset where the true label or value is known, then returns quality measures instead of only predictions. This separation matters because inference produces decisions for new rows, while evaluation measures how trustworthy those decisions are before wider use. BigQuery ML supports explanation alongside scoring to help analysts understand results, including explainable AI, feature attributions, and contribution analysis for changes in key metrics.
You can enable feature attributions when the output destination is BigQuery or JSONL on Cloud Storage, but feature attributions are not supported for CSV output on Cloud Storage.
Running inference from SQL tools and the console means starting the same BigQuery ML batch job from four interfaces that share one pattern. These interfaces let SQL practitioners stay in familiar tools while controlling model version, source, output, and options. A large batch job can take time to complete, so jobs are monitored after submission until output is delivered.
The four interfaces are:
A console batch inference follows an ordered flow from model selection to output delivery:
bq://projectid.datasetid.TimesFM uses AI.DETECT_ANOMALIES for time-series anomaly detection, while ARIMA_PLUS and ARIMA_PLUS_XREG use ML.DETECT_ANOMALIES.Batch inference in BigQuery ML generates predictions for many rows at once directly where the data lives without moving data to another system. Data flows from BigQuery tables into the trained model and prediction results flow back into BigQuery tables where they can be queried with GoogleSQL. The batch job and the BigQuery tables it reads and writes must be in the same region.
Choose ARIMA_PLUS_XREG when the forecast depends on external regressors, and choose TimesFM or ARIMA_PLUS when the forecast depends only on the history of the time series itself. Forecasting queries configure temporal scope with parameters such as forecast horizon, which controls how many future points are generated, and confidence level, which controls the prediction interval around each forecasted value.
TimesFM uses AI.DETECT_ANOMALIES for time-series anomaly detection, while ARIMA_PLUS and ARIMA_PLUS_XREG use ML.DETECT_ANOMALIES for the same time-series anomaly task. Choose supervised detection with ML.PREDICT when labeled data already identifies which rows are anomalies, and choose unsupervised detection with AI.DETECT_ANOMALIES or ML.DETECT_ANOMALIES when labels do not exist.
BigQuery source tables for batch inference must be no larger than 100 GB, while comma-separated values (CSV) sources in Cloud Storage must be no larger than 10 GB per object and 100 GB total. Each CSV source must include a header row with column names as the first row and enclose all strings in double quotation marks, and an empty string is treated as null while BigQuery supports null values natively.
A data analyst has trained a classification model named customer_churn_model using BigQuery ML to predict customer attrition. The analyst now needs to generate batch predictions on a new dataset of current subscribers stored in a table named active_customers and output the predicted labels alongside customer identifiers for a marketing campaign.
Which BigQuery ML function should the analyst use to execute these predictions?
Last updated