demo: added batch prediction example

This commit is contained in:
Giorgio Conte 2023-03-06 10:16:21 +00:00
parent 406921c7d7
commit 0852ae3778
2 changed files with 22 additions and 4 deletions

View File

@ -17,7 +17,8 @@
"source": [
"import kfp\n",
"from google.cloud import aiplatform as aip\n",
"import google_cloud_pipeline_components.v1.bigquery as bqop"
"import google_cloud_pipeline_components.v1.bigquery as bqop\n",
"from google.cloud import bigquery"
]
},
{
@ -255,6 +256,23 @@
"\n",
"my_prediction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# batch prediction on BigQuery\n",
"\n",
"with open(\"sql/explain_predict.sql\") as file:\n",
" train_query = file.read()\n",
"\n",
"client = bigquery_client = bigquery.Client(location=LOCATION, project=PROJECT_ID)\n",
"batch_predictions = bigquery_client.query(train_query.format(project_id=PROJECT_ID, dataset=DATASET, model_name=f'{MODEL_NAME}-fraction-10')).to_dataframe()\n",
"\n",
"batch_predictions"
]
}
],
"metadata": {
@ -265,7 +283,7 @@
},
"language_info": {
"name": "python",
"version": "3.8.9"
"version": "3.10.9"
},
"orig_nbformat": 4,
"vscode": {

View File

@ -15,9 +15,9 @@
*/
SELECT *
FROM ML.EXPLAIN_PREDICT(MODEL `{project-id}.{dataset}.{model-name}`,
FROM ML.EXPLAIN_PREDICT(MODEL `{project_id}.{dataset}.{model-name}`,
(SELECT * EXCEPT (session_id, session_starting_ts, user_id, has_purchased)
FROM `{project-id}.{dataset}.ecommerce_abt`
FROM `{project_id}.{dataset}.ecommerce_abt`
WHERE extract(ISOYEAR FROM session_starting_ts) = 2023),
STRUCT(5 AS top_k_features, 0.5 AS threshold))
LIMIT 100