{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"インクリメンタルミニバッチ予測","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"インクリメンタルミニバッチ予測","__idx":0},"children":["インクリメンタルミニバッチ予測"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["このドキュメントでは、_インクリメンタル予測_の実装方法について説明し、低レイテンシ要件に対応するためのベストプラクティスを提供します。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["予測には3つの主なパターンがあります:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["オンライン"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["オフライン"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["インクリメンタル"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/247133042-d733e9c4-9139-4363-a652-65b3a7c5f714.a9bffd1c6133669aaf87179e1aee73b77f2ce418d0eec745d7b71606ea7d2e92.3cb60505.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["オンライン予測:"]}," 通常、JSON形式のレコードを入力として受け取り、予測結果を返すREST APIとして実装されます。各予測の完了にかかる時間は、ミリ秒から秒単位です。各APIコールのレスポンスは、例えばCookie IDからユーザー属性を解決するなど、複数のJOINが必要になるため、計算が複雑になる可能性があります。アンサンブルモデルは、REST APIコールの低レイテンシ要件を満たせない場合があります。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["オフライン予測:"]}," 通常、日次バッチジョブとしてスケジュールされます。予測のための高いスループットを実現できますが、一般的に各バッチの予測を完了するのに数十分から数時間かかります。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["インクリメンタル(ミニバッチ)予測:"]}," バッチ予測と似ていますが、タスクをより小さなバッチに分割できる点が異なります。各ミニバッチの予測を完了するのに数秒から数分かかります。厳密なリアルタイム要件には適用できませんが、数分のレイテンシが許容されるセミリアルタイムのシナリオには適用できます。"]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["予測結果をキーバリューストアに保存する場合、レイテンシをミリ秒単位にすることが可能です。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["インクリメンタルミニバッチ予測を実装する"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["保険商品の営業コールバックをリクエストした新規ユーザーにスコアを割り当てるユースケースを考えてみましょう。ただし、ユーザー数が多く、予測されたLTV(顧客生涯価値)スコアによって優先順位をつける必要があります。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["5分間のバッチごとに多くの新規顧客を処理する必要があり、一部の既存顧客には追加のレコードがある場合があります。そのため、過去5分間にアクセスしたユーザーの新しいLTVスコアを計算することが期待されます。予測は、次のバッチが開始される前の5分以内に完了する必要があります。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["予測結果が",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["${predicted_table}"]},"に保存されていると仮定すると、次のSQLクエリを使用して、最新のLTVスコアでソートされたユーザー詳細を取得できます:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["各ユーザーの最新LTVスコアを取得する"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"WITH scores AS (\n  SELECT\n    userid,\n    td_last(time, score) as score # 最新の予測スコアを使用\n  FROM\n    ${predicted_table}\n  WHERE\n    score >= 0.7 -- スコアの閾値でフィルタリング\n  GROUP BY\n    userid\n)\nSELECT\n  l.userid, l.score,\n  r.user_name, r.user_age, r.user_email, r.user_tel_no\nFROM\n  scores l\n  JOIN user_info r ON (l.userid=r.userid)\nORDER BY\n  score DESC\n-- LIMIT 100\n","lang":"sql"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["次のワークフローを使用して、過去5分間にアクセスしたユーザーにLTVスコアを追加するミニバッチ予測をスケジュールできます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ミニバッチ予測を実行するワークフロー"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"# 5分ごとに予測を実行\ntimezone: Asia/Tokyo\nschedule:\n  cron>: */5 * * * *\n\n# 過去5分間にアクセスしたユーザーをリストアップ\n+list_users:\n  td>: queries/list_users.sql\n  store_last_results: true\n\n# ミニバッチ予測を実行\n+gluon_predict:\n  ml_predict>:\n    notebook: gluon_predict\n    model_name: ${model_name}\n    input_table: ${input_database}.${input_table}\n    output_table: ${output_database}.${output_table}\n    output_mode: append # output_tableにスコアを追加\n    rowid_column: userid\n    rowid_filter: ${td.last.results.users}\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["${model_name}で指定された予測モデルは、月次ベースで作成され、検証済みの良好なパフォーマンスを持つモデルが予測に使用されることを想定しています。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["\"",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["queries/list_users.sql"]},"\"では、過去5分間にアクセスしたユーザーのIDを次のようにリストアップできます:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["queries/list_users.sql"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"SELECT\n  -- カンマ区切りのユーザーリスト: '111','222'\n  array_join(transform(array_agg(DISTINCT userid), x -> '''' || x || ''''), ',')  as users\nFROM\n  session\nWHERE\n  time >= TD_TIME_ADD(TD_SCHEDULED_TIME(), '-5m', 'JST') -- 過去5分間のアクセス\n","lang":"sql"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["\"",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["rowid_column"]},"\"と\"",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["rowid_filter"]},"\"は、次のSQLクエリを発行するために使用され、一致する行のみが予測に使用されます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"SELECT * FROM ${input_database}.{input_table}\nWHERE {rowid_column} in ({rowid_filter})\n","lang":"sql"},"children":[]}]},"headings":[{"value":"インクリメンタルミニバッチ予測","id":"インクリメンタルミニバッチ予測","depth":1}],"frontmatter":{"seo":{"title":"インクリメンタルミニバッチ予測"}},"lastModified":"2025-11-22T02:43:27.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/products/customer-data-platform/machine-learning/automl/advanced-topics/incremental-mini-batch-prediction","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}