# バッチ予測のユースケース

> バッチ予測のユースケース - CSVファイルと外部サービスの両方でAPIコードでスコアリングのいくつかのエンドツーエンドの例を確認します。

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-23T18:01:59.422917+00:00` (UTC).

## Primary page

- [バッチ予測のユースケース](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [ローカルからのCSVファイルのエンドツーエンドのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-of-csv-files-from-local-files): In-page section heading.
- [予測の説明](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#prediction-explanations): In-page section heading.
- [カスタムCSV形式](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#custom-csv-format): In-page section heading.
- [S3でのCSVファイルのエンドツーエンドのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-of-csv-files-on-s3): In-page section heading.
- [予測の説明](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#prediction-explanations_1): In-page section heading.
- [AIカタログからCSVファイルへのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#ai-catalog-to-csv-file-scoring): In-page section heading.
- [JDBC PostgreSQLデータベースからのエンドツーエンドのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-from-a-jdbc-postgresql-database): In-page section heading.
- [Snowflakeによるエンドツーエンドのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-with-snowflake): In-page section heading.
- [Synapseによるエンドツーエンドのスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-with-synapse): In-page section heading.
- [BigQueryによるエンドツーエンドスコアリング](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/pred-examples.html.md#end-to-end-scoring-with-bigquery): In-page section heading.

## Documentation content

以下は、CSVファイルと外部サービスの両方のAPIコードを使用したエンドツーエンドのスコアリングのいくつかの例です。

- ローカルからのCSVファイルのエンドツーエンドのスコアリング
- S3でのCSVファイルのエンドツーエンドのスコアリング
- AIカタログからCSVファイルへのスコアリング
- JDBC PostgreSQLデータベースからのエンドツーエンドのスコアリング
- Snowflakeによるエンドツーエンドのスコアリング
- Synapseによるエンドツーエンドのスコアリング
- BigQueryによるエンドツーエンドスコアリング

> [!NOTE] 備考
> これらのユースケースでは、 [DataRobot](https://datarobot-public-api-client.readthedocs-hosted.com/) APIクライアントをインストールする必要があります。

## ローカルからのCSVファイルのエンドツーエンドのスコアリング

次の例では、ローカルCSVファイルがスコアリングされ、処理の開始を待機した後にダウンロードが初期化されます。

```
import datarobot as dr

dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)

deployment_id = "..."

input_file = "to_predict.csv"
output_file = "predicted.csv"

job = dr.BatchPredictionJob.score_to_file(
    deployment_id,
    input_file,
    output_file,
    passthrough_columns_set="all"
)

print("started scoring...", job)
job.wait_for_completion() 
```

### 予測の説明

目的の [予測の説明パラメーター](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/output-format.html.md#prediction-explanations) をジョブ設定に追加して、予測の説明を含めることができます。

```
job = dr.BatchPredictionJob.score_to_file(
    deployment_id,
    input_file,
    output_file,
    max_explanations=10,
    threshold_high=0.5,
    threshold_low=0.15,
) 
```

### カスタムCSV形式

CSVファイルがデフォルトのCSV形式でない場合は、 `csvSettings` を設定して予想CSV形式を変更できます。

```
job = dr.BatchPredictionJob.score_to_file(
    deployment_id,
    input_file,
    output_file,
    csv_settings={
        'delimiter': ';',
        'quotechar': '\'',
        'encoding': 'ms_kanji',
    },
) 
```

## S3でのCSVファイルのエンドツーエンドのスコアリング

```
import datarobot as dr

dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)

deployment_id = "616d01a8ddbd17fc2c75caf4"
credential_id = "..."

s3_csv_input_file = 's3://my-bucket/data/to_predict.csv'
s3_csv_output_file = 's3://my-bucket/data/predicted.csv'

job = dr.BatchPredictionJob.score_s3(
    deployment_id,
    source_url=s3_csv_input_file,
    destination_url=s3_csv_output_file,
    credential=credential_id
)

print("started scoring...", job)
job.wait_for_completion() 
```

同じ機能が `score_azure` および `score_gcp` で使用可能です。 資格情報IDの代わりに、 `credential` オブジェクト自身を指定することもできます。

```
credentials = dr.Credential.get(credential_id)

job = dr.BatchPredictionJob.score_s3(
    deployment_id,
    source_url=s3_csv_input_file,
    destination_url=s3_csv_output_file,
    credential=credentials,
) 
```

### 予測の説明

目的の [予測の説明パラメーター](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/output-format.html.md#prediction-explanations) をジョブ設定に追加して、予測の説明を含めることができます。

```
job = dr.BatchPredictionJob.score_s3(
    deployment_id,
    source_url=s3_csv_input_file,
    destination_url=s3_csv_output_file,
    credential=credential_id,
    max_explanations=10,
    threshold_high=0.5,
    threshold_low=0.15,
) 
```

## AIカタログからCSVファイルへのスコアリング

入力に [AIカタログ](https://docs.datarobot.com/ja/docs/classic-ui/data/ai-catalog/catalog.html.md) を使用する場合、作成済みのデータセットの `dataset_id` が必要です。

```
import datarobot as dr

dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)

deployment_id = "616d01a8ddbd17fc2c75caf4"
credential_id = "..."
dataset_id = "..."

dataset = dr.Dataset.get(dataset_id)

job = dr.BatchPredictionJob.score(
    deployment_id,
    intake_settings={
        'type': 'dataset',
        'dataset_id': dataset,
    },
    output_settings={
        'type': 'localFile',
    },
)

job.wait_for_completion() 
```

## JDBC PostgreSQLデータベースからのエンドツーエンドのスコアリング

以下は、表 `public.scoring_data` からのスコアリングデータセットで、スコアリングされたデータを `public.scored_data` に保存します（表がすでに存在する場合）。

```
import datarobot as dr

dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)

deployment_id = "616d01a8ddbd17fc2c75caf4"
credential_id = "..."
datastore_id = "..."

intake_settings = {
    'type': 'jdbc',
    'table': 'scoring_data',
    'schema': 'public',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
}

output_settings = {
    'type': 'jdbc',
    'table': 'scored_data',
    'schema': 'public',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
    'statement_type': 'insert'
}

job = dr.BatchPredictionJob.score(
    deployment_id,
    passthrough_columns_set='all',
    intake_settings=intake_settings,
    output_settings=output_settings,
)

print("started scoring...", job)
job.wait_for_completion() 
```

JDBCスコアリングの詳細については、 [こちら](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/intake-options.html.md#jdbc-scoring) を参照してください。

## Snowflakeによるエンドツーエンドのスコアリング

以下の例では、テーブル `public.SCORING_DATA` からのスコアリングデータセットで、スコアリングされたデータを `public.SCORED_DATA` に保存します（テーブルがすでに存在する場合）。

```
import datarobot as dr
dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)
deployment_id = "616d01a8ddbd17fc2c75caf4"
credential_id = "..."
cloud_storage_credential_id = "..."
datastore_id = "..."
intake_settings = {
    'type': 'snowflake',
    'table': 'SCORING_DATA',
    'schema': 'PUBLIC',
    'external_stage': 'my_s3_stage_in_snowflake',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
    'cloud_storage_type': 's3',
    'cloud_storage_credential_id': cloud_storage_credential_id
}
output_settings = {
    'type': 'snowflake',
    'table': 'SCORED_DATA',
    'schema': 'PUBLIC',
    'statement_type': 'insert'
    'external_stage': 'my_s3_stage_in_snowflake',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
    'cloud_storage_type': 's3',
    'cloud_storage_credential_id': cloud_storage_credential_id
}
job = dr.BatchPredictionJob.score(
    deployment_id,
    passthrough_columns_set='all',
    intake_settings=intake_settings,
    output_settings=output_settings,
)
print("started scoring...", job)
job.wait_for_completion() 
```

Snowflakeスコアリングの詳細については、 [入力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/intake-options.html.md#snowflake-scoring) および [出力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/output-options.html.md#snowflake-write) ドキュメントを参照してください。

## Synapseによるエンドツーエンドのスコアリング

以下の例では、テーブル `public.scoring_data` からのスコアリングデータセットで、スコアリングされたデータを `public.scored_data` に保存します（テーブルがすでに存在する場合）。

```
import datarobot as dr
dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)
deployment_id = "616d01a8ddbd17fc2c75caf4"
credential_id = "..."
cloud_storage_credential_id = "..."
datastore_id = "..."
intake_settings = {
    'type': 'synapse',
    'table': 'SCORING_DATA',
    'schema': 'PUBLIC',
    'external_data_source': 'some_datastore',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
    'cloud_storage_credential_id': cloud_storage_credential_id
}
output_settings = {
    'type': 'synapse',
    'table': 'SCORED_DATA',
    'schema': 'PUBLIC',
    'statement_type': 'insert'
    'external_data_source': 'some_datastore',
    'data_store_id': datastore_id,
    'credential_id': credential_id,
    'cloud_storage_credential_id': cloud_storage_credential_id
}
job = dr.BatchPredictionJob.score(
    deployment_id,
    passthrough_columns_set='all',
    intake_settings=intake_settings,
    output_settings=output_settings,
)
print("started scoring...", job)
job.wait_for_completion() 
```

Synapseスコアリングの詳細については、 [入力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/intake-options.html.md#synapse-scoring) および [出力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/output-options.html.md#synapse-write) ドキュメントを参照してください。

## BigQueryによるエンドツーエンドスコアリング

次の例では、BigQueryテーブルからデータをスコアリングし、結果をBigQueryテーブルに送信しています。

```
import datarobot as dr

dr.Client(
    endpoint="https://app.datarobot.com/api/v2",
    token="...",
)

deployment_id = "616d01a8ddbd17fc2c75caf4"
gcs_credential_id = "6166c01ee91fb6641ecd28bd"

intake_settings = {
    'type': 'bigquery',
    'dataset': 'my-dataset',
    'table': 'intake-table',
    'bucket': 'my-bucket',
    'credential_id': gcs_credential_id,
}

output_settings = {
    'type': 'bigquery',
    'dataset': 'my-dataset',
    'table': 'output-table',
    'bucket': 'my-bucket',
    'credential_id': gcs_credential_id,
}

job = dr.BatchPredictionJob.score(
    deployment=deployment_id,
    intake_settings=intake_settings,
    output_settings=output_settings,
    include_prediction_status=True,
    passthrough_columns=["some_col_name"],
)

print("started scoring...", job)
job.wait_for_completion() 
```

BigQueryスコアリングの詳細については、 [入力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/intake-options.html.md#bigquery-scoring) および [出力](https://docs.datarobot.com/ja/docs/api/reference/batch-prediction-api/output-options.html.md#bigquery-write) ドキュメントを参照してください。
