Stay organized with collections
Save and categorize content based on your preferences.
The ML.ROC_CURVE function
This document describes the ML.ROC_CURVE function, which you can use to
evaluate binary class classification specific metrics.
Syntax
ML.ROC_CURVE(
MODEL `PROJECT_ID.DATASET.MODEL_NAME`,
{ TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) },
[, GENERATE_ARRAY(THRESHOLDS)]
[, STRUCT(TRIAL_ID AS trial_id)])
Arguments
ML.ROC_CURVE takes the following arguments:
PROJECT_ID: the project that contains the
resource.
DATASET: the dataset that contains the
resource.
MODEL: the name of the model.
TABLE: the name of the input table that contains
the evaluation data.
If TABLE is specified, the input column names in the table must match the
column names in the model, and their types should be compatible according to
BigQuery implicit coercion rules.
The input must have a column that matches the
label column name that's provided during training. This value is provided
using the input_label_cols option. If input_label_cols is unspecified,
the column that's named label in the training data is used.
If you don't specify either TABLE or QUERY_STATEMENT,
ML.ROC_CURVE computes the curve results as follows:
If the data is split during training, the split evaluation data is used
to compute the curve results.
If the data is not split during training, the entire training input is
used to compute the curve results.
QUERY_STATEMENT: a GoogleSQL query that is
used to generate the evaluation data. For the supported SQL syntax of the
QUERY_STATEMENT clause in GoogleSQL, see
Query syntax.
If QUERY_STATEMENT is specified, the input column names from the query
must match the column names in the model, and their types should be
compatible according to BigQuery
implicit coercion rules.
The input must have a column that matches the label column name provided
during training. This value is provided using the input_label_cols option.
If input_label_cols is unspecified, the column named label in the
training data is used. The extra columns are ignored.
If you used the
TRANSFORM clause
in the CREATE MODEL statement that created the model, then only the input
columns present in the TRANSFORM clause must appear in QUERY_STATEMENT.
If you don't specify either table or QUERY_STATEMENT,
ML.ROC_CURVE computes the curve results as follows:
If the data is split during training, the split evaluation data is used
to compute the curve results.
If the data is not split during training, the entire training input is
used to compute the curve results.
THRESHOLDS: an ARRAY<FLOAT64> value that specifies
the percentile values of the prediction output supplied by the
GENERATE_ARRAY function.
TRIAL_ID: an INT64 value that identifies the
hyperparameter tuning trial that you want the function to evaluate. The
function uses the optimal trial by default. Only specify this argument if you
ran hyperparameter tuning when creating the model.
Output
ML.ROC_CURVE returns multiple rows with metrics for
different threshold values for the model. The metrics include the following:
threshold: a FLOAT64 value that contains the custom threshold for the
binary class classification model.
recall: a FLOAT64 value that indicates the proportion of actual positive
cases that were correctly predicted by the model.
true_positives: an INT64 value that contains the number of cases
correctly predicted as positive by the model.
false_positives: an INT64 value that contains the number of cases
incorrectly predicted as positive by the model.
true_negatives: an INT64 value that contains the number of cases
correctly predicted as negative by the model.
false_negatives: an INT64 value that contains the number of cases
incorrectly predicted as negative by the model.
Examples
The following examples assume your model and input table are in your default
project.
Evaluate the ROC curve of a binary class logistic regression model
The following query returns all of the output columns for ML.ROC_CURVE. You
can graph the recall and false_positive_rate values for an ROC curve. The
threshold values returned are chosen based on the percentile values of the
prediction output.
The following query returns all of the output columns for ML.ROC_CURVE. The
threshold values returned are chosen based on the output of the GENERATE_ARRAY
function.
Instead of getting an ROC curve (the recall versus false positive rate), the
following query calculates a precision-recall curve by using the precision
from the true and false positive counts:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eML.ROC_CURVE\u003c/code\u003e function is used to evaluate binary class classification models by returning metrics for different threshold values.\u003c/p\u003e\n"],["\u003cp\u003eThis function requires a model, and either an input table or a query to generate evaluation data, ensuring that column names and types match those in the model.\u003c/p\u003e\n"],["\u003cp\u003eUsers can specify custom threshold values using the \u003ccode\u003eGENERATE_ARRAY\u003c/code\u003e function to control the percentile values of the prediction output.\u003c/p\u003e\n"],["\u003cp\u003eThe output includes metrics like threshold, recall, true positives, false positives, true negatives, and false negatives, which can be used to generate an ROC curve or a precision-recall curve.\u003c/p\u003e\n"]]],[],null,["# The ML.ROC_CURVE function\n=========================\n\nThis document describes the `ML.ROC_CURVE` function, which you can use to\nevaluate binary class classification specific metrics.\n\nSyntax\n------\n\n```sql\nML.ROC_CURVE(\n MODEL `PROJECT_ID.DATASET.MODEL_NAME`,\n { TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) },\n [, GENERATE_ARRAY(THRESHOLDS)]\n [, STRUCT(TRIAL_ID AS trial_id)])\n```\n\n### Arguments\n\n`ML.ROC_CURVE` takes the following arguments:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project that contains the resource.\n- \u003cvar translate=\"no\"\u003eDATASET\u003c/var\u003e: the dataset that contains the resource.\n- \u003cvar translate=\"no\"\u003eMODEL\u003c/var\u003e: the name of the model.\n- \u003cvar translate=\"no\"\u003eTABLE\u003c/var\u003e: the name of the input table that contains\n the evaluation data.\n\n If `TABLE` is specified, the input column names in the table must match the\n column names in the model, and their types should be compatible according to\n BigQuery [implicit coercion rules](/bigquery/docs/reference/standard-sql/conversion_rules#coercion).\n The input must have a column that matches the\n label column name that's provided during training. This value is provided\n using the `input_label_cols` option. If `input_label_cols` is unspecified,\n the column that's named `label` in the training data is used.\n\n If you don't specify either `TABLE` or `QUERY_STATEMENT`,\n `ML.ROC_CURVE` computes the curve results as follows:\n - If the data is split during training, the split evaluation data is used to compute the curve results.\n - If the data is not split during training, the entire training input is used to compute the curve results.\n- \u003cvar translate=\"no\"\u003eQUERY_STATEMENT\u003c/var\u003e: a GoogleSQL query that is\n used to generate the evaluation data. For the supported SQL syntax of the\n `QUERY_STATEMENT` clause in GoogleSQL, see\n [Query syntax](/bigquery/docs/reference/standard-sql/query-syntax#sql_syntax).\n\n If `QUERY_STATEMENT` is specified, the input column names from the query\n must match the column names in the model, and their types should be\n compatible according to BigQuery\n [implicit coercion rules](/bigquery/docs/reference/standard-sql/conversion_rules#coercion).\n The input must have a column that matches the label column name provided\n during training. This value is provided using the `input_label_cols` option.\n If `input_label_cols` is unspecified, the column named `label` in the\n training data is used. The extra columns are ignored.\n\n If you used the\n [`TRANSFORM` clause](/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create#transform)\n in the `CREATE MODEL` statement that created the model, then only the input\n columns present in the `TRANSFORM` clause must appear in `QUERY_STATEMENT`.\n\n If you don't specify either `table` or `QUERY_STATEMENT`,\n `ML.ROC_CURVE` computes the curve results as follows:\n - If the data is split during training, the split evaluation data is used to compute the curve results.\n - If the data is not split during training, the entire training input is used to compute the curve results.\n- \u003cvar translate=\"no\"\u003eTHRESHOLDS\u003c/var\u003e: an `ARRAY\u003cFLOAT64\u003e` value that specifies\n the percentile values of the prediction output supplied by the\n [`GENERATE_ARRAY` function](/bigquery/docs/reference/standard-sql/array_functions#generate_array).\n\n- \u003cvar translate=\"no\"\u003eTRIAL_ID\u003c/var\u003e: an `INT64` value that identifies the\n hyperparameter tuning trial that you want the function to evaluate. The\n function uses the optimal trial by default. Only specify this argument if you\n ran hyperparameter tuning when creating the model.\n\nOutput\n------\n\n`ML.ROC_CURVE` returns multiple rows with metrics for\ndifferent threshold values for the model. The metrics include the following:\n\n- `threshold`: a `FLOAT64` value that contains the custom threshold for the binary class classification model.\n- `recall`: a `FLOAT64` value that indicates the proportion of actual positive cases that were correctly predicted by the model.\n- `true_positives`: an `INT64` value that contains the number of cases correctly predicted as positive by the model.\n- `false_positives`: an `INT64` value that contains the number of cases incorrectly predicted as positive by the model.\n- `true_negatives`: an `INT64` value that contains the number of cases correctly predicted as negative by the model.\n- `false_negatives`: an `INT64` value that contains the number of cases incorrectly predicted as negative by the model.\n\nExamples\n--------\n\nThe following examples assume your model and input table are in your default\nproject.\n\n### Evaluate the ROC curve of a binary class logistic regression model\n\nThe following query returns all of the output columns for `ML.ROC_CURVE`. You\ncan graph the `recall` and `false_positive_rate` values for an ROC curve. The\nthreshold values returned are chosen based on the percentile values of the\nprediction output. \n\n```sql\nSELECT\n *\nFROM\n ML.ROC_CURVE(MODEL `mydataset.mymodel`,\n TABLE `mydataset.mytable`)\n```\n\n### Evaluate an ROC curve with custom thresholds\n\nThe following query returns all of the output columns for `ML.ROC_CURVE`. The\nthreshold values returned are chosen based on the output of the `GENERATE_ARRAY`\nfunction. \n\n```sql\nSELECT\n *\nFROM\n ML.ROC_CURVE(MODEL `mydataset.mymodel`,\n TABLE `mydataset.mytable`,\n GENERATE_ARRAY(0.4,0.6,0.01))\n```\n\n### Evaluate the precision-recall curve\n\nInstead of getting an ROC curve (the recall versus false positive rate), the\nfollowing query calculates a precision-recall curve by using the precision\nfrom the true and false positive counts: \n\n```sql\nSELECT\n recall,\n true_positives / (true_positives + false_positives) AS precision\nFROM\n ML.ROC_CURVE(MODEL `mydataset.mymodel`,\n TABLE `mydataset.mytable`)\n```\n\nWhat's next\n-----------\n\n- For information about model evaluation, see [BigQuery ML model evaluation overview](/bigquery/docs/evaluate-overview).\n- For information about the supported SQL statements and functions for each model type, see [End-to-end user journey for each model](/bigquery/docs/e2e-journey)."]]