A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-weights below:

The ML.WEIGHTS function | BigQuery

Stay organized with collections Save and categorize content based on your preferences.

The ML.WEIGHTS function

This document describes the ML.WEIGHTS function, which lets you see the underlying weights that a model uses during prediction. This function applies to linear and logistic regression models and matrix factorization models.

For matrix factorization models, you can use the ML.GENERATE_EMBEDDING function as an alternative to the ML.WEIGHTS function. ML.GENERATE_EMBEDDING generates the same factor weights and intercept data as ML.WEIGHTS as an array in a single column, rather than in two columns. Having all of the embeddings in a single column lets you directly use the VECTOR_SEARCH function on theML.GENERATE_EMBEDDING output.

Syntax
ML.WEIGHTS(
  MODEL `PROJECT_ID.DATASET.MODEL`,
  STRUCT([, STANDARDIZE AS standardize]))
Arguments

ML.WEIGHTS takes the following arguments:

Output

ML.WEIGHTS has different output columns for different model types.

Linear and logistic regression models

For linear and logistic regression models, ML.WEIGHTS returns the following columns:

If you used the TRANSFORM clause in the CREATE MODEL statement that created the model, ML.WEIGHTS outputs the weights of TRANSFORM output features. The weights are denormalized by default, with the option to get normalized weights, exactly like models that are created without TRANSFORM.

Matrix factorization models

For matrix factorization models, ML.WEIGHTS returns the following columns:

There is an additional row in the output that contains the global__intercept__ value calculated from the input data. This row has NULL values for the processed_input and factor_weights columns. For implicit feedback models, global__intercept__ is always 0.

Examples

The following examples show how to use ML.WEIGHTS with and without the standardize argument.

Without standardization

The following example retrieves weight information from mymodel in mydataset. The dataset is in your default project. It returns the weights that are associated with each one-hot encoded category for the input column input_col.

SELECT
  category,
  weight
FROM
  UNNEST((
    SELECT
      category_weights
    FROM
      ML.WEIGHTS(MODEL `mydataset.mymodel`)
    WHERE
      processed_input = 'input_col'))

This command uses the UNNEST function because the category_weights column is a nested repeated column.

With standardization

The following example retrieves weight information from mymodel in mydataset. The dataset is in your default project. It retrieves standardized weights, which assume all features have a mean of 0 and a standard deviation of 1.

SELECT
  *
FROM
  ML.WEIGHTS(MODEL `mydataset.mymodel`,
    STRUCT(true AS standardize))
What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["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-07 UTC."],[[["The `ML.WEIGHTS` function allows you to view the underlying weights used by a model during prediction for linear and logistic regression models as well as matrix factorization models."],["For matrix factorization models, `ML.GENERATE_EMBEDDING` can be used as an alternative to `ML.WEIGHTS`, providing similar factor weights and intercept data in a single column."],["`ML.WEIGHTS` syntax requires specifying the model, which includes the `project_id`, `dataset`, and `model` name, with an optional `standardize` argument for regression models."],["The output of `ML.WEIGHTS` varies by model type, providing details such as `trial_id`, `processed_input`, `weight`, and `category_weights` for regression models, and `feature`, `factor_weights`, and `intercept` for matrix factorization models."],["Standardization, when applied using the `standardize` argument, normalizes weights to assume all features have a mean of `0` and a standard deviation of `1`, allowing for magnitude comparison between weights in linear and logistic regression models."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4