Stay organized with collections
Save and categorize content based on your preferences.
The ML.RECONSTRUCTION_LOSS function
This document describes the ML.RECONSTRUCTION_LOSS function, which you can use
to compute the reconstruction losses between the input and output data of an
autoencoder model.
Syntax
ML.RECONSTRUCTION_LOSS(
MODEL `PROJECT_ID.DATASET.MODEL_NAME`,
{ TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) }
)
Arguments
ML.RECONSTRUCTION_LOSS 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 data table.
If you specify TABLE, the input column names in the table must match
the column names in the model, and their types must be compatible according to
BigQuery implicit coercion rules.
QUERY_STATEMENT: the GoogleSQL
query to use for input data to generate the reconstruction losses. For
the supported SQL syntax of the QUERY_STATEMENT clause in
GoogleSQL, see
Query syntax.
If you specify QUERY_STATEMENT, the input column names from the query must
match the column names in the model, and their types must be compatible
according to BigQuery implicit coercion rules.
If you used the
TRANSFORM clause
in the CREATE MODEL statement that created the model,
then you can only use the input columns present in the TRANSFORM clause
in the QUERY_STATEMENT.
Output
ML.RECONSTRUCTION_LOSS returns the following columns:
mean_absolute_error: a FLOAT64 value that contains the
mean absolute error for
the model.
mean_squared_error: a FLOAT64 value that contains the
mean squared error for
the model.
mean_squared_log_error: a FLOAT64 value that contains the mean squared
log error for the model.
[[["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.RECONSTRUCTION_LOSS\u003c/code\u003e function computes the reconstruction losses between input and output data of an autoencoder model in BigQuery ML.\u003c/p\u003e\n"],["\u003cp\u003eThis function accepts a model name and either a table or a query statement as input to generate reconstruction losses.\u003c/p\u003e\n"],["\u003cp\u003eInput column names and types must match the model's structure and adhere to BigQuery's implicit coercion rules when specifying either a table or a query statement.\u003c/p\u003e\n"],["\u003cp\u003eThe output of \u003ccode\u003eML.RECONSTRUCTION_LOSS\u003c/code\u003e includes \u003ccode\u003emean_absolute_error\u003c/code\u003e, \u003ccode\u003emean_squared_error\u003c/code\u003e, and \u003ccode\u003emean_squared_log_error\u003c/code\u003e, all of which are \u003ccode\u003eFLOAT64\u003c/code\u003e values.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eML.RECONSTRUCTION_LOSS\u003c/code\u003e is not compatible with imported TensorFlow models.\u003c/p\u003e\n"]]],[],null,["# The ML.RECONSTRUCTION_LOSS function\n===================================\n\nThis document describes the `ML.RECONSTRUCTION_LOSS` function, which you can use\nto compute the reconstruction losses between the input and output data of an\n[autoencoder model](/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create-autoencoder).\n\nSyntax\n------\n\n```sql\nML.RECONSTRUCTION_LOSS(\n MODEL `PROJECT_ID.DATASET.MODEL_NAME`,\n { TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) }\n)\n```\n\n### Arguments\n\n`ML.RECONSTRUCTION_LOSS` 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 data table.\n\n If you specify `TABLE`, the input column names in the table must match\n the column names in the model, and their types must be compatible according to\n BigQuery [implicit coercion rules](/bigquery/docs/reference/standard-sql/conversion_rules#coercion).\n- \u003cvar translate=\"no\"\u003eQUERY_STATEMENT\u003c/var\u003e: the GoogleSQL\n query to use for input data to generate the reconstruction losses. For\n the supported SQL syntax of the `QUERY_STATEMENT` clause in\n GoogleSQL, see\n [Query syntax](/bigquery/docs/reference/standard-sql/query-syntax#sql_syntax).\n\n If you specify `QUERY_STATEMENT`, the input column names from the query must\n match the column names in the model, and their types must be compatible\n according to BigQuery [implicit coercion rules](/bigquery/docs/reference/standard-sql/conversion_rules#coercion).\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,\n then you can only use the input columns present in the `TRANSFORM` clause\n in the `QUERY_STATEMENT`.\n\nOutput\n------\n\n`ML.RECONSTRUCTION_LOSS` returns the following columns:\n\n- `mean_absolute_error`: a `FLOAT64` value that contains the [mean absolute error](https://en.wikipedia.org/wiki/Mean_absolute_error) for the model.\n- `mean_squared_error`: a `FLOAT64` value that contains the [mean squared error](https://en.wikipedia.org/wiki/Mean_squared_error) for the model.\n- `mean_squared_log_error`: a `FLOAT64` value that contains the mean squared log error for the model.\n\nLimitations\n-----------\n\n`ML.RECONSTRUCTION_LOSS` doesn't support\n[imported TensorFlow models](/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create-tensorflow).\n\nExample\n-------\n\nThe following query computes reconstruction losses for the model\n`mydataset.mymodel` in your default project: \n\n```sql\nSELECT *\nFROM ML.RECONSTRUCTION_LOSS(\n MODEL `mydataset.mymodel`,\n (SELECT column1,\n column2,\n column3,\n column4\n FROM `mydataset.mytable`)\n)\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)."]]