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.
Files changed (286) hide show
  1. bigquery_data_science/__init__.py +58 -0
  2. bigquery_data_science/_skills/PLANS.md +76 -0
  3. bigquery_data_science/_skills/bigquery-ai/SKILL.md +66 -0
  4. bigquery_data_science/_skills/bigquery-ai/narrative/ai_agg.md +528 -0
  5. bigquery_data_science/_skills/bigquery-ai/narrative/ai_classify.md +450 -0
  6. bigquery_data_science/_skills/bigquery-ai/narrative/ai_count_tokens.md +180 -0
  7. bigquery_data_science/_skills/bigquery-ai/narrative/ai_detect_anomalies.md +322 -0
  8. bigquery_data_science/_skills/bigquery-ai/narrative/ai_embed.md +425 -0
  9. bigquery_data_science/_skills/bigquery-ai/narrative/ai_evaluate.md +368 -0
  10. bigquery_data_science/_skills/bigquery-ai/narrative/ai_forecast.md +437 -0
  11. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate.md +693 -0
  12. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_bool.md +248 -0
  13. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_double.md +254 -0
  14. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_embedding.md +402 -0
  15. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_int.md +252 -0
  16. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_table.md +447 -0
  17. bigquery_data_science/_skills/bigquery-ai/narrative/ai_generate_text.md +356 -0
  18. bigquery_data_science/_skills/bigquery-ai/narrative/ai_if.md +373 -0
  19. bigquery_data_science/_skills/bigquery-ai/narrative/ai_key_drivers.md +331 -0
  20. bigquery_data_science/_skills/bigquery-ai/narrative/ai_parse_document.md +416 -0
  21. bigquery_data_science/_skills/bigquery-ai/narrative/ai_predict.md +559 -0
  22. bigquery_data_science/_skills/bigquery-ai/narrative/ai_score.md +310 -0
  23. bigquery_data_science/_skills/bigquery-ai/narrative/ai_search.md +465 -0
  24. bigquery_data_science/_skills/bigquery-ai/narrative/ai_similarity.md +371 -0
  25. bigquery_data_science/_skills/bigquery-ai/narrative/catalog_search.md +951 -0
  26. bigquery_data_science/_skills/bigquery-ai/narrative/content_analysis.md +284 -0
  27. bigquery_data_science/_skills/bigquery-ai/narrative/content_moderation.md +369 -0
  28. bigquery_data_science/_skills/bigquery-ai/narrative/data_enrichment.md +426 -0
  29. bigquery_data_science/_skills/bigquery-ai/narrative/document_intelligence.md +470 -0
  30. bigquery_data_science/_skills/bigquery-ai/narrative/document_rag.md +453 -0
  31. bigquery_data_science/_skills/bigquery-ai/narrative/image_deduplication.md +770 -0
  32. bigquery_data_science/_skills/bigquery-ai/narrative/log_analysis.md +668 -0
  33. bigquery_data_science/_skills/bigquery-ai/narrative/metric_diagnostics.md +568 -0
  34. bigquery_data_science/_skills/bigquery-ai/narrative/ml_annotate_image.md +680 -0
  35. bigquery_data_science/_skills/bigquery-ai/narrative/ml_generate_embedding.md +217 -0
  36. bigquery_data_science/_skills/bigquery-ai/narrative/ml_generate_text.md +223 -0
  37. bigquery_data_science/_skills/bigquery-ai/narrative/ml_process_document.md +392 -0
  38. bigquery_data_science/_skills/bigquery-ai/narrative/ml_transcribe.md +815 -0
  39. bigquery_data_science/_skills/bigquery-ai/narrative/ml_translate.md +600 -0
  40. bigquery_data_science/_skills/bigquery-ai/narrative/ml_understand_text.md +673 -0
  41. bigquery_data_science/_skills/bigquery-ai/narrative/multimodal_analysis.md +266 -0
  42. bigquery_data_science/_skills/bigquery-ai/narrative/rag_pipeline.md +593 -0
  43. bigquery_data_science/_skills/bigquery-ai/narrative/semantic_search.md +510 -0
  44. bigquery_data_science/_skills/bigquery-ai/narrative/tabular_prediction.md +485 -0
  45. bigquery_data_science/_skills/bigquery-ai/narrative/time_series_intelligence.md +489 -0
  46. bigquery_data_science/_skills/bigquery-ai/narrative/vector_search.md +672 -0
  47. bigquery_data_science/_skills/bigquery-ai/reference/augmented-analytics.md +77 -0
  48. bigquery_data_science/_skills/bigquery-ai/reference/cloud-ai-service-models.md +88 -0
  49. bigquery_data_science/_skills/bigquery-ai/reference/document-processing.md +95 -0
  50. bigquery_data_science/_skills/bigquery-ai/reference/embeddings-and-search.md +166 -0
  51. bigquery_data_science/_skills/bigquery-ai/reference/general-purpose-generation.md +87 -0
  52. bigquery_data_science/_skills/bigquery-ai/reference/managed-functions.md +72 -0
  53. bigquery_data_science/_skills/bigquery-ai/reference/predictive-ai.md +113 -0
  54. bigquery_data_science/_skills/bigquery-ai/reference/workflows.md +56 -0
  55. bigquery_data_science/_skills/bigquery-ai/skill.manifest.json +109 -0
  56. bigquery_data_science/_skills/bigquery-ai/syntax/INDEX.md +71 -0
  57. bigquery_data_science/_skills/bigquery-ai/syntax/aiagg.md +67 -0
  58. bigquery_data_science/_skills/bigquery-ai/syntax/aicausal_effect-covered-in-bigquery-ml.md +17 -0
  59. bigquery_data_science/_skills/bigquery-ai/syntax/aiclassify.md +72 -0
  60. bigquery_data_science/_skills/bigquery-ai/syntax/aicount_tokens.md +53 -0
  61. bigquery_data_science/_skills/bigquery-ai/syntax/aidetect_anomalies.md +63 -0
  62. bigquery_data_science/_skills/bigquery-ai/syntax/aiembed.md +85 -0
  63. bigquery_data_science/_skills/bigquery-ai/syntax/aievaluate.md +114 -0
  64. bigquery_data_science/_skills/bigquery-ai/syntax/aiforecast.md +123 -0
  65. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate.md +69 -0
  66. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_bool.md +53 -0
  67. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_double.md +45 -0
  68. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_embedding.md +108 -0
  69. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_int.md +45 -0
  70. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_table.md +64 -0
  71. bigquery_data_science/_skills/bigquery-ai/syntax/aigenerate_text.md +167 -0
  72. bigquery_data_science/_skills/bigquery-ai/syntax/aiif.md +56 -0
  73. bigquery_data_science/_skills/bigquery-ai/syntax/aikey_drivers.md +76 -0
  74. bigquery_data_science/_skills/bigquery-ai/syntax/aiparse_document.md +91 -0
  75. bigquery_data_science/_skills/bigquery-ai/syntax/aipredict.md +74 -0
  76. bigquery_data_science/_skills/bigquery-ai/syntax/aiscore.md +52 -0
  77. bigquery_data_science/_skills/bigquery-ai/syntax/aisearch.md +66 -0
  78. bigquery_data_science/_skills/bigquery-ai/syntax/aisimilarity.md +79 -0
  79. bigquery_data_science/_skills/bigquery-ai/syntax/choosing-between-these-and-the-ai-functions.md +11 -0
  80. bigquery_data_science/_skills/bigquery-ai/syntax/hybrid-search-capability.md +165 -0
  81. bigquery_data_science/_skills/bigquery-ai/syntax/mlannotate_image.md +24 -0
  82. bigquery_data_science/_skills/bigquery-ai/syntax/mlgenerate_embedding.md +34 -0
  83. bigquery_data_science/_skills/bigquery-ai/syntax/mlgenerate_text.md +65 -0
  84. bigquery_data_science/_skills/bigquery-ai/syntax/mlprocess_document.md +125 -0
  85. bigquery_data_science/_skills/bigquery-ai/syntax/mltranscribe.md +26 -0
  86. bigquery_data_science/_skills/bigquery-ai/syntax/mltranslate.md +27 -0
  87. bigquery_data_science/_skills/bigquery-ai/syntax/mlunderstand_text.md +32 -0
  88. bigquery_data_science/_skills/bigquery-ai/syntax/multimodal-input-patterns-by-function.md +128 -0
  89. bigquery_data_science/_skills/bigquery-ai/syntax/object-tables.md +109 -0
  90. bigquery_data_science/_skills/bigquery-ai/syntax/objectref-and-objectrefruntime-schema-reference.md +50 -0
  91. bigquery_data_science/_skills/bigquery-ai/syntax/objfetch_metadata.md +49 -0
  92. bigquery_data_science/_skills/bigquery-ai/syntax/objget_access_url.md +66 -0
  93. bigquery_data_science/_skills/bigquery-ai/syntax/objget_read_url.md +40 -0
  94. bigquery_data_science/_skills/bigquery-ai/syntax/objlist.md +34 -0
  95. bigquery_data_science/_skills/bigquery-ai/syntax/objmake_ref.md +58 -0
  96. bigquery_data_science/_skills/bigquery-ai/syntax/per-row-failures-and-the-retry-pattern.md +19 -0
  97. bigquery_data_science/_skills/bigquery-ai/syntax/setup-apis-connection-roles.md +39 -0
  98. bigquery_data_science/_skills/bigquery-ai/syntax/two-input-shapes.md +22 -0
  99. bigquery_data_science/_skills/bigquery-ai/syntax/vector_search.md +78 -0
  100. bigquery_data_science/_skills/bigquery-ai/syntax/what-the-five-have-in-common.md +27 -0
  101. bigquery_data_science/_skills/bigquery-data-science/SKILL.md +69 -0
  102. bigquery_data_science/_skills/bigquery-data-science/reference/namespace-matrix.md +112 -0
  103. bigquery_data_science/_skills/bigquery-data-science/skill.manifest.json +13 -0
  104. bigquery_data_science/_skills/bigquery-ml/SKILL.md +70 -0
  105. bigquery_data_science/_skills/bigquery-ml/narrative/airflow_with_kfp.md +379 -0
  106. bigquery_data_science/_skills/bigquery-ml/narrative/anomaly_fraud_detection.md +195 -0
  107. bigquery_data_science/_skills/bigquery-ml/narrative/arima_plus.md +635 -0
  108. bigquery_data_science/_skills/bigquery-ml/narrative/arima_plus_xreg.md +453 -0
  109. bigquery_data_science/_skills/bigquery-ml/narrative/autoencoder.md +470 -0
  110. bigquery_data_science/_skills/bigquery-ml/narrative/automl_classifier.md +291 -0
  111. bigquery_data_science/_skills/bigquery-ml/narrative/automl_regressor.md +274 -0
  112. bigquery_data_science/_skills/bigquery-ml/narrative/boosted_tree_classifier.md +449 -0
  113. bigquery_data_science/_skills/bigquery-ml/narrative/boosted_tree_regressor.md +400 -0
  114. bigquery_data_science/_skills/bigquery-ml/narrative/bucketizing.md +201 -0
  115. bigquery_data_science/_skills/bigquery-ml/narrative/causal_effect.md +773 -0
  116. bigquery_data_science/_skills/bigquery-ml/narrative/churn_retention.md +271 -0
  117. bigquery_data_science/_skills/bigquery-ml/narrative/cloud_workflows.md +370 -0
  118. bigquery_data_science/_skills/bigquery-ml/narrative/composer_airflow.md +475 -0
  119. bigquery_data_science/_skills/bigquery-ml/narrative/contribution_analysis.md +346 -0
  120. bigquery_data_science/_skills/bigquery-ml/narrative/cross_validation.md +185 -0
  121. bigquery_data_science/_skills/bigquery-ml/narrative/customer_segmentation.md +233 -0
  122. bigquery_data_science/_skills/bigquery-ml/narrative/dataform.md +372 -0
  123. bigquery_data_science/_skills/bigquery-ml/narrative/dbt.md +283 -0
  124. bigquery_data_science/_skills/bigquery-ml/narrative/difference_in_differences.md +280 -0
  125. bigquery_data_science/_skills/bigquery-ml/narrative/distance.md +195 -0
  126. bigquery_data_science/_skills/bigquery-ml/narrative/dnn_classifier.md +326 -0
  127. bigquery_data_science/_skills/bigquery-ml/narrative/dnn_regressor.md +308 -0
  128. bigquery_data_science/_skills/bigquery-ml/narrative/embeddings_classification.md +426 -0
  129. bigquery_data_science/_skills/bigquery-ml/narrative/encoding.md +238 -0
  130. bigquery_data_science/_skills/bigquery-ml/narrative/ensembling.md +278 -0
  131. bigquery_data_science/_skills/bigquery-ml/narrative/evaluation.md +445 -0
  132. bigquery_data_science/_skills/bigquery-ml/narrative/exploration.md +779 -0
  133. bigquery_data_science/_skills/bigquery-ml/narrative/export.md +321 -0
  134. bigquery_data_science/_skills/bigquery-ml/narrative/feature_engineering.md +280 -0
  135. bigquery_data_science/_skills/bigquery-ml/narrative/feature_store.md +652 -0
  136. bigquery_data_science/_skills/bigquery-ml/narrative/feature_store_workflow.md +426 -0
  137. bigquery_data_science/_skills/bigquery-ml/narrative/ga4_churn_prediction.md +285 -0
  138. bigquery_data_science/_skills/bigquery-ml/narrative/hierarchical_forecasting.md +441 -0
  139. bigquery_data_science/_skills/bigquery-ml/narrative/image.md +791 -0
  140. bigquery_data_science/_skills/bigquery-ml/narrative/imported.md +426 -0
  141. bigquery_data_science/_skills/bigquery-ml/narrative/kmeans.md +348 -0
  142. bigquery_data_science/_skills/bigquery-ml/narrative/linear_regression.md +372 -0
  143. bigquery_data_science/_skills/bigquery-ml/narrative/logistic_regression.md +390 -0
  144. bigquery_data_science/_skills/bigquery-ml/narrative/matrix_factorization.md +404 -0
  145. bigquery_data_science/_skills/bigquery-ml/narrative/model_monitoring.md +609 -0
  146. bigquery_data_science/_skills/bigquery-ml/narrative/pca.md +357 -0
  147. bigquery_data_science/_skills/bigquery-ml/narrative/price_elasticity_dml.md +286 -0
  148. bigquery_data_science/_skills/bigquery-ml/narrative/propensity_score_matching.md +350 -0
  149. bigquery_data_science/_skills/bigquery-ml/narrative/random_forest_classifier.md +445 -0
  150. bigquery_data_science/_skills/bigquery-ml/narrative/random_forest_regressor.md +409 -0
  151. bigquery_data_science/_skills/bigquery-ml/narrative/recommendation.md +281 -0
  152. bigquery_data_science/_skills/bigquery-ml/narrative/regression_based_forecasting.md +491 -0
  153. bigquery_data_science/_skills/bigquery-ml/narrative/remote.md +428 -0
  154. bigquery_data_science/_skills/bigquery-ml/narrative/scalers.md +325 -0
  155. bigquery_data_science/_skills/bigquery-ml/narrative/scheduled_queries.md +284 -0
  156. bigquery_data_science/_skills/bigquery-ml/narrative/sql_scripting.md +243 -0
  157. bigquery_data_science/_skills/bigquery-ml/narrative/survival_analysis.md +363 -0
  158. bigquery_data_science/_skills/bigquery-ml/narrative/synthetic_control.md +221 -0
  159. bigquery_data_science/_skills/bigquery-ml/narrative/text.md +215 -0
  160. bigquery_data_science/_skills/bigquery-ml/narrative/time_series.md +669 -0
  161. bigquery_data_science/_skills/bigquery-ml/narrative/transform_only.md +273 -0
  162. bigquery_data_science/_skills/bigquery-ml/narrative/uplift_cate.md +241 -0
  163. bigquery_data_science/_skills/bigquery-ml/narrative/vertex_kfp.md +360 -0
  164. bigquery_data_science/_skills/bigquery-ml/narrative/wide_and_deep_classifier.md +316 -0
  165. bigquery_data_science/_skills/bigquery-ml/narrative/wide_and_deep_regressor.md +298 -0
  166. bigquery_data_science/_skills/bigquery-ml/reference/classification.md +80 -0
  167. bigquery_data_science/_skills/bigquery-ml/reference/model-management.md +90 -0
  168. bigquery_data_science/_skills/bigquery-ml/reference/preprocessing-functions.md +234 -0
  169. bigquery_data_science/_skills/bigquery-ml/reference/regression.md +79 -0
  170. bigquery_data_science/_skills/bigquery-ml/reference/unsupervised-and-specialized.md +101 -0
  171. bigquery_data_science/_skills/bigquery-ml/reference/workflows-and-pipelines.md +111 -0
  172. bigquery_data_science/_skills/bigquery-ml/skill.manifest.json +177 -0
  173. bigquery_data_science/_skills/bigquery-ml/syntax/1-model_type-catalog.md +28 -0
  174. bigquery_data_science/_skills/bigquery-ml/syntax/2-task-mlevaluate-metric-columns.md +26 -0
  175. bigquery_data_science/_skills/bigquery-ml/syntax/3-capability-matrix-per-model-type.md +21 -0
  176. bigquery_data_science/_skills/bigquery-ml/syntax/4-explainability-weights-functions.md +14 -0
  177. bigquery_data_science/_skills/bigquery-ml/syntax/5-connection-matrix.md +11 -0
  178. bigquery_data_science/_skills/bigquery-ml/syntax/6-which-model-free-function-no-create-model-no-connection.md +15 -0
  179. bigquery_data_science/_skills/bigquery-ml/syntax/7-point-in-time-feature-retrieval-which-of-the-two.md +11 -0
  180. bigquery_data_science/_skills/bigquery-ml/syntax/INDEX.md +111 -0
  181. bigquery_data_science/_skills/bigquery-ml/syntax/aicausal_effect.md +85 -0
  182. bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus-forecasting-lifecycle-functions.md +14 -0
  183. bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus-univariate-time-series-forecasting.md +132 -0
  184. bigquery_data_science/_skills/bigquery-ml/syntax/arima_plus_xreg-multivariate-time-series-with-external-regressors.md +103 -0
  185. bigquery_data_science/_skills/bigquery-ml/syntax/autoencoder.md +102 -0
  186. bigquery_data_science/_skills/bigquery-ml/syntax/automl_classifier-automl_regressor.md +88 -0
  187. bigquery_data_science/_skills/bigquery-ml/syntax/boosted_tree_classifier-boosted_tree_regressor.md +117 -0
  188. bigquery_data_science/_skills/bigquery-ml/syntax/contribution_analysis.md +113 -0
  189. bigquery_data_science/_skills/bigquery-ml/syntax/dnn_classifier-dnn_regressor.md +107 -0
  190. bigquery_data_science/_skills/bigquery-ml/syntax/dnn_linear_combined_classifier-dnn_linear_combined_regressor-wide-and-deep.md +98 -0
  191. bigquery_data_science/_skills/bigquery-ml/syntax/explainability-functions-mlexplain_predict-mlglobal_explain-mlfeature_importance.md +7 -0
  192. bigquery_data_science/_skills/bigquery-ml/syntax/exploratory-data-analysis-mldescribe_data-mlcorrelation.md +11 -0
  193. bigquery_data_science/_skills/bigquery-ml/syntax/export-model.md +92 -0
  194. bigquery_data_science/_skills/bigquery-ml/syntax/feature-engineering-standalone-preprocessing-functions.md +13 -0
  195. bigquery_data_science/_skills/bigquery-ml/syntax/image-preprocessing-functions-mldecode_image-mlresize_image-mlconvert_image_type-mlconvert_color_space.md +63 -0
  196. bigquery_data_science/_skills/bigquery-ml/syntax/imported-models-tensorflow-tensorflow_lite-onnx-xgboost.md +36 -0
  197. bigquery_data_science/_skills/bigquery-ml/syntax/kmeans.md +87 -0
  198. bigquery_data_science/_skills/bigquery-ml/syntax/linear_reg-logistic_reg-generalized-linear-models.md +101 -0
  199. bigquery_data_science/_skills/bigquery-ml/syntax/matrix_factorization.md +162 -0
  200. bigquery_data_science/_skills/bigquery-ml/syntax/mladvanced_weights.md +76 -0
  201. bigquery_data_science/_skills/bigquery-ml/syntax/mlarima_coefficients.md +30 -0
  202. bigquery_data_science/_skills/bigquery-ml/syntax/mlarima_evaluate.md +49 -0
  203. bigquery_data_science/_skills/bigquery-ml/syntax/mlbag_of_words.md +47 -0
  204. bigquery_data_science/_skills/bigquery-ml/syntax/mlbucketize.md +47 -0
  205. bigquery_data_science/_skills/bigquery-ml/syntax/mlcentroids.md +46 -0
  206. bigquery_data_science/_skills/bigquery-ml/syntax/mlconfusion_matrix.md +56 -0
  207. bigquery_data_science/_skills/bigquery-ml/syntax/mlconvert_color_space.md +53 -0
  208. bigquery_data_science/_skills/bigquery-ml/syntax/mlconvert_image_type.md +39 -0
  209. bigquery_data_science/_skills/bigquery-ml/syntax/mlcorrelation.md +78 -0
  210. bigquery_data_science/_skills/bigquery-ml/syntax/mldecode_image.md +44 -0
  211. bigquery_data_science/_skills/bigquery-ml/syntax/mldescribe_data.md +74 -0
  212. bigquery_data_science/_skills/bigquery-ml/syntax/mldetect_anomalies.md +86 -0
  213. bigquery_data_science/_skills/bigquery-ml/syntax/mldistance.md +48 -0
  214. bigquery_data_science/_skills/bigquery-ml/syntax/mlentity_features_at_time.md +56 -0
  215. bigquery_data_science/_skills/bigquery-ml/syntax/mlevaluate.md +72 -0
  216. bigquery_data_science/_skills/bigquery-ml/syntax/mlexplain_forecast.md +50 -0
  217. bigquery_data_science/_skills/bigquery-ml/syntax/mlexplain_predict.md +66 -0
  218. bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_cross.md +46 -0
  219. bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_importance.md +47 -0
  220. bigquery_data_science/_skills/bigquery-ml/syntax/mlfeature_info.md +50 -0
  221. bigquery_data_science/_skills/bigquery-ml/syntax/mlfeatures_at_time.md +51 -0
  222. bigquery_data_science/_skills/bigquery-ml/syntax/mlforecast.md +76 -0
  223. bigquery_data_science/_skills/bigquery-ml/syntax/mlgenerate_embedding-from-a-bqml-pca-autoencoder-matrix_factorization-model.md +64 -0
  224. bigquery_data_science/_skills/bigquery-ml/syntax/mlglobal_explain.md +63 -0
  225. bigquery_data_science/_skills/bigquery-ml/syntax/mlhash_bucketize.md +47 -0
  226. bigquery_data_science/_skills/bigquery-ml/syntax/mlholiday_info.md +46 -0
  227. bigquery_data_science/_skills/bigquery-ml/syntax/mlimputer.md +46 -0
  228. bigquery_data_science/_skills/bigquery-ml/syntax/mllp_norm.md +47 -0
  229. bigquery_data_science/_skills/bigquery-ml/syntax/mlmetrics.md +80 -0
  230. bigquery_data_science/_skills/bigquery-ml/syntax/mlngrams.md +37 -0
  231. bigquery_data_science/_skills/bigquery-ml/syntax/mlone_hot_encoder-mlmulti_hot_encoder-mllabel_encoder.md +67 -0
  232. bigquery_data_science/_skills/bigquery-ml/syntax/mlpolynomial_expand.md +47 -0
  233. bigquery_data_science/_skills/bigquery-ml/syntax/mlpredict.md +67 -0
  234. bigquery_data_science/_skills/bigquery-ml/syntax/mlprincipal_component_info.md +42 -0
  235. bigquery_data_science/_skills/bigquery-ml/syntax/mlprincipal_components.md +40 -0
  236. bigquery_data_science/_skills/bigquery-ml/syntax/mlquantile_bucketize.md +43 -0
  237. bigquery_data_science/_skills/bigquery-ml/syntax/mlrecommend.md +60 -0
  238. bigquery_data_science/_skills/bigquery-ml/syntax/mlreconstruction_loss.md +48 -0
  239. bigquery_data_science/_skills/bigquery-ml/syntax/mlresize_image.md +45 -0
  240. bigquery_data_science/_skills/bigquery-ml/syntax/mlroc_curve.md +63 -0
  241. bigquery_data_science/_skills/bigquery-ml/syntax/mltf_idf.md +37 -0
  242. bigquery_data_science/_skills/bigquery-ml/syntax/mltfdv_describe.md +34 -0
  243. bigquery_data_science/_skills/bigquery-ml/syntax/mltfdv_validate.md +48 -0
  244. bigquery_data_science/_skills/bigquery-ml/syntax/mltraining_info.md +78 -0
  245. bigquery_data_science/_skills/bigquery-ml/syntax/mltransform-applying-a-saved-transform.md +52 -0
  246. bigquery_data_science/_skills/bigquery-ml/syntax/mltranspose-not-a-function-pointer.md +32 -0
  247. bigquery_data_science/_skills/bigquery-ml/syntax/mltrial_info.md +60 -0
  248. bigquery_data_science/_skills/bigquery-ml/syntax/mlvalidate_data_drift.md +99 -0
  249. bigquery_data_science/_skills/bigquery-ml/syntax/mlvalidate_data_skew.md +50 -0
  250. bigquery_data_science/_skills/bigquery-ml/syntax/mlweights.md +84 -0
  251. bigquery_data_science/_skills/bigquery-ml/syntax/model-free-time-series-decomposition-mltrend-mlseasonality-mldetect_change_points.md +100 -0
  252. bigquery_data_science/_skills/bigquery-ml/syntax/model-introspection-mlfeature_info-mltraining_info-mltrial_info.md +7 -0
  253. bigquery_data_science/_skills/bigquery-ml/syntax/model-monitoring-data-validation.md +23 -0
  254. bigquery_data_science/_skills/bigquery-ml/syntax/numerical-scalers-mlstandard_scaler-mlmin_max_scaler-mlmax_abs_scaler-mlrobust_scaler-mlnormalizer.md +77 -0
  255. bigquery_data_science/_skills/bigquery-ml/syntax/onnx.md +55 -0
  256. bigquery_data_science/_skills/bigquery-ml/syntax/pca.md +91 -0
  257. bigquery_data_science/_skills/bigquery-ml/syntax/point-in-time-feature-retrieval-mlfeatures_at_time-mlentity_features_at_time.md +25 -0
  258. bigquery_data_science/_skills/bigquery-ml/syntax/quick-comparison.md +14 -0
  259. bigquery_data_science/_skills/bigquery-ml/syntax/random_forest_classifier-random_forest_regressor.md +123 -0
  260. bigquery_data_science/_skills/bigquery-ml/syntax/remote-remote-model-over-a-vertex-ai-endpoint-the-mechanism.md +87 -0
  261. bigquery_data_science/_skills/bigquery-ml/syntax/tensorflow.md +48 -0
  262. bigquery_data_science/_skills/bigquery-ml/syntax/tensorflow_lite.md +29 -0
  263. bigquery_data_science/_skills/bigquery-ml/syntax/text-preprocessing-functions-mlngrams-mltf_idf-mlbag_of_words.md +18 -0
  264. bigquery_data_science/_skills/bigquery-ml/syntax/timesfm-built-in-foundation-forecaster-see-bigquery-ai.md +28 -0
  265. bigquery_data_science/_skills/bigquery-ml/syntax/transform_only.md +91 -0
  266. bigquery_data_science/_skills/bigquery-ml/syntax/xgboost.md +72 -0
  267. bigquery_data_science/_skills/pinned-models.json +28 -0
  268. bigquery_data_science/catalog.py +1107 -0
  269. bigquery_data_science/cli.py +786 -0
  270. bigquery_data_science/installer.py +282 -0
  271. bigquery_data_science/mcp_server.py +317 -0
  272. bigquery_data_science/tooling/__init__.py +15 -0
  273. bigquery_data_science/tooling/convert_notebook.py +176 -0
  274. bigquery_data_science/tooling/link_policy.py +247 -0
  275. bigquery_data_science/tooling/manifest.py +152 -0
  276. bigquery_data_science/tooling/markdown_anchors.py +84 -0
  277. bigquery_data_science/tooling/narrative_drift.py +163 -0
  278. bigquery_data_science/tooling/pinned_models.py +216 -0
  279. bigquery_data_science/tooling/reference_structure.py +85 -0
  280. bigquery_data_science/tooling/sync_syntax.py +407 -0
  281. bigquery_data_science/tooling/validate.py +208 -0
  282. bigquery_data_science-0.7.0.dist-info/METADATA +306 -0
  283. bigquery_data_science-0.7.0.dist-info/RECORD +286 -0
  284. bigquery_data_science-0.7.0.dist-info/WHEEL +4 -0
  285. bigquery_data_science-0.7.0.dist-info/entry_points.txt +5 -0
  286. bigquery_data_science-0.7.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,426 @@
1
+ > **Source (`statmike/bigquery-data-science`):** **Notebook:** [`bigquery-ml/models/imported/imported.ipynb`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/models/imported/imported.ipynb) · **SQL:** [`bigquery-ml/models/imported/imported.sql`](https://github.com/statmike/bigquery-data-science/blob/main/bigquery-ml/models/imported/imported.sql)
2
+
3
+ # Imported Models — BigQuery ML
4
+
5
+ Bring a model trained **outside** BigQuery — TensorFlow, TensorFlow Lite, ONNX, or XGBoost — into BigQuery ML from Cloud Storage with `CREATE MODEL` (`model_type` = one of `TENSORFLOW` / `TENSORFLOW_LITE` / `ONNX` / `XGBOOST`) and run inference with `ML.PREDICT` **inside BigQuery compute**. This is the BigQuery ML Inference Engine: same SQL API, no Vertex AI endpoint to deploy, manage, or pay for.
6
+
7
+ **Lifecycle:** `CREATE MODEL` (with `MODEL_PATH` pointing at a GCS artifact) → `ML.PREDICT` → (`ML.FEATURE_IMPORTANCE`, XGBoost only)
8
+
9
+ **All four share one shape:**
10
+ ```sql
11
+ CREATE MODEL `PROJECT.DATASET.NAME`
12
+ OPTIONS(MODEL_TYPE = '...', MODEL_PATH = 'gs://bucket/path/*')
13
+ ```
14
+ — but they differ sharply in what's supported afterward. There's **no training, no `TRANSFORM`, no hyperparameter tuning, no `ML.EVALUATE`** for any of them: the model is frozen at import, and you supply inputs already in the format the model expects.
15
+
16
+ **When to use an imported model (vs. a `models/remote` (remote model)):**
17
+ - The model is small enough to fit BigQuery's size limits (250-450 MB depending on format) and needs no GPU.
18
+ - You want zero serving infrastructure — no endpoint to deploy or keep warm.
19
+ - Contrast with `models/remote` (`models/remote/`), where the model runs on an external Vertex AI endpoint of any size/framework, at the cost of needing that endpoint deployed and a connection configured.
20
+
21
+ **Data:** [`bigquery-public-data.ml_datasets.penguins`](https://console.cloud.google.com/marketplace/product/bigquery-public-datasets) — same 4 physical measurements used by `models/kmeans` (K-Means)/`models/pca` (PCA)/`models/transform_only` (Transform-Only), trained **locally** (outside BigQuery — that's the entire premise of "imported") with scikit-learn, XGBoost, and Keras, then imported and scored with `ML.PREDICT`.
22
+
23
+ **A verified, undocumented gotcha about the `XGBOOST` importer:** what it accepts is decided by the artifact's **file extension**, not by the library version that wrote it. A Booster saved by a current xgboost (3.x) imports without complaint as `model.json` or `model.ubj`, and is rejected as `model.bst` — even when the `.bst` and `.ubj` files are byte-for-byte identical. Save with a `.json`/`.ubj` extension and no version pin is needed anywhere in this notebook. Step 3 has the measurement.
24
+
25
+ **References:** `RESOURCES.md` (Full reference) | [Imported models journey](https://cloud.google.com/bigquery/docs/e2e-journey-import) | `setup` (Setup guide)
26
+
27
+ ---
28
+ ## Setup
29
+
30
+ Set your project and location, authenticate, and create a shared dataset for the model.
31
+
32
+ > Imported models need **no BigQuery connection** to read the GCS model file — BigQuery uses the credentials of whoever runs `CREATE MODEL` (a connection is only required for the unrelated case of serving against an *object table* under reservation pricing). But this notebook also does real **local training** (scikit-learn, XGBoost, Keras) to produce the artifacts to import, which is why Setup installs far more than the usual `google-cloud-bigquery`.
33
+
34
+ ```python
35
+ PROJECT_ID = 'statmike-mlops-349915' # <-- Replace with your project ID
36
+ LOCATION = 'US' # BigQuery dataset location
37
+ DATASET_ID = 'bq_ml' # Shared dataset across all bigquery-ml notebooks
38
+ BUCKET = 'statmike-mlops-349915' # <-- Replace with your GCS bucket (same location as DATASET_ID) -- used to stage each imported model's artifact
39
+ ```
40
+
41
+ ### Environment
42
+
43
+ > **Already set up the project environment?** The cell below is a no-op — packages are already in your kernel. See the `setup` (Setup Reference) for details.
44
+ >
45
+ > **Running standalone** (Colab, Colab Enterprise, Vertex AI Workbench)? The cell below installs required packages into your current kernel.
46
+ >
47
+ > **No version pins (see the gotcha above):** current `xgboost` is fine, because Step 3 saves the Booster with a `.json` extension. That in turn removes the `numpy<2` and `setuptools<81` pins this notebook used to need in order to run an old xgboost release.
48
+
49
+ > **This notebook shares a virtual environment with every other bigquery-ml notebook.** If another notebook's own `install()` cell runs at the same moment, the two concurrent writes to `site-packages` can corrupt a package mid-install. That surfaces later as a confusing `"No module named 'numpy.strings'"` (or `'numpy.rec'`) error buried deep inside an unrelated `sklearn`/`xgboost` import — not a real version incompatibility. The cell below catches that immediately, with an actionable message, instead of failing several cells later. **Avoid running this notebook's Setup at the same time as another bigquery-ml notebook's Setup** — if you hit the error below, wait for the other notebook's install to finish, then re-run this cell (and the one above it).
50
+
51
+ ```python
52
+ import numpy, scipy, sklearn, xgboost
53
+ from sklearn.linear_model import LogisticRegression # exercises the exact scipy import chain Step 2 needs
54
+
55
+ # No version assertions -- nothing here is pinned. This cell exists to fail
56
+ # fast and legibly if a concurrent install in the shared environment left
57
+ # site-packages half-written: the import chain above is exactly the one
58
+ # Step 2 and Step 3 depend on.
59
+ print(f'Environment OK -- numpy {numpy.__version__}, scipy {scipy.__version__}, xgboost {xgboost.__version__}')
60
+ ```
61
+
62
+ ```python
63
+ from google.cloud import bigquery, storage
64
+ import pandas as pd
65
+
66
+ client = bigquery.Client(project=PROJECT_ID)
67
+ gcs_client = storage.Client(project=PROJECT_ID)
68
+ gcs_bucket = gcs_client.bucket(BUCKET)
69
+ pd.set_option('display.max_colwidth', None)
70
+
71
+ # Create the shared dataset (idempotent)
72
+ dataset_ref = bigquery.DatasetReference(PROJECT_ID, DATASET_ID)
73
+ dataset = bigquery.Dataset(dataset_ref)
74
+ dataset.location = LOCATION
75
+ client.create_dataset(dataset, exists_ok=True)
76
+ print(f'Dataset {PROJECT_ID}.{DATASET_ID} ready')
77
+
78
+ # Register %%bigquery cell magic (auto-loaded in Colab, needed elsewhere)
79
+ %load_ext bigquery_magics
80
+ ```
81
+
82
+ ---
83
+ ## Step 1 — Pull the training data locally
84
+
85
+ Every format in this notebook is trained **outside** BigQuery, so the data has to leave BigQuery once, into a local pandas DataFrame — the opposite direction from every other notebook in this project.
86
+
87
+ ```python
88
+ import numpy as np
89
+
90
+ query = """
91
+ SELECT species, culmen_length_mm, culmen_depth_mm, flipper_length_mm, body_mass_g
92
+ FROM `bigquery-public-data.ml_datasets.penguins`
93
+ WHERE body_mass_g IS NOT NULL
94
+ AND culmen_length_mm IS NOT NULL
95
+ AND culmen_depth_mm IS NOT NULL
96
+ AND flipper_length_mm IS NOT NULL
97
+ """
98
+ df = client.query(query).to_dataframe()
99
+
100
+ feature_cols = ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g']
101
+ X = df[feature_cols].values.astype('float32')
102
+ species_classes = sorted(df['species'].unique())
103
+ y_multi = np.array([species_classes.index(s) for s in df['species']])
104
+ y_binary = (df['species'] == 'Adelie Penguin (Pygoscelis adeliae)').astype('float32').values
105
+
106
+ print(df.shape, dict(enumerate(species_classes)))
107
+ ```
108
+
109
+ ---
110
+ ## Step 2 — `ONNX`: import a scikit-learn model
111
+
112
+ Train a scikit-learn `LogisticRegression`, convert it to ONNX with `skl2onnx`, and fix the two version gotchas verified above (`ir_version=8`, `target_opset=13`) before uploading.
113
+
114
+ ```python
115
+ from sklearn.linear_model import LogisticRegression
116
+ from skl2onnx import convert_sklearn
117
+ from skl2onnx.common.data_types import FloatTensorType
118
+
119
+ clf = LogisticRegression(max_iter=1000)
120
+ clf.fit(X, y_multi)
121
+ print('sklearn train accuracy:', clf.score(X, y_multi))
122
+
123
+ # zipmap=False: without it, sklearn-onnx emits a "sequence of map" for
124
+ # probabilities that BigQuery ML's importer rejects outright.
125
+ onnx_model = convert_sklearn(
126
+ clf,
127
+ initial_types=[('input', FloatTensorType([None, 4]))],
128
+ options={id(clf): {'zipmap': False}},
129
+ target_opset=13, # ONNX Runtime 1.12 (BQML's engine) only guarantees support through opset 17
130
+ )
131
+ onnx_model.ir_version = 8 # ONNX Runtime 1.12 max supported IR version
132
+
133
+ with open('sklearn_logreg.onnx', 'wb') as f:
134
+ f.write(onnx_model.SerializeToString())
135
+ print('ONNX model written')
136
+ ```
137
+
138
+ ```python
139
+ blob = gcs_bucket.blob('bq_ml/imported/onnx/model.onnx')
140
+ blob.upload_from_filename('sklearn_logreg.onnx')
141
+ print(f'Uploaded to gs://{BUCKET}/bq_ml/imported/onnx/model.onnx')
142
+
143
+ query = f"""
144
+ CREATE OR REPLACE MODEL `{PROJECT_ID}.{DATASET_ID}.imported_onnx_penguins`
145
+ OPTIONS(
146
+ model_type = 'ONNX',
147
+ model_path = 'gs://{BUCKET}/bq_ml/imported/onnx/*'
148
+ )
149
+ """
150
+ client.query(query).result()
151
+ print('Model imported_onnx_penguins created')
152
+ ```
153
+
154
+ `ML.FEATURE_INFO` is **not** supported for ONNX (or any imported type) — verified: `"Model type ONNX is not supported by FEATURE_INFO."` Use the Python client (`client.get_model(...)`) to confirm the import succeeded instead.
155
+
156
+ ```python
157
+ query = f"""
158
+ SELECT species, label, probabilities
159
+ FROM ML.PREDICT(
160
+ MODEL `{PROJECT_ID}.{DATASET_ID}.imported_onnx_penguins`,
161
+ (SELECT species,
162
+ [CAST(culmen_length_mm AS FLOAT64), CAST(culmen_depth_mm AS FLOAT64),
163
+ CAST(flipper_length_mm AS FLOAT64), CAST(body_mass_g AS FLOAT64)] AS input
164
+ FROM `bigquery-public-data.ml_datasets.penguins`
165
+ WHERE body_mass_g IS NOT NULL LIMIT 5)
166
+ )
167
+ """
168
+ client.query(query).to_dataframe()
169
+ ```
170
+
171
+ ---
172
+ ## Step 3 — `XGBOOST`: import a native XGBoost Booster
173
+
174
+ XGBoost is BigQuery ML's **native** import format for this library — no conversion step, just `booster.save_model(...)`. Trained here as a **binary** classifier (predict "is this an Adelie penguin?") rather than the multiclass model used elsewhere in this notebook — verified live that a `multi:softprob` objective still predicts fine, but BigQuery ML silently returns an ARRAY of per-class probabilities even though `OUTPUT` declares a single `FLOAT64` field, which reads confusingly. A binary objective keeps the declared output type honest.
175
+
176
+ > **GOTCHA (verified, undocumented as of this writing):** BigQuery ML's XGBoost importer decides what it will accept from the artifact's **file extension**, not from the library version that wrote it. Saving the *same* Booster from current xgboost three ways and importing each:
177
+ >
178
+ > | Uploaded as | Result |
179
+ > |---|---|
180
+ > | `model.json` | Imports; `ML.PREDICT` and `ML.FEATURE_IMPORTANCE` both work |
181
+ > | `model.ubj` | Imports |
182
+ > | `model.bst` | Rejected: `Invalid XGBoost model: could not load model from file` — a JSON parse error at character position 1 |
183
+ >
184
+ > The `.bst` and `.ubj` uploads were **byte-identical** in that test — current xgboost writes UBJSON under either extension — so what differs is the name, not the contents. Save as `.json` (below) or `.ubj` and no version pin is needed. The reverse direction has the matching quirk: `models/export` (`EXPORT MODEL`) writes `model.bst` at the `xgboost_version = '0.9'` default and `model.ubj` at `'2.1'`.
185
+
186
+ ```python
187
+ import xgboost as xgb
188
+ print('xgboost version:', xgb.__version__) # unpinned -- the .json extension is what matters
189
+
190
+ dtrain = xgb.DMatrix(X, label=y_binary, feature_names=feature_cols)
191
+ params = {'objective': 'binary:logistic', 'max_depth': 3, 'eta': 0.3}
192
+ booster = xgb.train(params, dtrain, num_boost_round=50)
193
+
194
+ preds = booster.predict(dtrain)
195
+ train_acc = ((preds > 0.5).astype(int) == y_binary).mean()
196
+ print('xgboost train accuracy:', train_acc)
197
+
198
+ booster.save_model('xgb_penguins.json')
199
+ print('XGBoost model written')
200
+ ```
201
+
202
+ ```python
203
+ blob = gcs_bucket.blob('bq_ml/imported/xgboost/model.json')
204
+ blob.upload_from_filename('xgb_penguins.json')
205
+ print(f'Uploaded to gs://{BUCKET}/bq_ml/imported/xgboost/model.json')
206
+
207
+ # INPUT/OUTPUT is required here (the Booster file has feature_names but not
208
+ # feature_types) -- unlike ONNX/TensorFlow, which need neither.
209
+ query = f"""
210
+ CREATE OR REPLACE MODEL `{PROJECT_ID}.{DATASET_ID}.imported_xgboost_penguins`
211
+ INPUT(culmen_length_mm FLOAT64, culmen_depth_mm FLOAT64, flipper_length_mm FLOAT64, body_mass_g FLOAT64)
212
+ OUTPUT(is_adelie_prob FLOAT64)
213
+ OPTIONS(
214
+ model_type = 'XGBOOST',
215
+ model_path = 'gs://{BUCKET}/bq_ml/imported/xgboost/*'
216
+ )
217
+ """
218
+ client.query(query).result()
219
+ print('Model imported_xgboost_penguins created')
220
+ ```
221
+
222
+ ```python
223
+ query = f"""
224
+ SELECT species, is_adelie_prob
225
+ FROM ML.PREDICT(
226
+ MODEL `{PROJECT_ID}.{DATASET_ID}.imported_xgboost_penguins`,
227
+ (SELECT species, culmen_length_mm, culmen_depth_mm, flipper_length_mm, body_mass_g
228
+ FROM `bigquery-public-data.ml_datasets.penguins`
229
+ WHERE body_mass_g IS NOT NULL LIMIT 5)
230
+ )
231
+ """
232
+ client.query(query).to_dataframe()
233
+ ```
234
+
235
+ `XGBOOST` is the **only** imported type that supports `ML.FEATURE_IMPORTANCE` — unlike ONNX/TensorFlow/TensorFlow Lite, which support none of the introspection functions.
236
+
237
+ ```python
238
+ query = f"""
239
+ SELECT *
240
+ FROM ML.FEATURE_IMPORTANCE(MODEL `{PROJECT_ID}.{DATASET_ID}.imported_xgboost_penguins`)
241
+ """
242
+ client.query(query).to_dataframe()
243
+ ```
244
+
245
+ ---
246
+ ## Step 4 — `TENSORFLOW`: import a Keras SavedModel
247
+
248
+ A small Keras `Sequential` model with a `tf.keras.layers.Normalization` layer **baked in** (`.adapt()`-ed on the training data). Imported models support no `TRANSFORM`/preprocessing of their own, so any feature scaling the model needs must live inside the exported graph itself — this lets raw column values be fed directly at predict time, same as the trained data.
249
+
250
+ ```python
251
+ import tensorflow as tf
252
+
253
+ norm = tf.keras.layers.Normalization(axis=-1)
254
+ norm.adapt(X)
255
+
256
+ model = tf.keras.Sequential([
257
+ tf.keras.layers.Input(shape=(4,), name='input'),
258
+ norm,
259
+ tf.keras.layers.Dense(8, activation='relu'),
260
+ tf.keras.layers.Dense(3, activation='softmax'),
261
+ ])
262
+ model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
263
+ model.fit(X, y_multi, epochs=60, verbose=0)
264
+ loss, acc = model.evaluate(X, y_multi, verbose=0)
265
+ print('keras train accuracy (raw, unscaled features -- Normalization is baked in):', acc)
266
+
267
+ model.export('tf_savedmodel')
268
+ ```
269
+
270
+ ```python
271
+ import os
272
+
273
+ for root, _, files in os.walk('tf_savedmodel'):
274
+ for fname in files:
275
+ local_path = os.path.join(root, fname)
276
+ rel_path = os.path.relpath(local_path, 'tf_savedmodel')
277
+ blob = gcs_bucket.blob(f'bq_ml/imported/tensorflow/{rel_path}')
278
+ blob.upload_from_filename(local_path)
279
+ print(f'Uploaded SavedModel to gs://{BUCKET}/bq_ml/imported/tensorflow/')
280
+
281
+ query = f"""
282
+ CREATE OR REPLACE MODEL `{PROJECT_ID}.{DATASET_ID}.imported_tensorflow_penguins`
283
+ OPTIONS(
284
+ model_type = 'TENSORFLOW',
285
+ model_path = 'gs://{BUCKET}/bq_ml/imported/tensorflow/*'
286
+ )
287
+ """
288
+ client.query(query).result()
289
+ print('Model imported_tensorflow_penguins created')
290
+ ```
291
+
292
+ Input is a single `ARRAY<FLOAT64>` column matching the SavedModel's named input signature (`"input"`, shape `(-1, 4)`) — BigQuery maps it by name. The output column is auto-named `output_0` (the model's output tensor has no name).
293
+
294
+ ```python
295
+ query = f"""
296
+ SELECT species, output_0
297
+ FROM ML.PREDICT(
298
+ MODEL `{PROJECT_ID}.{DATASET_ID}.imported_tensorflow_penguins`,
299
+ (SELECT species,
300
+ [CAST(culmen_length_mm AS FLOAT64), CAST(culmen_depth_mm AS FLOAT64),
301
+ CAST(flipper_length_mm AS FLOAT64), CAST(body_mass_g AS FLOAT64)] AS input
302
+ FROM `bigquery-public-data.ml_datasets.penguins`
303
+ WHERE body_mass_g IS NOT NULL LIMIT 5)
304
+ )
305
+ """
306
+ client.query(query).to_dataframe()
307
+ ```
308
+
309
+ > **Correction to the docs (verified live):** the capability table cited in `RESOURCES.md` (sourced from official BigQuery ML documentation) lists `ML.EXPLAIN_PREDICT` as supported for `TENSORFLOW` imports. Calling it on this model returns `"TENSORFLOW model is unsupported in ml.explain_predict."` Not reproduced here — treat that specific cell as unverified/stale until confirmed against a model that does support it.
310
+
311
+ ---
312
+ ## Step 5 — `TENSORFLOW_LITE`: the same model, converted to `.tflite`
313
+
314
+ `tf.lite.TFLiteConverter.from_saved_model(...)` on the exact SavedModel from Step 4 — same graph, same baked-in `Normalization` layer, just a more compact serialized format.
315
+
316
+ ```python
317
+ converter = tf.lite.TFLiteConverter.from_saved_model('tf_savedmodel')
318
+ tflite_model = converter.convert()
319
+ with open('model.tflite', 'wb') as f:
320
+ f.write(tflite_model)
321
+ print(f'TFLite model written ({len(tflite_model)} bytes)')
322
+ ```
323
+
324
+ ```python
325
+ blob = gcs_bucket.blob('bq_ml/imported/tflite/model.tflite')
326
+ blob.upload_from_filename('model.tflite')
327
+ print(f'Uploaded to gs://{BUCKET}/bq_ml/imported/tflite/model.tflite')
328
+
329
+ query = f"""
330
+ CREATE OR REPLACE MODEL `{PROJECT_ID}.{DATASET_ID}.imported_tflite_penguins`
331
+ OPTIONS(
332
+ model_type = 'TENSORFLOW_LITE',
333
+ model_path = 'gs://{BUCKET}/bq_ml/imported/tflite/*'
334
+ )
335
+ """
336
+ client.query(query).result()
337
+ print('Model imported_tflite_penguins created')
338
+ ```
339
+
340
+ **Verified:** predictions match the `TENSORFLOW` import in Step 4 to about 7 significant figures — not bit-for-bit identical (they differ at the 7th-8th decimal place, ordinary float32 kernel differences between the TensorFlow runtime and the TFLite interpreter, since no quantization was applied during conversion) — same input contract (`ARRAY<FLOAT64>` named `"input"`), same `output_0` naming convention. Only `ML.PREDICT` is supported for this type — narrower than `TENSORFLOW`, which at least nominally lists `ML.EXPLAIN_PREDICT` (see the correction above).
341
+
342
+ ```python
343
+ query = f"""
344
+ SELECT species, output_0
345
+ FROM ML.PREDICT(
346
+ MODEL `{PROJECT_ID}.{DATASET_ID}.imported_tflite_penguins`,
347
+ (SELECT species,
348
+ [CAST(culmen_length_mm AS FLOAT64), CAST(culmen_depth_mm AS FLOAT64),
349
+ CAST(flipper_length_mm AS FLOAT64), CAST(body_mass_g AS FLOAT64)] AS input
350
+ FROM `bigquery-public-data.ml_datasets.penguins`
351
+ WHERE body_mass_g IS NOT NULL LIMIT 5)
352
+ )
353
+ """
354
+ client.query(query).to_dataframe()
355
+ ```
356
+
357
+ ---
358
+ ## Step 6 — Comparing the four formats
359
+
360
+ | | `ONNX` | `XGBOOST` | `TENSORFLOW` | `TENSORFLOW_LITE` |
361
+ |---|---|---|---|---|
362
+ | Trained with | scikit-learn → skl2onnx | xgboost (native) | Keras | Keras → TFLiteConverter |
363
+ | Size limit | 450 MB | 250 MB | 450 MB | 450 MB |
364
+ | `INPUT`/`OUTPUT` clause | Not needed | Required (unless `feature_names`+`feature_types` in file) | Not needed | Not needed |
365
+ | `ML.FEATURE_INFO` | No | No | No | No |
366
+ | `ML.FEATURE_IMPORTANCE` | No | **Yes (only one)** | No | No |
367
+ | `ML.EXPLAIN_PREDICT` | No | No | Documented, **not actually supported** (verified) | No |
368
+ | `ML.EVALUATE` / HP tuning / `TRANSFORM` | No | No | No | No |
369
+ | Version gotcha | IR version ≤ 8, opset ≤ ~17 | Save as `.json`/`.ubj`; a `.bst` upload is rejected | 450 MB / ~250 MB RAM limit | Only TF core + TF Text ops |
370
+
371
+ Every format shares the same bottom line: **no training-time BigQuery cost, no serving infrastructure, but a frozen model** with almost no introspection beyond `ML.PREDICT`.
372
+
373
+ ---
374
+ ## Related production content
375
+
376
+ This notebook stays focused on the `CREATE MODEL`/`ML.PREDICT` mechanics of each import format. For the full production picture — real-world model sizes, tokenization contracts, container-free serving tradeoffs — see:
377
+ - [MLOps/Serving/SQL Inference/BQML Import Model via ONNX.ipynb](https://github.com/statmike/vertex-ai-mlops/blob/main/MLOps/Serving/SQL%20Inference/BQML%20Import%20Model%20via%20ONNX.ipynb) — a HuggingFace PyTorch sentiment model converted to ONNX, with the 250 MB practical limit and pre-tokenized `ARRAY` inputs.
378
+ - [MLOps/Serving/SQL Inference/Serve TensorFlow SavedModel Format With BigQuery.ipynb](https://github.com/statmike/vertex-ai-mlops/blob/main/MLOps/Serving/SQL%20Inference/Serve%20TensorFlow%20SavedModel%20Format%20With%20BigQuery.ipynb) — importing a TensorFlow SavedModel at production scale.
379
+
380
+ ---
381
+ ## Examples — `%%bigquery` Magics
382
+
383
+ The same operations using IPython magic commands — write SQL directly in cells without Python string wrapping.
384
+
385
+ - `%%bigquery` — run SQL, display results inline
386
+ - `%%bigquery df` — run SQL, capture results into a pandas DataFrame
387
+
388
+ ```sql
389
+ %%bigquery --project {PROJECT_ID}
390
+
391
+ SELECT *
392
+ FROM ML.FEATURE_IMPORTANCE(MODEL `statmike-mlops-349915.bq_ml.imported_xgboost_penguins`)
393
+ ```
394
+
395
+ ---
396
+ ## Examples — BigFrames
397
+
398
+ `bigframes.ml.imported` has a dedicated wrapper class per format — `ONNXModel`, `TensorFlowModel`, `XGBoostModel` (no separate class for TensorFlow Lite). Each wraps the exact same `CREATE MODEL ... MODEL_PATH=...` mechanics shown above; `.predict()` maps to `ML.PREDICT`.
399
+
400
+ ```python
401
+ import bigframes.pandas as bpd
402
+ from bigframes.ml.imported import ONNXModel
403
+
404
+ bpd.close_session() # Reset session to apply project/location settings
405
+ bpd.options.bigquery.project = PROJECT_ID
406
+ bpd.options.bigquery.location = LOCATION
407
+ ```
408
+
409
+ ```python
410
+ bf_onnx_model = ONNXModel(model_path=f'gs://{BUCKET}/bq_ml/imported/onnx/*')
411
+
412
+ # Build the ARRAY<FLOAT64> input column in the SQL itself -- BigFrames'
413
+ # DataFrame.apply(axis=1) requires a registered BigQuery function for
414
+ # row-wise Python callables, so the array literal is constructed server-side.
415
+ bf_query = f"""
416
+ SELECT species,
417
+ [CAST(culmen_length_mm AS FLOAT64), CAST(culmen_depth_mm AS FLOAT64),
418
+ CAST(flipper_length_mm AS FLOAT64), CAST(body_mass_g AS FLOAT64)] AS input
419
+ FROM `bigquery-public-data.ml_datasets.penguins`
420
+ WHERE body_mass_g IS NOT NULL
421
+ LIMIT 5
422
+ """
423
+ bf_df = bpd.read_gbq(bf_query)
424
+
425
+ bf_onnx_model.predict(bf_df[['input']]).peek()
426
+ ```