Associate Data Practitioner

Unlock the power of your data in the cloud! Get hands-on with Google Cloud's core data services like BigQuery and Looker to validate your practical skills in data ingestion, analysis, and management, and earn your Associate Data Practitioner certification!

Practice Test

Fundamental
Exam

Execute SQL to create, train, and evaluate models using BigQuery ML

Create Machine Learning Models Using SQL

BigQuery ML enables machine learning directly inside BigQuery using standard SQL commands. It lets you define, train, and evaluate models without moving data to another tool. This streamlines your workflow by keeping everything in one place. With simple SQL statements, data analysts and scientists can build models without writing complex code. All processing runs where the data lives, so you benefit from BigQuery’s speed and scalability.

BigQuery ML supports various model types, which you specify with the MODEL_TYPE clause in your SQL. After choosing a model type, you can set options for evaluation and training. You can choose from:

  • Linear Regression for numeric prediction
  • Logistic Regression for binary classification
  • K-Means Clustering for unsupervised grouping

This flexible approach helps you match the model to your analysis needs.

To start a model, you use the CREATE MODEL statement in BigQuery ML. First, write a SELECT query that defines your training data. Then, add options like input label and model type in the OPTIONS clause. This single command trains the model and stores it in a dataset. Everything happens in one SQL command, making model creation fast and easy.

Once your model is trained, you can assess its performance with the ML.EVALUATE function. This returns metrics such as mean squared error for regression or accuracy for classification. You run a SELECT query calling ML.EVALUATE over your model and test data. If needed, you can also use ML.TRAIN explicitly to control training details. Evaluating models helps you see if you need to refine features or adjust parameters.

After evaluation, you can generate predictions using the ML.PREDICT function. Provide new data in a SELECT statement, and ML.PREDICT returns predictions alongside your input fields. This on-demand prediction lets you integrate ML results directly into reports and dashboards. You can even feed these predictions into other SQL queries or export them for further analysis. BigQuery ML makes it simple to operationalize your models.

Conclusion

BigQuery ML lets you create, train, and evaluate models using only SQL, removing the need for separate ML tools. It supports multiple model types like linear regression, logistic regression, and k-means clustering, so you can pick the best fit for your problem. By using commands such as CREATE MODEL, ML.EVALUATE, and ML.PREDICT, you handle the entire machine learning cycle inside your data warehouse. This integrated approach speeds up development and reduces complexity. Mastering these SQL techniques will help you build and deploy reliable models more quickly.