Guide to BigQuery ML workflows using SQL to create, train, evaluate, and predict with models, plus production practices for automating, monitoring, and deploying machine learning at scale.
Hello and welcome back.This guide walks through the core BigQuery ML workflow: how to create, train, evaluate, and use models for prediction — all using SQL inside BigQuery. In a few minutes you’ll see how straightforward the end-to-end cycle can be.We can break the workflow into four clear stages:
CREATE MODEL — define the model and the training query.
Model training — BigQuery executes the SQL, trains the model, and can tune hyperparameters (you can also set hyperparameters explicitly via OPTIONS).
ML.EVALUATE — compute evaluation metrics to verify model quality.
ML.PREDICT — generate predictions on new data (batch or streaming).
This create → train → evaluate → predict cycle repeats as you refine features or incorporate new data.and that’s
CREATE MODEL registers a model in your dataset and specifies the training query. Use the OPTIONS clause to select model_type and other configuration values (e.g., hyperparameters, input label, and optimization settings). The SELECT query defines the features and the label (target). If you know SQL, you already have most of the skills required to start with BigQuery ML.Example — create a simple linear regression model:
CREATE MODEL `project.dataset.model_name`OPTIONS(model_type='linear_reg') ASSELECT feature1, feature2, targetFROM `project.dataset.training_data`;
Notes on this example:
model_type='linear_reg' specifies linear regression. BigQuery ML supports many model types: logistic regression, DNN classifiers/regressors, boosted tree and XGBoost models, clustering, matrix factorization, and more.
The SELECT query defines the training set and the features. For supervised models, include the label (target) column in the query.
Use additional OPTIONS to set hyperparameters or to enable automatic hyperparameter tuning for supported model types.
Table — common BigQuery ML model types and typical use cases:
If evaluation metrics indicate poor performance, iterate: change features, add or clean data, engineer new features, or adjust model options, then retrain.
Use ML.PREDICT to apply a trained model to new data and produce predictions. Predictions can be executed in batch (SQL) for offline scoring or integrated into streaming pipelines and APIs for near-real-time inference.Example — batch prediction:
ML.PREDICT returns the predicted value along with probability/confidence columns for classification models (e.g., predicted_label, probability) and predicted values for regression models (predicted_value).
If your model underperforms, treat the evaluation results as actionable feedback: refine features, enrich or clean the training data, tune model options, and retrain. The SQL-first approach makes iteration fast and reproducible.