bigquery-data-science 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bigquery_data_science/__init__.py +58 -0
- bigquery_data_science/_skills/PLANS.md +76 -0
- bigquery_data_science/_skills/bigquery-ai/SKILL.md +66 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_agg.md +528 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_classify.md +450 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_count_tokens.md +180 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_detect_anomalies.md +322 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_embed.md +425 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_evaluate.md +368 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_forecast.md +437 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate.md +693 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_bool.md +248 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_double.md +254 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_embedding.md +402 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_int.md +252 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_table.md +447 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_text.md +356 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_if.md +373 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_key_drivers.md +331 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_parse_document.md +416 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_predict.md +559 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_score.md +310 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_search.md +465 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ai_similarity.md +371 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/catalog_search.md +951 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/content_analysis.md +284 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/content_moderation.md +369 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/data_enrichment.md +426 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/document_intelligence.md +470 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/document_rag.md +453 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/image_deduplication.md +770 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/log_analysis.md +668 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/metric_diagnostics.md +568 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_annotate_image.md +680 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_generate_embedding.md +217 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_generate_text.md +223 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_process_document.md +392 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_transcribe.md +815 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_translate.md +600 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/ml_understand_text.md +673 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/multimodal_analysis.md +266 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/rag_pipeline.md +593 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/semantic_search.md +510 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/tabular_prediction.md +485 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/time_series_intelligence.md +489 -0
- bigquery_data_science/_skills/bigquery-ai/narrative/vector_search.md +672 -0
- bigquery_data_science/_skills/bigquery-ai/reference/augmented-analytics.md +77 -0
- bigquery_data_science/_skills/bigquery-ai/reference/cloud-ai-service-models.md +88 -0
- bigquery_data_science/_skills/bigquery-ai/reference/document-processing.md +95 -0
- bigquery_data_science/_skills/bigquery-ai/reference/embeddings-and-search.md +166 -0
- bigquery_data_science/_skills/bigquery-ai/reference/general-purpose-generation.md +87 -0
- bigquery_data_science/_skills/bigquery-ai/reference/managed-functions.md +72 -0
- bigquery_data_science/_skills/bigquery-ai/reference/predictive-ai.md +113 -0
- bigquery_data_science/_skills/bigquery-ai/reference/workflows.md +56 -0
- bigquery_data_science/_skills/bigquery-ai/skill.manifest.json +109 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/INDEX.md +71 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiagg.md +67 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aicausal_effect-covered-in-bigquery-ml.md +17 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiclassify.md +72 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aicount_tokens.md +53 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aidetect_anomalies.md +63 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiembed.md +85 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aievaluate.md +114 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiforecast.md +123 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate.md +69 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_bool.md +53 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_double.md +45 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_embedding.md +108 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_int.md +45 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_table.md +64 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_text.md +167 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiif.md +56 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aikey_drivers.md +76 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiparse_document.md +91 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aipredict.md +74 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aiscore.md +52 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aisearch.md +66 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/aisimilarity.md +79 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/choosing-between-these-and-the-ai-functions.md +11 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/hybrid-search-capability.md +165 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mlannotate_image.md +24 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mlgenerate_embedding.md +34 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mlgenerate_text.md +65 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mlprocess_document.md +125 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mltranscribe.md +26 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mltranslate.md +27 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/mlunderstand_text.md +32 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/multimodal-input-patterns-by-function.md +128 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/object-tables.md +109 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objectref-and-objectrefruntime-schema-reference.md +50 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objfetch_metadata.md +49 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objget_access_url.md +66 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objget_read_url.md +40 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objlist.md +34 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/objmake_ref.md +58 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/per-row-failures-and-the-retry-pattern.md +19 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/setup-apis-connection-roles.md +39 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/two-input-shapes.md +22 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/vector_search.md +78 -0
- bigquery_data_science/_skills/bigquery-ai/syntax/what-the-five-have-in-common.md +27 -0
- bigquery_data_science/_skills/bigquery-data-science/SKILL.md +69 -0
- bigquery_data_science/_skills/bigquery-data-science/reference/namespace-matrix.md +112 -0
- bigquery_data_science/_skills/bigquery-data-science/skill.manifest.json +13 -0
- bigquery_data_science/_skills/bigquery-ml/SKILL.md +70 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/airflow_with_kfp.md +379 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/anomaly_fraud_detection.md +195 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/arima_plus.md +635 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/arima_plus_xreg.md +453 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/autoencoder.md +470 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/automl_classifier.md +291 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/automl_regressor.md +274 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/boosted_tree_classifier.md +449 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/boosted_tree_regressor.md +400 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/bucketizing.md +201 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/causal_effect.md +773 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/churn_retention.md +271 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/cloud_workflows.md +370 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/composer_airflow.md +475 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/contribution_analysis.md +346 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/cross_validation.md +185 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/customer_segmentation.md +233 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/dataform.md +372 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/dbt.md +283 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/difference_in_differences.md +280 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/distance.md +195 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/dnn_classifier.md +326 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/dnn_regressor.md +308 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/embeddings_classification.md +426 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/encoding.md +238 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/ensembling.md +278 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/evaluation.md +445 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/exploration.md +779 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/export.md +321 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/feature_engineering.md +280 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/feature_store.md +652 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/feature_store_workflow.md +426 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/ga4_churn_prediction.md +285 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/hierarchical_forecasting.md +441 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/image.md +791 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/imported.md +426 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/kmeans.md +348 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/linear_regression.md +372 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/logistic_regression.md +390 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/matrix_factorization.md +404 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/model_monitoring.md +609 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/pca.md +357 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/price_elasticity_dml.md +286 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/propensity_score_matching.md +350 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/random_forest_classifier.md +445 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/random_forest_regressor.md +409 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/recommendation.md +281 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/regression_based_forecasting.md +491 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/remote.md +428 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/scalers.md +325 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/scheduled_queries.md +284 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/sql_scripting.md +243 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/survival_analysis.md +363 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/synthetic_control.md +221 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/text.md +215 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/time_series.md +669 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/transform_only.md +273 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/uplift_cate.md +241 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/vertex_kfp.md +360 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/wide_and_deep_classifier.md +316 -0
- bigquery_data_science/_skills/bigquery-ml/narrative/wide_and_deep_regressor.md +298 -0
- bigquery_data_science/_skills/bigquery-ml/reference/classification.md +80 -0
- bigquery_data_science/_skills/bigquery-ml/reference/model-management.md +90 -0
- bigquery_data_science/_skills/bigquery-ml/reference/preprocessing-functions.md +234 -0
- bigquery_data_science/_skills/bigquery-ml/reference/regression.md +79 -0
- bigquery_data_science/_skills/bigquery-ml/reference/unsupervised-and-specialized.md +101 -0
- bigquery_data_science/_skills/bigquery-ml/reference/workflows-and-pipelines.md +111 -0
- bigquery_data_science/_skills/bigquery-ml/skill.manifest.json +177 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/1-model_type-catalog.md +28 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/2-task-mlevaluate-metric-columns.md +26 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/3-capability-matrix-per-model-type.md +21 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/4-explainability-weights-functions.md +14 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/5-connection-matrix.md +11 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/6-which-model-free-function-no-create-model-no-connection.md +15 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/7-point-in-time-feature-retrieval-which-of-the-two.md +11 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/INDEX.md +111 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/aicausal_effect.md +85 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus-forecasting-lifecycle-functions.md +14 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus-univariate-time-series-forecasting.md +132 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus_xreg-multivariate-time-series-with-external-regressors.md +103 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/autoencoder.md +102 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/automl_classifier-automl_regressor.md +88 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/boosted_tree_classifier-boosted_tree_regressor.md +117 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/contribution_analysis.md +113 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/dnn_classifier-dnn_regressor.md +107 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/dnn_linear_combined_classifier-dnn_linear_combined_regressor-wide-and-deep.md +98 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/explainability-functions-mlexplain_predict-mlglobal_explain-mlfeature_importance.md +7 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/exploratory-data-analysis-mldescribe_data-mlcorrelation.md +11 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/export-model.md +92 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/feature-engineering-standalone-preprocessing-functions.md +13 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/image-preprocessing-functions-mldecode_image-mlresize_image-mlconvert_image_type-mlconvert_color_space.md +63 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/imported-models-tensorflow-tensorflow_lite-onnx-xgboost.md +36 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/kmeans.md +87 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/linear_reg-logistic_reg-generalized-linear-models.md +101 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/matrix_factorization.md +162 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mladvanced_weights.md +76 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlarima_coefficients.md +30 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlarima_evaluate.md +49 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlbag_of_words.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlbucketize.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlcentroids.md +46 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlconfusion_matrix.md +56 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlconvert_color_space.md +53 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlconvert_image_type.md +39 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlcorrelation.md +78 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mldecode_image.md +44 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mldescribe_data.md +74 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mldetect_anomalies.md +86 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mldistance.md +48 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlentity_features_at_time.md +56 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlevaluate.md +72 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlexplain_forecast.md +50 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlexplain_predict.md +66 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_cross.md +46 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_importance.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_info.md +50 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlfeatures_at_time.md +51 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlforecast.md +76 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlgenerate_embedding-from-a-bqml-pca-autoencoder-matrix_factorization-model.md +64 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlglobal_explain.md +63 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlhash_bucketize.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlholiday_info.md +46 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlimputer.md +46 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mllp_norm.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlmetrics.md +80 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlngrams.md +37 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlone_hot_encoder-mlmulti_hot_encoder-mllabel_encoder.md +67 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlpolynomial_expand.md +47 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlpredict.md +67 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlprincipal_component_info.md +42 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlprincipal_components.md +40 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlquantile_bucketize.md +43 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlrecommend.md +60 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlreconstruction_loss.md +48 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlresize_image.md +45 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlroc_curve.md +63 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltf_idf.md +37 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltfdv_describe.md +34 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltfdv_validate.md +48 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltraining_info.md +78 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltransform-applying-a-saved-transform.md +52 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltranspose-not-a-function-pointer.md +32 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mltrial_info.md +60 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlvalidate_data_drift.md +99 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlvalidate_data_skew.md +50 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/mlweights.md +84 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/model-free-time-series-decomposition-mltrend-mlseasonality-mldetect_change_points.md +100 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/model-introspection-mlfeature_info-mltraining_info-mltrial_info.md +7 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/model-monitoring-data-validation.md +23 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/numerical-scalers-mlstandard_scaler-mlmin_max_scaler-mlmax_abs_scaler-mlrobust_scaler-mlnormalizer.md +77 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/onnx.md +55 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/pca.md +91 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/point-in-time-feature-retrieval-mlfeatures_at_time-mlentity_features_at_time.md +25 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/quick-comparison.md +14 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/random_forest_classifier-random_forest_regressor.md +123 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/remote-remote-model-over-a-vertex-ai-endpoint-the-mechanism.md +87 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/tensorflow.md +48 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/tensorflow_lite.md +29 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/text-preprocessing-functions-mlngrams-mltf_idf-mlbag_of_words.md +18 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/timesfm-built-in-foundation-forecaster-see-bigquery-ai.md +28 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/transform_only.md +91 -0
- bigquery_data_science/_skills/bigquery-ml/syntax/xgboost.md +72 -0
- bigquery_data_science/_skills/pinned-models.json +28 -0
- bigquery_data_science/catalog.py +1107 -0
- bigquery_data_science/cli.py +786 -0
- bigquery_data_science/installer.py +282 -0
- bigquery_data_science/mcp_server.py +317 -0
- bigquery_data_science/tooling/__init__.py +15 -0
- bigquery_data_science/tooling/convert_notebook.py +176 -0
- bigquery_data_science/tooling/link_policy.py +247 -0
- bigquery_data_science/tooling/manifest.py +152 -0
- bigquery_data_science/tooling/markdown_anchors.py +84 -0
- bigquery_data_science/tooling/narrative_drift.py +163 -0
- bigquery_data_science/tooling/pinned_models.py +216 -0
- bigquery_data_science/tooling/reference_structure.py +85 -0
- bigquery_data_science/tooling/sync_syntax.py +407 -0
- bigquery_data_science/tooling/validate.py +208 -0
- bigquery_data_science-0.7.0.dist-info/METADATA +306 -0
- bigquery_data_science-0.7.0.dist-info/RECORD +286 -0
- bigquery_data_science-0.7.0.dist-info/WHEEL +4 -0
- bigquery_data_science-0.7.0.dist-info/entry_points.txt +5 -0
- bigquery_data_science-0.7.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# `ML.ADVANCED_WEIGHTS`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-lifecycle-functions.md#mladvanced_weights`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-lifecycle-functions.md#mladvanced_weights)
|
|
4
|
+
|
|
5
|
+
- **Description:** Extended version of `ML.WEIGHTS` for **linear regression** and **binary logistic regression** models. Returns the same weights plus per-weight **standard errors** and **p-values** (statistical significance). Its output is a superset of `ML.WEIGHTS`.
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Statistical inference on coefficients (significance testing) for econometric / explanatory modeling.
|
|
8
|
+
- Identify which features have weights statistically distinguishable from zero.
|
|
9
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-advanced-weights
|
|
10
|
+
- **Type:** Table-valued function.
|
|
11
|
+
- **Applies to models:** `LINEAR_REG` and **binary** `LOGISTIC_REG` only. Multiclass logistic regression and matrix factorization are NOT supported. Model must be trained with `CALCULATE_P_VALUES = TRUE`, `CATEGORY_ENCODING_METHOD = 'DUMMY_ENCODING'`, and `L1_REG = 0`.
|
|
12
|
+
|
|
13
|
+
**Syntax:**
|
|
14
|
+
```sql
|
|
15
|
+
SELECT *
|
|
16
|
+
FROM ML.ADVANCED_WEIGHTS(MODEL `PROJECT_ID.DATASET.MODEL_NAME`
|
|
17
|
+
[, STRUCT(TRUE AS standardize)]);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Inputs:**
|
|
21
|
+
|
|
22
|
+
| Parameter | Type | Required | Default | Description |
|
|
23
|
+
|-----------|------|----------|---------|-------------|
|
|
24
|
+
| `MODEL` | model ref | Yes | — | Linear or binary logistic regression model trained with the required options above. |
|
|
25
|
+
| `STANDARDIZE` | BOOL (in STRUCT) | No | `FALSE` | Standardize weights (mean 0 / std 1). Set TRUE to obtain a standard error and p-value for the intercept. |
|
|
26
|
+
|
|
27
|
+
**Outputs:**
|
|
28
|
+
|
|
29
|
+
| Column | Type | Description |
|
|
30
|
+
|--------|------|-------------|
|
|
31
|
+
| `processed_input` | STRING | Feature input column name. |
|
|
32
|
+
| `weight` | FLOAT64 | Weight for a numeric feature; NULL for categorical (see `category`). |
|
|
33
|
+
| `category` | STRING | Category name for non-numeric/dummy-encoded inputs (NULL for numeric). |
|
|
34
|
+
| `standard_error` | FLOAT64 | Standard error of the weight. `NULL` for the intercept unless `standardize=TRUE`; **`0.0`** (not `NaN`) for a dropped dummy category. |
|
|
35
|
+
| `p_value` | FLOAT64 | p-value of the weight. `NULL` for the intercept unless `standardize=TRUE`; **`NaN`** for a dropped dummy category. |
|
|
36
|
+
|
|
37
|
+
The intercept arrives as a final row with `processed_input = '__INTERCEPT__'` and `category = NULL`. Note the two sentinel values differ: a baseline row is `weight = 0.0`, `standard_error = 0.0`, `p_value = NaN`, so `NOT IS_NAN(p_value)` is the reliable filter — reading `standard_error = 0.0` as a measured value will silently corrupt any average.
|
|
38
|
+
|
|
39
|
+
**Best practices:**
|
|
40
|
+
- Train with `CALCULATE_P_VALUES = TRUE` up front — p-values/standard errors are computed at CREATE MODEL time and cannot be added later.
|
|
41
|
+
- Set `STANDARDIZE => TRUE` when you need inference statistics for the intercept.
|
|
42
|
+
|
|
43
|
+
**Limitations:**
|
|
44
|
+
- Not available for multiclass logistic regression, matrix factorization, or any non-GLM model.
|
|
45
|
+
- Requires `L1_REG = 0` and `DUMMY_ENCODING`; incompatible with L1 regularization.
|
|
46
|
+
- Dropped dummy categories report `weight = 0.0` and `standard_error = 0.0` with a `NaN` p-value.
|
|
47
|
+
|
|
48
|
+
**Gotchas (verified live):**
|
|
49
|
+
- **Each precondition fails differently, and three of the four fail at `CREATE MODEL` time, not at query time.** Verified error text:
|
|
50
|
+
|
|
51
|
+
| What you got wrong | Where it fails | Message |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `calculate_p_values` omitted | the TVF | `Model is not supported by ML.ADVANCED_WEIGHTS because it was not trained with calculate_p_values = true.` |
|
|
54
|
+
| left the default `ONE_HOT_ENCODING` | `CREATE MODEL` | `Please specify CATEGORY_ENCODING_METHOD=DUMMY_ENCODING to enable p_values calculation.` |
|
|
55
|
+
| `l1_reg > 0` | `CREATE MODEL` | `L1_REG must be zero if CALCULATE_P_VALUES=TRUE.` |
|
|
56
|
+
| multiclass label | `CREATE MODEL` | `Option(s) calculate_p_values are found. P-values can only be calculated for linear regression and binary logistic regression models.` |
|
|
57
|
+
|
|
58
|
+
- **A model with categorical features emits a warning at `CREATE MODEL` time:** `Since model contains categorical values, regression statistics will not be calculated for unstandardized intercept.` This is expected, not a failure — it is why `__INTERCEPT__` returns `NULL` statistics and why `STRUCT(TRUE AS standardize)` exists.
|
|
59
|
+
- **The dropped `DUMMY_ENCODING` baseline is the most frequent category, not the first alphabetically.** On `penguins` the baselines are Adelie (146 rows), Biscoe (163), and `MALE` (168) — `MALE` wins despite `FEMALE` sorting earlier.
|
|
60
|
+
- **`standardize` does not change any p-value.** It scales `weight` and `standard_error` by the same factor, so the t-statistic is invariant. Use it to compare effect sizes on a common scale, never to change which coefficients are significant.
|
|
61
|
+
- **The standardized intercept is not the label mean.** Categorical features stay dummy-coded rather than centered, so it is the prediction at mean numeric features *and* baseline categories. On `penguins` it is 4110.72 while mean `body_mass_g` is 4207.06.
|
|
62
|
+
- **`p_value` bottoms out near `1e-15`** (double-precision floor). Below that, differences are numerical noise — do not rank features by p-value down there.
|
|
63
|
+
- **`category` values inherit whatever is in the data, including leading whitespace.** `census_adult_income` returns `' White'` and `' Female'`; `category = 'White'` matches nothing. Use `TRIM(category)`.
|
|
64
|
+
|
|
65
|
+
**BigFrames API:** No dedicated wrapper; call the TVF via SQL / `read_gbq`.
|
|
66
|
+
|
|
67
|
+
**Repo example (tested):** `bigquery-ml/models/linear_regression/` (Example 7) and `bigquery-ml/models/logistic_regression/` (Example 8) — the two model types that satisfy the constraint, each training its main model with `calculate_p_values = TRUE`, `DUMMY_ENCODING`, and `l1_reg = 0` from the start, since the options cannot be added later.
|
|
68
|
+
|
|
69
|
+
The linear example is the clean statistical read: on `penguins`, `island` is the only feature whose categories are insignificant (p ≈ 0.82 and 0.42) because Gentoo appears only on Biscoe and Chinstrap only on Dream, so `island` merely restates `species`. `ML.WEIGHTS` reports non-zero island weights and gives you no way to see this. It also runs the `STRUCT(TRUE AS standardize)` variant to recover intercept statistics and to show that `flipper_length_mm` moves from 16.24 g/mm to 227.60 g per standard deviation while its p-value is unchanged at 2.6e-06.
|
|
70
|
+
|
|
71
|
+
The logistic example is the scale read: on `census_adult_income` the model expands to 106 rows (105 coefficients plus `__INTERCEPT__`); eight are dropped baselines, leaving 97 real tests, and **54 of those come back with p > 0.05**. Verified breakdown — `native_country` 38/41 insignificant, `education` 5/15, `workclass` 4/8, `occupation` 4/14, `race` 2/4, `marital_status` 1/6, and every numeric feature significant. More than half of what a 32k-row model learned is undefendable, concentrated almost entirely in one sparse high-cardinality column, and neither `ML.WEIGHTS` nor `ML.GLOBAL_EXPLAIN` would surface it.
|
|
72
|
+
|
|
73
|
+
> Note: For boosted trees / random forest see `ML.FEATURE_IMPORTANCE` and `ML.GLOBAL_EXPLAIN`; for k-means see `ML.CENTROIDS`; for PCA/autoencoder see `ML.PRINCIPAL_COMPONENTS` / `ML.PRINCIPAL_COMPONENT_INFO`; for ARIMA_PLUS see `ML.ARIMA_COEFFICIENTS`. The tree, clustering, and forecasting model files (`models/boosted_tree_classifier/`, `models/pca/`, `models/kmeans/`, `models/autoencoder/`, `models/arima_plus/`) do NOT use `ML.WEIGHTS`. Neither do the DNN and wide-and-deep types — `models/dnn_classifier/` (Example 7) records why: no coefficients exist, so Integrated Gradients via `ML.GLOBAL_EXPLAIN` is the only mechanism available there.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
---
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# `ML.ARIMA_COEFFICIENTS`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-lifecycle-functions.md#mlarima_coefficients`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-lifecycle-functions.md#mlarima_coefficients)
|
|
4
|
+
|
|
5
|
+
- **Description:** Returns the fitted ARIMA coefficients per time series — the "weights" function for ARIMA_PLUS models.
|
|
6
|
+
- **Use cases:** Inspect AR/MA coefficient vectors and the intercept/drift; audit/export fitted model parameters.
|
|
7
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-arima-coefficients
|
|
8
|
+
- **Type:** Table-valued (model-weights family). **Applies to models:** `ARIMA_PLUS`, `ARIMA_PLUS_XREG`. **Status:** GA.
|
|
9
|
+
|
|
10
|
+
**Syntax:**
|
|
11
|
+
```sql
|
|
12
|
+
SELECT *
|
|
13
|
+
FROM ML.ARIMA_COEFFICIENTS(MODEL `PROJECT_ID.DATASET.MODEL_NAME`);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Outputs:**
|
|
17
|
+
|
|
18
|
+
| Column | Type | Description |
|
|
19
|
+
|--------|------|-------------|
|
|
20
|
+
| `\<time_series_id_col\>` | (varies) | Series id (when trained with `time_series_id_col`). |
|
|
21
|
+
| `ar_coefficients` | ARRAY\<FLOAT64\> | Autoregressive (AR) coefficients; length = `non_seasonal_p`. Empty `[]` when p=0. |
|
|
22
|
+
| `ma_coefficients` | ARRAY\<FLOAT64\> | Moving-average (MA) coefficients; length = `non_seasonal_q`. Empty `[]` when q=0. |
|
|
23
|
+
| `intercept_or_drift` | FLOAT64 | Constant (intercept) or drift term of the model. |
|
|
24
|
+
|
|
25
|
+
**Best practices:** Join with `ML.ARIMA_EVALUATE` on the series id to pair `(p,d,q)` with the coefficient vectors.
|
|
26
|
+
**Limitations:** Output is the ARIMA-specific analog of `ML.WEIGHTS`; standard `ML.WEIGHTS` does not apply to ARIMA_PLUS.
|
|
27
|
+
**BigFrames API:** `bigframes.ml.forecasting.ARIMAPlus().coef_` (or `.summary()`).
|
|
28
|
+
**Repo example (tested):** `bigquery-ml/models/arima_plus/arima_plus.sql` (Example 8) — per-series `ar_coefficients` / `ma_coefficients` / `intercept_or_drift`, sitting directly after `ML.ARIMA_EVALUATE` (Example 3) so the `(p,d,q)` order and the coefficient vector lengths can be read against each other.
|
|
29
|
+
|
|
30
|
+
---
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# `ML.ARIMA_EVALUATE`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-lifecycle-functions.md#mlarima_evaluate`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-lifecycle-functions.md#mlarima_evaluate)
|
|
4
|
+
|
|
5
|
+
- **Description:** Returns the auto-ARIMA model selection results and quality metrics, one row per time series (the candidate chosen by auto.ARIMA, or all candidates with `show_all_candidate_models`).
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Inspect the selected `(p,d,q)` order, drift, and AIC per series.
|
|
8
|
+
- See which decomposition features fired (`has_holiday_effect`, `has_spikes_and_dips`, `has_step_changes`) and detected seasonalities.
|
|
9
|
+
- Surface per-series training failures via `error_message`.
|
|
10
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-arima-evaluate
|
|
11
|
+
- **Type:** Table-valued. **Applies to models:** `ARIMA_PLUS`, `ARIMA_PLUS_XREG`. **Status:** GA.
|
|
12
|
+
|
|
13
|
+
**Syntax:**
|
|
14
|
+
```sql
|
|
15
|
+
SELECT *
|
|
16
|
+
FROM ML.ARIMA_EVALUATE(
|
|
17
|
+
MODEL `PROJECT_ID.DATASET.MODEL_NAME`,
|
|
18
|
+
STRUCT(FALSE AS show_all_candidate_models)
|
|
19
|
+
);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Inputs:**
|
|
23
|
+
|
|
24
|
+
| Parameter | Type | Required | Default | Description |
|
|
25
|
+
|-----------|------|----------|---------|-------------|
|
|
26
|
+
| `show_all_candidate_models` | BOOL | No | FALSE | If TRUE, returns every candidate ARIMA model evaluated by auto.ARIMA; if FALSE, only the selected model per series. |
|
|
27
|
+
|
|
28
|
+
**Outputs:**
|
|
29
|
+
|
|
30
|
+
| Column | Type | Description |
|
|
31
|
+
|--------|------|-------------|
|
|
32
|
+
| `\<time_series_id_col\>` | (varies) | Series id (when trained with `time_series_id_col`). |
|
|
33
|
+
| `non_seasonal_p` / `non_seasonal_d` / `non_seasonal_q` | INT64 | ARIMA order (AR lags, differencing degree, MA terms). |
|
|
34
|
+
| `has_drift` | BOOL | Whether a drift term is included. |
|
|
35
|
+
| `log_likelihood` | FLOAT64 | Model log-likelihood. |
|
|
36
|
+
| `AIC` | FLOAT64 | Akaike Information Criterion (lower is better; selection criterion). |
|
|
37
|
+
| `variance` | FLOAT64 | Variance of the model residuals. |
|
|
38
|
+
| `seasonal_periods` | ARRAY\<STRING\> | Detected seasonalities, e.g. `[WEEKLY]`, `[WEEKLY, YEARLY]`, `[NO_SEASONALITY]`. |
|
|
39
|
+
| `has_holiday_effect` | BOOL | Holiday effect detected (when `holiday_region` set). |
|
|
40
|
+
| `has_spikes_and_dips` | BOOL | Spike/dip outliers detected. |
|
|
41
|
+
| `has_step_changes` | BOOL | Step (level) changes detected. |
|
|
42
|
+
| `error_message` | STRING | Per-series training error, empty when successful. |
|
|
43
|
+
|
|
44
|
+
**Best practices:** Order by the series id column for stable review; check `error_message` for short/failed series.
|
|
45
|
+
**Limitations:** `seasonal_periods`, `has_holiday_effect`, etc. depend on `CREATE MODEL` options (e.g. `holiday_region`).
|
|
46
|
+
**BigFrames API:** No direct equivalent.
|
|
47
|
+
**Repo example (tested):** `bigquery-ml/models/arima_plus/arima_plus.sql` (Example 3) — the full per-series model-selection table for a multi-series model. Example 10 in the same file uses it as the *verification* of a manual order: training with `auto_arima = FALSE` and `non_seasonal_order = STRUCT(2 AS p, 1 AS d, 1 AS q)`, then reading `non_seasonal_p/d/q` back to confirm auto.ARIMA was actually bypassed.
|
|
48
|
+
|
|
49
|
+
---
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# `ML.BAG_OF_WORDS`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mlbag_of_words`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mlbag_of_words)
|
|
4
|
+
|
|
5
|
+
- **Description:** Computes a bag-of-words (per-document term-frequency) representation of tokenized documents.
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Produce sparse count features for text classification when raw frequency (not IDF weighting) is wanted.
|
|
8
|
+
- Quick baseline text features feeding `LOGISTIC_REG` / `BOOSTED_TREE_*`.
|
|
9
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-bag-of-words
|
|
10
|
+
- **Type:** Analytic — **requires `OVER ()`** (dictionary is built across the document window).
|
|
11
|
+
- **Applies to models:** Any model type via `TRANSFORM` or precomputed columns.
|
|
12
|
+
|
|
13
|
+
**Syntax:**
|
|
14
|
+
```sql
|
|
15
|
+
ML.BAG_OF_WORDS(tokenized_document [, top_k] [, frequency_threshold]) OVER ()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Inputs:**
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Required | Default | Description |
|
|
21
|
+
|-----------|------|----------|---------|-------------|
|
|
22
|
+
| `tokenized_document` | `ARRAY<STRING>` | Yes | — | One document's tokens. |
|
|
23
|
+
| `top_k` | `INT64` | No | 32000 (max 1048576) | Dictionary size excluding the unknown term; keeps the `top_k` terms appearing in the most documents. |
|
|
24
|
+
| `frequency_threshold` | `INT64` | No | 5 | Minimum number of documents a term must appear in to enter the dictionary. |
|
|
25
|
+
|
|
26
|
+
**Outputs:**
|
|
27
|
+
|
|
28
|
+
| Column | Type | Description |
|
|
29
|
+
|--------|------|-------------|
|
|
30
|
+
| (result) | `ARRAY<STRUCT<index INT64, value INT64>>` | Per-document term counts. `index 0` = unknown term; remaining indices map to the alphabetically ordered dictionary; `value` is the count of that term in the document. |
|
|
31
|
+
|
|
32
|
+
**Best practices:** Use inside `TRANSFORM` so the dictionary is frozen with the model and re-applied at predict time. Combine with `ML.NGRAMS` upstream for n-gram bags. Use `top_k` to cap dimensionality.
|
|
33
|
+
**Limitations:** Empty `OVER ()` required; counts depend on the analytic window — apply over the full corpus. Index `0` reserved for unknown. Shares the same `frequency_threshold=5` default gotcha as `ML.TF_IDF` above — verified live (see that entry).
|
|
34
|
+
**BigFrames API:** No direct equivalent.
|
|
35
|
+
**Repo example (tested):** `bigquery-ml/functions/text/text.ipynb` — real product-name tokens, the `frequency_threshold=5` gotcha proof, and `ML.BAG_OF_WORDS` embedded in a real `LOGISTIC_REG` `TRANSFORM` classifying product category from the product name alone (~0.95 accuracy).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
**Status:** All three are **GA**. **Connection required:** No.
|
|
40
|
+
|
|
41
|
+
**Typical pipeline:** tokenize (GoogleSQL `TEXT_ANALYZE`/`SPLIT`) → optional `ML.NGRAMS` → `ML.BAG_OF_WORDS`
|
|
42
|
+
or `ML.TF_IDF` (in `TRANSFORM`) → train classifier. Note: `ML.TF_IDF`/`ML.BAG_OF_WORDS` are analytic
|
|
43
|
+
(`OVER ()`) and an analytic function cannot be an argument of another analytic function — chain via
|
|
44
|
+
subqueries/CTEs, not nesting (consistent with the repo's note for `ML.STANDARD_SCALER` etc.).
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
---
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# `ML.BUCKETIZE`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mlbucketize`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mlbucketize)
|
|
4
|
+
|
|
5
|
+
- **Description:** Bucketizes a continuous numerical value into a string-named bucket using a manually supplied array of split points (bin boundaries).
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Convert a numeric column (age, price) into categorical bins for linear/logistic models.
|
|
8
|
+
- Encode domain knowledge as explicit boundaries (e.g. age brackets).
|
|
9
|
+
- Inside `TRANSFORM` so the same boundaries are reapplied at `ML.PREDICT`.
|
|
10
|
+
- **documentation:** [ML.BUCKETIZE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-bucketize)
|
|
11
|
+
- **Type:** Scalar (operates row-by-row; no `OVER()`).
|
|
12
|
+
- **Applies to models:** Any model type that supports manual feature preprocessing (linear/logistic regression, boosted trees, DNN, k-means, etc.) when used in `TRANSFORM`; also usable in plain SQL.
|
|
13
|
+
|
|
14
|
+
**Syntax:**
|
|
15
|
+
```sql
|
|
16
|
+
ML.BUCKETIZE(numerical_expression, array_split_points[, exclude_boundaries[, output_format]])
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Inputs:**
|
|
20
|
+
|
|
21
|
+
| Parameter | Type | Required | Default | Description |
|
|
22
|
+
|-----------|------|----------|---------|-------------|
|
|
23
|
+
| `numerical_expression` | NUMERIC/FLOAT64 | Yes | — | The numerical value to bucketize. |
|
|
24
|
+
| `array_split_points` | ARRAY\<numeric\> | Yes | — | Sorted points at which to split into buckets. |
|
|
25
|
+
| `exclude_boundaries` | BOOL | No | `FALSE` | If `TRUE`, drops the implicit lower (`-inf`) and upper (`+inf`) overflow buckets so only interior bins remain. |
|
|
26
|
+
| `output_format` | STRING | No | `"bucket_names"` | `"bucket_names"` → `bin_<i>` (index starts at 1); `"bucket_ranges"` → `[lower, upper)`; `"bucket_ranges_json"` → `{"start":"..","end":".."}`. |
|
|
27
|
+
|
|
28
|
+
**Outputs:**
|
|
29
|
+
|
|
30
|
+
| Column | Type | Description |
|
|
31
|
+
|--------|------|-------------|
|
|
32
|
+
| (scalar result) | STRING | Bucket label, e.g. `bin_3` or `[2, 3)` depending on `output_format`. |
|
|
33
|
+
|
|
34
|
+
**Best practices:**
|
|
35
|
+
- Generate boundaries dynamically with `GENERATE_ARRAY(start, end, step)` for evenly spaced bins.
|
|
36
|
+
- Place inside `TRANSFORM` so the bin definition travels with the model to serving/export.
|
|
37
|
+
- Use `exclude_boundaries = TRUE` to suppress overflow buckets when out-of-range values are not expected.
|
|
38
|
+
|
|
39
|
+
**Limitations:**
|
|
40
|
+
- Split points must be numeric and sorted; behavior with NULL `numerical_expression` returns NULL.
|
|
41
|
+
- Boundaries are fixed (no data-driven balancing) — for equal-frequency bins use `ML.QUANTILE_BUCKETIZE`.
|
|
42
|
+
- **GOTCHA, verified live — `exclude_boundaries=TRUE` does NOT null out-of-range values.** It's easy to misread "drops the implicit lower/upper overflow buckets" as "values outside the split-point range become NULL." What actually happens: the **outermost split points are dropped entirely**, merging the overflow bucket into its nearest interior neighbor. With split points `[10, 20, 30]`: default gives 4 bins `(-inf,10)` `[10,20)` `[20,30)` `[30,+inf)`; with `exclude_boundaries=TRUE` this becomes just 2 bins `(-inf,20)` `[20,+inf)` — the `10` and `30` split points disappear, leaving only `20` as the sole effective boundary. No value ever becomes NULL from this option alone.
|
|
43
|
+
|
|
44
|
+
**BigFrames API:** `bigframes.ml.preprocessing.KBinsDiscretizer` (strategy-dependent; not a 1:1 of explicit split points).
|
|
45
|
+
**Repo example (tested):** [`functions/bucketizing/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/bucketizing) — Example 1 runs all three `output_format` values against the same `[3000, 4000, 5000]` split points on `penguins.body_mass_g`; Example 2 is the `exclude_boundaries` clarification above, proven live with `[10, 20, 30]`; Example 5 embeds `ML.QUANTILE_BUCKETIZE` and `ML.HASH_BUCKETIZE` together in a real `LOGISTIC_REG` `TRANSFORM` (accuracy ~0.81).
|
|
46
|
+
|
|
47
|
+
---
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# `ML.CENTROIDS`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-lifecycle-functions.md#mlcentroids`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-lifecycle-functions.md#mlcentroids)
|
|
4
|
+
|
|
5
|
+
- **Description:** Returns the learned centroid (cluster center) coordinates of a trained `KMEANS` model — one row per feature per centroid, so you can inspect what each cluster "looks like."
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Profile/interpret clusters by comparing each centroid's feature values.
|
|
8
|
+
- Compare centroids across hyperparameter-tuning trials (one `trial_id` per tuned model).
|
|
9
|
+
- Feed centroid coordinates into downstream segmentation/labeling logic.
|
|
10
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-centroids
|
|
11
|
+
- **Type:** Table-valued function (model weights function).
|
|
12
|
+
- **Applies to models:** `KMEANS` only.
|
|
13
|
+
|
|
14
|
+
**Syntax:**
|
|
15
|
+
```sql
|
|
16
|
+
SELECT *
|
|
17
|
+
FROM ML.CENTROIDS(MODEL `PROJECT_ID.DATASET.MODEL_NAME`
|
|
18
|
+
[, STRUCT(standardize AS standardize)]);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Inputs:**
|
|
22
|
+
|
|
23
|
+
| Parameter | Type | Required | Default | Description |
|
|
24
|
+
|-----------|------|----------|---------|-------------|
|
|
25
|
+
| `MODEL` | model ref | Yes | — | A trained `KMEANS` model. |
|
|
26
|
+
| `standardize` | BOOL | No | `TRUE` | Whether to return centroid feature values in standardized (`TRUE`) or original (`FALSE`) space. |
|
|
27
|
+
|
|
28
|
+
**Outputs:**
|
|
29
|
+
|
|
30
|
+
| Column | Type | Description |
|
|
31
|
+
|--------|------|-------------|
|
|
32
|
+
| `centroid_id` | INT64 | The cluster (centroid) identifier. |
|
|
33
|
+
| `feature` | STRING | The feature/column name. |
|
|
34
|
+
| `numerical_value` | FLOAT64 | Centroid value for numeric features (else NULL). |
|
|
35
|
+
| `categorical_value` | ARRAY\<STRUCT\<category STRING, value FLOAT64\>\> | Centroid values for categorical (one-hot) features. |
|
|
36
|
+
| `trial_id` | INT64 | Present only for hyperparameter-tuned models; identifies the trial. |
|
|
37
|
+
|
|
38
|
+
**Best practices:** Use `standardize = FALSE` to read centroids in the original feature units when profiling clusters for business stakeholders.
|
|
39
|
+
**Limitations:** `KMEANS` only — not valid for PCA/autoencoder/MF or supervised models. Numeric vs. categorical features land in separate columns; `UNNEST(categorical_value)` to flatten one-hot categories.
|
|
40
|
+
**BigFrames API:** `bigframes.ml.cluster.KMeans().cluster_centers_` (centroid attribute).
|
|
41
|
+
**Repo example (tested):**
|
|
42
|
+
- `bigquery-ml/models/kmeans/kmeans.sql` (Example 4) — one row per (`centroid_id`, `feature`) `ORDER BY centroid_id, feature`, read as the interpretation step: the centroid with the highest body-mass and flipper-length coordinates is the large-species cluster. Because `KMEANS` is non-deterministic (Example 7), read the profile off the coordinates, not off a remembered `centroid_id`.
|
|
43
|
+
- `bigquery-ml/workflows/customer_segmentation/customer_segmentation.sql` (Step 3) — the same call on RFM features, feeding the aggregated segment profiles in Step 4.
|
|
44
|
+
- On a hyperparameter-tuned model the output also carries `trial_id`, so the row count multiplies by the number of trials (one row per feature x centroid x trial) — see `models/kmeans/kmeans.sql`'s tuning example for the tuned variant.
|
|
45
|
+
|
|
46
|
+
---
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `ML.CONFUSION_MATRIX`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-lifecycle-functions.md#mlconfusion_matrix`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-lifecycle-functions.md#mlconfusion_matrix)
|
|
4
|
+
|
|
5
|
+
- **Description:** Returns a confusion matrix for a trained classification model — rows of actual (expected) labels vs. counts of predicted labels — computed over evaluation/input data.
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Inspect per-class correct vs. incorrect predictions beyond a single accuracy number.
|
|
8
|
+
- Diagnose class imbalance and which classes a model confuses (multiclass).
|
|
9
|
+
- Validate the effect of a custom decision `threshold` on binary classifiers.
|
|
10
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-confusion
|
|
11
|
+
- **Type:** Table-valued function (TVF).
|
|
12
|
+
- **Applies to models:** Classification models only — `LOGISTIC_REG` (binary + multiclass), `BOOSTED_TREE_CLASSIFIER`, `RANDOM_FOREST_CLASSIFIER`, `DNN_CLASSIFIER`, `DNN_LINEAR_COMBINED_CLASSIFIER` (wide-and-deep), and `AUTOML_CLASSIFIER`. Does **not** support imported TensorFlow models, regression, clustering, MF, PCA, autoencoder, ARIMA_PLUS, or remote/LLM models.
|
|
13
|
+
|
|
14
|
+
**Syntax:**
|
|
15
|
+
```sql
|
|
16
|
+
ML.CONFUSION_MATRIX(
|
|
17
|
+
MODEL `PROJECT_ID.DATASET.MODEL_NAME`
|
|
18
|
+
[, { TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) }]
|
|
19
|
+
[, STRUCT([THRESHOLD AS threshold] [, TRIAL_ID AS trial_id])]
|
|
20
|
+
)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Inputs:**
|
|
24
|
+
|
|
25
|
+
| Parameter | Type | Required | Default | Description |
|
|
26
|
+
|-----------|------|----------|---------|-------------|
|
|
27
|
+
| `MODEL` | model ref | Yes | — | A trained classification model. |
|
|
28
|
+
| `TABLE` / `QUERY_STATEMENT` | table or query | No\* | eval/training split | Input data whose columns match the model's features plus the label column. If omitted, uses the held-out eval split (or the full training data if no split). \*Required for some models, and required if you set `threshold`. |
|
|
29
|
+
| `threshold` | FLOAT64 (in STRUCT) | No | 0.5 | Custom positive-class cutoff. **Binary only** — error if used on a multiclass model. Requires TABLE/QUERY also be supplied. |
|
|
30
|
+
| `trial_id` | INT64 (in STRUCT) | No | optimal trial | Select a specific hyperparameter-tuning trial; defaults to the optimal trial. |
|
|
31
|
+
|
|
32
|
+
**Outputs:**
|
|
33
|
+
|
|
34
|
+
| Column | Type | Description |
|
|
35
|
+
|--------|------|-------------|
|
|
36
|
+
| `expected_label` | (label type) | Actual label value; one row per class. Exact value/type as passed in the label column. |
|
|
37
|
+
| \<one column per class\> | INT64 | Count of rows with that actual label predicted as this class. Column name is the class label (if it conforms to BigQuery column-naming rules). |
|
|
38
|
+
|
|
39
|
+
**Best practices:**
|
|
40
|
+
- Call without input args right after training to use the held-out eval split; pass your own TABLE for an independent test set.
|
|
41
|
+
- For binary models, sweep `threshold` (e.g. 0.3 / 0.5 / 0.7) to see precision/recall trade-offs as integer counts.
|
|
42
|
+
- Pair with `ML.EVALUATE` (scalar metrics) and `ML.ROC_CURVE` (threshold curve) for a complete classification picture.
|
|
43
|
+
|
|
44
|
+
**Limitations:**
|
|
45
|
+
- Classification models only; no regression/clustering/imported-TF.
|
|
46
|
+
- `threshold` is binary-only and requires explicit input data.
|
|
47
|
+
- Column names derive from class labels; labels not matching column-naming rules get sanitized names.
|
|
48
|
+
|
|
49
|
+
**BigFrames API:** `model.confusion_matrix(X, y)` on a `bigframes.ml` classifier (e.g. `LogisticRegression`, `XGBoostClassifier`).
|
|
50
|
+
**Repo example (tested):**
|
|
51
|
+
- `bigquery-ml/models/logistic_regression/logistic_regression.sql` (Example 3) — `SELECT * FROM ML.CONFUSION_MATRIX(MODEL ...)` on the census income binary classifier.
|
|
52
|
+
- `bigquery-ml/models/boosted_tree_classifier/boosted_tree_classifier.sql` (Example 3) — the same call on a `BOOSTED_TREE_CLASSIFIER`; `models/random_forest_classifier/`, `models/dnn_classifier/`, `models/wide_and_deep_classifier/`, and `models/automl_classifier/` each carry it too, so the matrix is directly comparable across classifier types on one dataset.
|
|
53
|
+
- `bigquery-ml/workflows/churn_retention/churn_retention.sql` (Step 3) — uses the matrix to settle *which class* a metric describes: the `expected_label = true` row (FALSE=1997, TRUE=3059) confirms `ML.EVALUATE`'s `recall = 0.605` is recall on the churned class, not the retained one.
|
|
54
|
+
- `bigquery-ml/workflows/cross_validation/cross_validation.sql` — the motivating case for k-fold: a held-out eval split with only ~15 real fraud cases (TP=13, FN=2), where a metric estimated from 15 positives is exactly the high-variance situation cross-validation exists to quantify.
|
|
55
|
+
|
|
56
|
+
---
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# `ML.CONVERT_COLOR_SPACE`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mlconvert_color_space`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mlconvert_color_space)
|
|
4
|
+
|
|
5
|
+
- **Description:** Converts an RGB image to a different color space.
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Match the color space a vision model was trained on (e.g. grayscale or YIQ input).
|
|
8
|
+
- **documentation:** [ML.CONVERT_COLOR_SPACE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-convert-color-space)
|
|
9
|
+
- **Type:** Scalar (row-wise; no `OVER()`).
|
|
10
|
+
- **Applies to models:** Same as the family; consumes `ML.DECODE_IMAGE`/`ML.RESIZE_IMAGE` output (input must be RGB).
|
|
11
|
+
|
|
12
|
+
**Syntax:**
|
|
13
|
+
```sql
|
|
14
|
+
ML.CONVERT_COLOR_SPACE(rgb_image, target_color_space)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Inputs:**
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Required | Default | Description |
|
|
20
|
+
|-----------|------|----------|---------|-------------|
|
|
21
|
+
| `rgb_image` | STRUCT (RGB, from `ML.DECODE_IMAGE`/`ML.RESIZE_IMAGE`) | Yes | — | Image in RGB color space. Accepts **either** value type — `ARRAY<FLOAT64>` or the `ARRAY<INT64>` produced by `ML.CONVERT_IMAGE_TYPE`. |
|
|
22
|
+
| `target_color_space` | STRING | Yes | — | Target color space: `'HSV'`, `'YIQ'`, `'YUV'`, or `'GRAYSCALE'`. |
|
|
23
|
+
|
|
24
|
+
**Outputs:**
|
|
25
|
+
|
|
26
|
+
| Column | Type | Description |
|
|
27
|
+
|--------|------|-------------|
|
|
28
|
+
| (result) | STRUCT\<ARRAY\<INT64\> dimensions, ARRAY\<FLOAT64\> values\> | Image in the requested color space. Always `FLOAT64`, whichever value type went in. `'GRAYSCALE'` returns **1 channel**; the other three return 3. |
|
|
29
|
+
|
|
30
|
+
**Best practices:** Only convert when the model expects a non-RGB color space; input must be RGB.
|
|
31
|
+
**Limitations:**
|
|
32
|
+
- **Requires a reservation** — see the family gotcha above.
|
|
33
|
+
- **`'GRAYSCALE'` changes the channel count to 1** (verified: a 1×2 RGB image converts to `[1, 2, 1]`, two values). This is the reverse of `ML.DECODE_IMAGE`, which replicates a grayscale source *up* to 3 channels — so a decode-then-grayscale pipeline goes 1 → 3 → 1, and the channel count of a feature vector is set by the last function in the chain, not by the source image. `'HSV'`, `'YIQ'`, and `'YUV'` return 3 distinct channels.
|
|
34
|
+
- **`'GRAYSCALE'` and `'YIQ'`'s Y channel are two different lumas.** `'GRAYSCALE'` uses `[0.2989, 0.5870, 0.1140]` — the 4-decimal rounding `tf.image.rgb_to_grayscale` hardcodes. `'YIQ'`'s Y uses the true BT.601 `[0.299, 0.587, 0.114]`. On RGB `(200, 100, 50)` they give `0.48698039215686273` and `0.4870588235294117`, a gap of `0.02` of one 8-bit level. Invisible, and enough to break a bit-for-bit reproducibility check against a reimplementation — pick the right one deliberately.
|
|
35
|
+
- **`'HSV'`'s hue is on `[0, 1]`, not degrees.** `(200, 100, 50)` → hue `0.05555555555555555`, which is 20°/360. A threshold written in degrees is off by 360×.
|
|
36
|
+
- **Integer input is normalized, not misread.** `ML.CONVERT_COLOR_SPACE(ML.CONVERT_IMAGE_TYPE(img), 'HSV')` is bit-identical to the float path — it divides by 255 on the way in rather than treating a `200` as already-scaled.
|
|
37
|
+
- An unsupported target is rejected by name: `Color space LAB is not supported; error in ML.CONVERT_COLOR_SPACE expression`.
|
|
38
|
+
- Output-size/display gotcha as above.
|
|
39
|
+
**BigFrames API:** No direct equivalent.
|
|
40
|
+
**Repo example (tested):** [`functions/image/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/image) Step 5 — the channel-count change, the two lumas, the `[0, 1]` hue, integer normalization, and the rejected target; Step 7 diffs `'HSV'`/`'YIQ'`/`'YUV'` against TensorFlow.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
**Status:** All four are **GA**. **Reservation required: YES** — see the family gotcha at the top of this section; this is the one thing about them that no official page states. **Connection required:** No for the functions themselves; the *object table* over the image files needs a Cloud Resource Connection whose service account holds `roles/storage.objectViewer` on the bucket, and the vision model may need one too (see the model entry).
|
|
45
|
+
|
|
46
|
+
**TRANSFORM-clause behavior:** All four are exportable preprocessing functions usable inside `TRANSFORM`, so the decode/resize/type/color-space steps are stored with the model and re-applied automatically at `ML.PREDICT`. Because they are scalar (no `OVER()`), they nest directly and impose no analytic-window constraints — unlike the analytic scalers/encoders/text functions documented in this folder.
|
|
47
|
+
|
|
48
|
+
**Typical pipeline:** object table (`data` BYTES) → `ML.DECODE_IMAGE` → `ML.RESIZE_IMAGE` → `ML.CONVERT_COLOR_SPACE` → `ML.CONVERT_IMAGE_TYPE` → vision model via `ML.PREDICT` (or all of it inside `TRANSFORM`). **The order is not arbitrary:** `ML.CONVERT_IMAGE_TYPE` is one-way and has no integer→float signature, and `ML.RESIZE_IMAGE` is type-preserving, so converting early quantizes at every later resize. Convert last.
|
|
49
|
+
|
|
50
|
+
**Sources:** [ML.DECODE_IMAGE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-decode-image) · [ML.RESIZE_IMAGE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-resize-image) · [ML.CONVERT_IMAGE_TYPE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-convert-image-type) · [ML.CONVERT_COLOR_SPACE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-convert-color-space) · [Run inference on image object tables](https://cloud.google.com/bigquery/docs/object-table-inference)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
---
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# `ML.CONVERT_IMAGE_TYPE`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mlconvert_image_type`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mlconvert_image_type)
|
|
4
|
+
|
|
5
|
+
- **Description:** Converts the floating-point pixel values produced by `ML.DECODE_IMAGE` into integers on the **closed** range `[0, 255]`, as required by some models.
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Feed integer-input vision models (e.g. SSD MobileNet V2, which expects `tf.uint8`).
|
|
8
|
+
- **documentation:** [ML.CONVERT_IMAGE_TYPE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-convert-image-type)
|
|
9
|
+
- **Type:** Scalar (row-wise; no `OVER()`).
|
|
10
|
+
- **Applies to models:** Same as the family; consumes `ML.DECODE_IMAGE` (or other image-function) output.
|
|
11
|
+
|
|
12
|
+
**Syntax:**
|
|
13
|
+
```sql
|
|
14
|
+
ML.CONVERT_IMAGE_TYPE(decoded_image)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Inputs:**
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Required | Default | Description |
|
|
20
|
+
|-----------|------|----------|---------|-------------|
|
|
21
|
+
| `decoded_image` | STRUCT with `ARRAY<FLOAT64> values` | Yes | — | Image whose float pixel values are converted to integers on `[0, 255]`. **Only the float form is accepted** — see below. |
|
|
22
|
+
|
|
23
|
+
**Outputs:**
|
|
24
|
+
|
|
25
|
+
| Column | Type | Description |
|
|
26
|
+
|--------|------|-------------|
|
|
27
|
+
| (result) | STRUCT\<ARRAY\<INT64\> dimensions, ARRAY\<INT64\> values\> | Image with integer pixel values. |
|
|
28
|
+
|
|
29
|
+
**Best practices:** Apply only when the target model requires integer pixels; leave float output for models trained on `[0,1]` floats. Make it the **last** step of the pipeline — `ML.RESIZE_IMAGE` is type-preserving and will re-quantize integers at every subsequent resize.
|
|
30
|
+
**Limitations:**
|
|
31
|
+
- **Requires a reservation** — see the family gotcha above.
|
|
32
|
+
- **It is one-way.** There is no inverse and no overload for integer input; feeding it its own output fails with `No matching signature for function ML.CONVERT_IMAGE_TYPE / Argument types: STRUCT<dimensions ARRAY<INT64>, values ARRAY<INT64>> / Signature: ML.CONVERT_IMAGE_TYPE(STRUCT<dimensions ARRAY<INT64>, values ARRAY<FLOAT64>>)`. (That error is also the authoritative statement of the struct's field names.)
|
|
33
|
+
- The documented range `[0, 255)` is **wrong at the top end** — a pure-white pixel returns exactly `255` (verified). The interval is closed.
|
|
34
|
+
- Matches `tf.image.convert_image_dtype(..., tf.uint8)` exactly (verified against TensorFlow 2.21.0).
|
|
35
|
+
- Output-size/display gotcha as above.
|
|
36
|
+
**BigFrames API:** No direct equivalent.
|
|
37
|
+
**Repo example (tested):** [`functions/image/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/image) Steps 3–4 — the closed range, the one-way signature error, and the pipeline-ordering consequence; Step 8 ends its feature pipeline with it.
|
|
38
|
+
|
|
39
|
+
---
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# `ML.CORRELATION`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mlcorrelation`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mlcorrelation)
|
|
4
|
+
|
|
5
|
+
- **Description:** Computes the correlation between one target column and one or more numeric correlation columns, optionally sliced by dimension columns. Three methods: `PEARSON`, `SPEARMAN`, `KENDALL`. With `dimension_cols`, the output is a full `GROUP BY CUBE` over those dimensions. **Preview.**
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Rank candidate features against a target before feature selection.
|
|
8
|
+
- Detect **Simpson's-paradox-shaped** structure: the whole-table coefficient versus the same coefficient inside every segment, in one query.
|
|
9
|
+
- Compare linear (`PEARSON`) against monotone (`SPEARMAN`) association to find non-linear-but-ordered relationships.
|
|
10
|
+
- Produce a correlation matrix over a wide table without writing one `CORR()` per pair.
|
|
11
|
+
- **documentation:** https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-correlation
|
|
12
|
+
- **Type:** Table-valued function. One row per (correlation column × cube cell).
|
|
13
|
+
- **Applies to models:** None — model-free utility.
|
|
14
|
+
|
|
15
|
+
**Syntax:**
|
|
16
|
+
```sql
|
|
17
|
+
ML.CORRELATION(
|
|
18
|
+
{ TABLE `PROJECT_ID.DATASET.TABLE_NAME` | (QUERY_STATEMENT) },
|
|
19
|
+
target_col => 'target',
|
|
20
|
+
target_correlation_cols => 'metric' | ['metric_1', 'metric_2', ...]
|
|
21
|
+
[, dimension_cols => 'dim' | ['dim_1', 'dim_2', ...] ]
|
|
22
|
+
[, method => 'PEARSON' | 'SPEARMAN' | 'KENDALL' ]
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Inputs:**
|
|
27
|
+
|
|
28
|
+
| Parameter | Type | Required | Default | Description |
|
|
29
|
+
|-----------|------|----------|---------|-------------|
|
|
30
|
+
| input data | `TABLE` reference or `(QUERY_STATEMENT)` | Yes | — | Data to correlate. |
|
|
31
|
+
| `target_col` | `STRING` | Yes | — | Name of the numeric target column. |
|
|
32
|
+
| `target_correlation_cols` | `STRING` or `ARRAY<STRING>` | Yes | — | Numeric column(s) to correlate against the target. |
|
|
33
|
+
| `dimension_cols` | `STRING` or `ARRAY<STRING>` | No | none | Groupable column(s) to slice by. **Maximum 12.** |
|
|
34
|
+
| `method` | `STRING` | No | `'PEARSON'` | `'PEARSON'`, `'SPEARMAN'`, or `'KENDALL'`. |
|
|
35
|
+
|
|
36
|
+
**Outputs:**
|
|
37
|
+
|
|
38
|
+
| Column | Type | Description |
|
|
39
|
+
|--------|------|-------------|
|
|
40
|
+
| `target_col` | `STRING` | Echo of the target column name. |
|
|
41
|
+
| `corr_col` | `STRING` | Which correlation column this row is for. |
|
|
42
|
+
| `correlation` | `FLOAT64` | The coefficient. `NULL` for degenerate segments (a single row) — those rows are **not** dropped. |
|
|
43
|
+
| `segment_size` | `INT64` | Rows in the segment. **Not** the pairwise *n* the coefficient used. |
|
|
44
|
+
| `segment_proportion` | `FLOAT64` | `segment_size` as a fraction of the whole input. |
|
|
45
|
+
| `segment` | `ARRAY<STRUCT<dimension_col STRING, dimension_value JSON>>` | Which dimensions this row is *not* rolled up over, and their values. Empty array on the global row. |
|
|
46
|
+
| one column per `dimension_cols` entry | source type | The dimension value, or `NULL` — for either of two reasons; see below. |
|
|
47
|
+
|
|
48
|
+
**Best practices:**
|
|
49
|
+
- **Round before comparing.** Never compare `correlation` across queries with `=`.
|
|
50
|
+
- **Use `segment` to disambiguate `NULL`.** A dimension column is `NULL` both when the row is a rollup over that dimension and when the segment *is* the genuine-`NULL` group. The rolled-up dimension is **absent** from `segment`; the genuine-`NULL` group is **present** in `segment` with `dimension_value` = JSON `null`. `NOT EXISTS (SELECT 1 FROM UNNEST(segment) s WHERE s.dimension_col = 'col')` is the rollup test.
|
|
51
|
+
- **Bucketize continuous columns before using them as dimensions** — see [`ML.QUANTILE_BUCKETIZE`](mlquantile_bucketize.md) and [`functions/bucketizing/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/bucketizing).
|
|
52
|
+
- **Filter by `segment_size`** to keep the cube readable, but treat it as an upper bound on evidence, not a sample size.
|
|
53
|
+
- Run [`ML.DESCRIBE_DATA`](mldescribe_data.md) first — it tells you the `NULL` rates that make `segment_size` misleading, and catches placeholder-encoded nulls before they become a segment.
|
|
54
|
+
|
|
55
|
+
**Limitations:**
|
|
56
|
+
- **Preview.**
|
|
57
|
+
- **`SPEARMAN` is not the textbook Spearman.** BigQuery computes it as `CORR()` over SQL `RANK()` — **competition (min) ranks**, where every tied observation gets the smallest rank in its group. SciPy, R, and pandas' default use **mid-ranks** (the average of the ranks the tie spans). On tied data the two disagree in the second decimal place: on `census_adult_income`, `education_num` vs `hours_per_week` reads `0.172612` from `ML.CORRELATION` and `0.167215` from `scipy.stats.spearmanr`. Reproduce BigQuery's number with `pandas.Series.rank(method='min')` or a pure-SQL `CORR()` over `RANK()`; on tie-free data all conventions agree. Not documented.
|
|
58
|
+
- **`KENDALL` *is* tie-corrected — it is tau-b.** So within one function, Kendall corrects for ties and Spearman does not. Matched against `scipy.stats.kendalltau(variant='b')` to floating-point noise; `variant='c'` does not match.
|
|
59
|
+
- **`KENDALL` is O(n²) and the constant is not small.** Measured on a synthetic table with the cache off, every doubling of rows multiplies slot time several-fold and the fitted exponent lands near 2, while `PEARSON` and `SPEARMAN` show no size dependence at all across the same range and return a million rows in about a second. A `KENDALL` on 100,000 rows of that shape did not finish inside 12 minutes. Sample or segment before using it.
|
|
60
|
+
- **Projecting the `segment` column changes `correlation`** in its last three digits, reproducibly, with the query cache off. Column pruning changes the physical plan, which changes the float summation order. Every projection that includes `segment` returns one value; every projection that omits it returns another. The gap lands in the sixteenth decimal place.
|
|
61
|
+
- **`PEARSON` matches `CORR()` but is not bit-identical** — agreement to ~15 significant digits, residual ~4e-16, float summation order again.
|
|
62
|
+
- **`segment_size` is the segment's row count, not the pairwise *n*.** Correlation is computed pairwise: for each correlation column, rows where either that column or the target is `NULL` are dropped. Two `corr_col` rows in the same segment can rest on different sample sizes and nothing in the output says so. `WHERE segment_size >= 30` does not guarantee 30 usable pairs.
|
|
63
|
+
- **`dimension_cols` accepts any groupable type, including `INT64`.** Passing a continuous numeric column silently produces one segment per distinct value (73 distinct ages → 74 output rows, no error).
|
|
64
|
+
- **Maximum 12 `dimension_cols`** — a 13th fails with an explicit error. Output row count is the full CUBE cell count, including degenerate single-row cells, so it grows fast: three dimensions on `census_adult_income` produce 134 rows.
|
|
65
|
+
|
|
66
|
+
**Related — three ways to correlate in BigQuery:**
|
|
67
|
+
|
|
68
|
+
| You want | Use | Notes |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| One pair, Pearson | `CORR(x, y)` | Aggregate function; matches `ML.CORRELATION` `PEARSON` to ~15 digits |
|
|
71
|
+
| One target vs many columns, optionally sliced | `ML.CORRELATION` | Three methods, CUBE slicing, one query |
|
|
72
|
+
| Which features *drive* an outcome, not just co-move | [`AI.KEY_DRIVERS`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ai/reference/augmented-analytics.md) / [`AI.CAUSAL_EFFECT`](aicausal_effect.md) | Correlation is symmetric and pairwise; these are neither |
|
|
73
|
+
|
|
74
|
+
**BigFrames API:** No wrapper. `bigframes.pandas.DataFrame.corr()` is a pandas-shaped equivalent compiled to BigQuery SQL — Pearson only, no dimension slicing, and a matrix rather than a target-vs-columns shape. Reach the SQL function via `bigframes.pandas.read_gbq`.
|
|
75
|
+
|
|
76
|
+
**Repo example (tested):** [`functions/exploration/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/exploration) — establishes `PEARSON` == `CORR()`, reproduces the `SPEARMAN` min-rank convention three ways (pandas, pure SQL, and a tie-free control), confirms `KENDALL` is tau-b against SciPy, measures the Kendall cost curve, matches the `dimension_cols` output row count against `GROUP BY CUBE` exactly, separates the two kinds of dimension `NULL`, and shows `segment_size` overstating the pairwise *n*.
|
|
77
|
+
|
|
78
|
+
---
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# `ML.DECODE_IMAGE`
|
|
2
|
+
|
|
3
|
+
> **Source:** [`bigquery-ml/reference/model-free-functions.md#mldecode_image`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/reference/model-free-functions.md#mldecode_image)
|
|
4
|
+
|
|
5
|
+
- **Description:** Converts image bytes into a multi-dimensional `STRUCT` of dimensions + pixel values that downstream image functions and vision models consume. This is the required entry point of the image pipeline. The argument is **any `BYTES` value** — an object table's `data` pseudocolumn is the usual source, but a `FROM_BASE64(...)` literal or a `BYTES` table column works identically (verified).
|
|
6
|
+
- **Use cases:**
|
|
7
|
+
- Decode JPEG/PNG/BMP bytes from an object table before inference with an imported/remote vision model.
|
|
8
|
+
- Produce a reusable decoded-image column to feed `ML.RESIZE_IMAGE` / `ML.CONVERT_*`.
|
|
9
|
+
- **documentation:** [ML.DECODE_IMAGE](https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-decode-image) · [Run inference on image object tables](https://cloud.google.com/bigquery/docs/object-table-inference)
|
|
10
|
+
- **Type:** Scalar (row-wise; no `OVER()`).
|
|
11
|
+
- **Applies to models:** Imported/remote vision models via `ML.PREDICT`, or any model's `TRANSFORM` that takes image input. Operates on object-table image bytes, not on a trained BQML model.
|
|
12
|
+
|
|
13
|
+
**Syntax:**
|
|
14
|
+
```sql
|
|
15
|
+
ML.DECODE_IMAGE(image_bytes)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Inputs:**
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Required | Default | Description |
|
|
21
|
+
|-----------|------|----------|---------|-------------|
|
|
22
|
+
| `image_bytes` | BYTES | Yes | — | Any `BYTES` value holding a JPEG/PNG/BMP image — typically an object table's `data` pseudocolumn. Must be `<= 10 MB`. |
|
|
23
|
+
|
|
24
|
+
**Outputs:**
|
|
25
|
+
|
|
26
|
+
| Column | Type | Description |
|
|
27
|
+
|--------|------|-------------|
|
|
28
|
+
| (result) | STRUCT\<ARRAY\<INT64\> dimensions, ARRAY\<FLOAT64\> values\> | Decoded image. `dimensions` is `[height, width, channels]`; `values` is `H × W × C` floats, **row-major HWC**, each `pixel / 255` on the **closed** interval `[0, 1]`. |
|
|
29
|
+
|
|
30
|
+
**Best practices:**
|
|
31
|
+
- When passing `ML.DECODE_IMAGE` output **directly** into `ML.PREDICT`, alias it with the model's expected input field name (e.g. `... AS input`).
|
|
32
|
+
- For repeated use, persist the decoded column to a table to avoid re-decoding.
|
|
33
|
+
**Limitations:**
|
|
34
|
+
- **Requires a reservation** — see the family gotcha above.
|
|
35
|
+
- **Channels is always 3.** Verified: an RGBA PNG comes back `[1, 2, 3]` with the alpha channel **dropped, not composited** (an `alpha = 128` pixel returns its raw RGB unchanged), and a single-channel grayscale PNG is **replicated into three identical channels**. There is no way to get 1 or 4 channels out of this function; do alpha compositing before the bytes reach BigQuery.
|
|
36
|
+
- The documented range `[0, 1)` is **wrong at the top end** — a pure-white pixel returns exactly `1.0` (verified). The interval is closed.
|
|
37
|
+
- Values are float64-exact: `values` matches `pixel / 255` computed in float64 with a maximum absolute difference of `0.0` (verified).
|
|
38
|
+
- Only JPEG, PNG, and BMP decode. Anything else — including a GIF, a WebP, or non-image bytes — fails with `Input image bytes could not be decoded. Expected valid image of type PNG, JPEG, or BMP; error in ML.DECODE_IMAGE expression`. `content_type` on an object table is upload-time metadata and is **not** validation; this error is the only real check.
|
|
39
|
+
- JPEG is lossy and is not close at small sizes: a 1×2 image of `(200,100,50),(0,128,255)` round-trips through JPEG as `(105,123,159),(86,104,140)` (Pillow's encoder at its default quality; a different encoder or quality gives different numbers, which is the point). PNG round-trips exactly. Use PNG for anything where pixel values matter.
|
|
40
|
+
- Large images can exceed editor display limits — write to a table.
|
|
41
|
+
**BigFrames API:** No direct equivalent (use SQL / object tables).
|
|
42
|
+
**Repo example (tested):** [`functions/image/`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/functions/image) — Steps 1–3 decode from `FROM_BASE64` literals and prove the field names, the channel rule, the closed range, the format list, and JPEG loss; Step 8 runs the object-table `data` path end to end.
|
|
43
|
+
|
|
44
|
+
---
|