The ML.PRINCIPAL_COMPONENTS function
This document describes the ML.PRINCIPAL_COMPONENTS
function, which lets you
see the principal components of a principal component analysis (PCA) model.
Principal components and
eigenvectors
are the same concepts in PCA models.
Syntax
ML.PRINCIPAL_COMPONENTS(MODEL `project_id.dataset.model`)
Arguments
ML.PRINCIPAL_COMPONENT
takes the following arguments:
project_id
: Your project ID.dataset
: The BigQuery dataset that contains the model.model
: The name of the model.
Output
ML.PRINCIPAL_COMPONENTS
returns the following columns:
principal_component_id
: anINT64
that contains the principal component ID.feature
: aSTRING
value that contains the feature column name.numerical_value
: aFLOAT64
value that contains the feature value for the principal component thatprincipal_component_id
identifies if the column identified by thefeature
value is numeric. Otherwise,numerical_value
isNULL
.categorical_value
: anARRAY<STRUCT>
value that contains information about categorical features. Each struct contains the following fields:categorical_value.category
: aSTRING
value that contains the name of each category.categorical_value.value
: aFLOAT64
value that contains the value ofcategorical_value.category
for the principal component thatprincipal_component_id
identifies.
The output is in descending order by the eigenvalues of the principal
components, which you can get by using the
ML.PRINCIPAL_COMPONENT_INFO
function.
Example
The following example retrieves the principal components from the model
mydataset.mymodel
in your default project:
SELECT * FROM ML.PRINCIPAL_COMPONENTS(MODEL `mydataset.mymodel`)
What's next
- For information about model weights support in BigQuery ML, see BigQuery ML model weights overview.
- For information about the supported SQL statements and functions for each model type, see End-to-end user journey for each model.