The ML.WEIGHTS Function

ML.WEIGHTS function

The ML.WEIGHTS function allows you to see the underlying weights used by a model during prediction.

ML.WEIGHTS returns the following columns:

  • processed_input — The name of the model feature input. The value of this column matches the name of the column in the SELECT statement used during training.
  • weight — The weight of each feature. For numerical columns, weight contains a value and the category_weights column is NULL. For non-numeric columns that are converted to one-hot encoding, the weight column is NULL and the category_weights column is an ARRAY of category names and weights for each category.
  • category_weights.category — The category name if the input column is non-numeric.
  • category_weights.weight — The category's weight if the input column is non-numeric.
  • class_label — For multiclass models, class_label is the label for a given weight. The output includes one row per <class_label, processed_input> combination.

ML.WEIGHTS syntax

ML.WEIGHTS(MODEL `project_id.dataset.model`)

Where:

  • project_id is your project ID.
  • dataset is the BigQuery dataset that contains the model.
  • model is the name of the model.

ML.WEIGHTS example

The following example retrieves weight information from mymodel in mydataset. The dataset is in your default project.

The query returns the weights 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.

Cette page vous a-t-elle été utile ? Évaluez-la :

Envoyer des commentaires concernant…

Besoin d'aide ? Consultez notre page d'assistance.