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_COMPONENTS 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: anINT64that contains the principal component ID.feature: aSTRINGvalue that contains the feature column name.numerical_value: aFLOAT64value that contains the feature value for the principal component thatprincipal_component_ididentifies if the column identified by thefeaturevalue is numeric. Otherwise,numerical_valueisNULL.categorical_value: anARRAY<STRUCT>value that contains information about categorical features. Each struct contains the following fields:categorical_value.category: aSTRINGvalue that contains the name of each category.categorical_value.value: aFLOAT64value that contains the value ofcategorical_value.categoryfor the principal component thatprincipal_component_ididentifies.
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 more information about model weights support in BigQuery ML, see BigQuery ML model weights overview.
- For more information about supported SQL statements and functions for ML models, see End-to-end user journeys for ML models.