使用 sk-learn 模型进行大查询预测

Big-query predict using sk-learn model

我已经在我的本地机器上创建了一个 sklearn 模型。然后我将其上传到 google 存储空间。我使用相同的模型在 AI Platform 中创建了模型和版本。它正在为在线预测工作。现在我想执行批量预测并将数据存储到大查询中,例如每次执行预测时它都会更新大查询 table。

有人可以建议我怎么做吗?

人工智能平台暂时不支持将预测结果写入BigQuery。

您可以使用 Dataflow 将预测结果写入 BigQuery。这里有两个选项:

  1. 创建 makes the predictions itself.
  2. 的 Dataflow 作业
  3. 创建使用 AI Platform 获取模型预测的 Dataflow 作业。可能这会使用在线预测。

在这两种情况下,您都可以定义一个 BigQuery 接收器以将新行插入到您的 table。

或者,只要 GCS 中出现新文件,您就可以使用 Cloud Functions 更新 BigQuery table。这个解决方案看起来像:

  1. 使用 gcloud 运行 批量预测(`gcloud ml-engine jobs submit prediction ... --output-path="gs://[My Bucket]/batch-predictions/"
  2. 结果写入多个文件:gs://[My Bucket]/batch-predictions/prediction.results-*-of-NNNNN
  3. 云功能是triggered to parse and insert the results to BigQuery. This Medium post解释了如何设置