일괄 예측

이 페이지에서는 한 번에 여러 데이터 행을 AutoML Tables에 제공하고, 각 행에 대한 예측을 받는 방법을 설명합니다.

소개

모델을 만들어 학습시킨 후에는 batchPredict 메서드를 사용해 일괄 예측에 대한 비동기 요청을 할 수 있습니다. 입력 데이터를 batchPredict 메서드에 표 형식으로 입력합니다. 각 행은 모델이 사용할 수 있도록 학습시킨 특성의 값을 제공합니다. batchPredict 메서드는 이 데이터를 모델에 전송하고 데이터 각 행에 대한 예측을 반환합니다.

예측을 계속 제공하려면 6개월마다 모델을 다시 학습시켜야 합니다.

일괄 예측 요청하기

일괄 예측을 사용하려면 Cloud Storage의 BigQuery 테이블이나 CSV 파일에 데이터 소스와 결과 대상을 지정해야 합니다. 소스와 대상에 동일한 기술을 사용할 필요는 없습니다. 예를 들어 데이터 소스에 BigQuery를, 결과 대상에 Cloud Storage의 CSV 파일을 사용해도 됩니다. 요구사항에 따라 아래 두 작업 중에서 적절한 단계를 따르세요.

데이터 소스에는 모델을 학습시키는 데 사용되는 모든 열을 포함하는 표 형식 데이터가 있어야 합니다. 학습 데이터에 없거나, 학습 데이터에는 있지만 학습에 사용할 수 없는 열을 포함할 수 있습니다. 이러한 추가 열은 예측 출력에 포함되지만 예측 생성에는 사용되지 않습니다.

BigQuery 테이블 사용

입력 데이터의 열과 데이터 유형 이름은 학습 데이터에서 사용한 데이터와 일치해야 합니다. 열 순서는 학습 데이터에서의 순서와 달라도 됩니다.

BigQuery 테이블 요구사항

  • BigQuery 데이터 소스 테이블은 100GB를 넘지 않아야 합니다.
  • US 또는 EU 위치에 있는 멀티 리전 BigQuery 데이터 세트를 사용해야 합니다.
  • 테이블이 다른 프로젝트에 있으면 해당 프로젝트의 AutoML Tables 서비스 계정에 BigQuery Data Editor 역할을 제공해야 합니다. 자세히 알아보기

일괄 예측 요청

콘솔

  1. Google Cloud Console의 AutoML Tables 페이지로 이동합니다.

    AutoML Tables 페이지로 이동

  2. 모델을 선택하고 사용할 모델을 엽니다.

  3. 테스트 및 사용 탭을 선택합니다.

  4. 일괄 예측을 클릭합니다.

  5. 입력 데이터세트에서 BigQuery의 테이블을 선택하고 데이터 소스의 프로젝트, 데이터세트, 테이블 ID를 입력합니다.

  6. 결과에서 BigQuery 프로젝트를 선택하고 결과 목적지의 프로젝트 ID를 입력합니다.

  7. 각 특성이 예측에 미치는 영향을 확인하려면 특성 중요도 생성을 선택합니다.

    특성 중요도를 생성하면 예측에 필요한 시간과 컴퓨팅 리소스가 늘어납니다. Cloud Storage의 결과 목적지에는 로컬 특성 중요도를 사용할 수 없습니다.

  8. 일괄 예측 보내기를 클릭해 일괄 예측을 요청합니다.

    AutoML Tables 일괄 예측 페이지

REST

models.batchPredict 메서드를 사용해 일괄 예측을 요청합니다.

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • endpoint: 전역 위치인 경우 automl.googleapis.com, EU 리전인 경우 eu-automl.googleapis.com입니다.
  • project-id: Google Cloud 프로젝트 ID입니다.
  • location: 리소스의 위치로 전역인 경우 us-central1, 유럽 연합인 경우 eu입니다.
  • model-id: 모델의 ID입니다. 예를 들면 TBL543입니다.
  • dataset-id: 예측 데이터가 있는 BigQuery 데이터 세트의 ID입니다.
  • table-id: 예측 데이터가 있는 BigQuery 테이블의 ID입니다.

    AutoML Tables는 project-id.dataset-id.table-idprediction-<model_name>-<timestamp>라는 예측 결과에 대한 하위 폴더를 만듭니다.

HTTP 메서드 및 URL:

POST https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict

JSON 요청 본문:

{
  "inputConfig": {
    "bigquerySource": {
      "inputUri": "bq://project-id.dataset-id.table-id"
    },
  },
  "outputConfig": {
    "bigqueryDestination": {
      "outputUri": "bq://project-id"
    },
  },
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict" | Select-Object -Expand Content
일괄 예측은 장기 실행 작업입니다. 작업 상태를 폴링하거나 작업이 반환될 때까지 기다립니다. 자세히 알아보기

요청 데이터에 feature_importance 매개변수를 추가하여 로컬 특성 중요도를 가져올 수 있습니다. 자세한 내용은 로컬 특성 중요도를 참조하세요.

Java

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.BatchPredictInputConfig;
import com.google.cloud.automl.v1beta1.BatchPredictOutputConfig;
import com.google.cloud.automl.v1beta1.BatchPredictRequest;
import com.google.cloud.automl.v1beta1.BatchPredictResult;
import com.google.cloud.automl.v1beta1.BigQueryDestination;
import com.google.cloud.automl.v1beta1.BigQuerySource;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.cloud.automl.v1beta1.PredictionServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

abstract class TablesBatchPredictBigQuery {

  static void batchPredict() throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String inputUri = "bq://YOUR_PROJECT_ID.bqDatasetID.bqTableId";
    String outputUri = "bq://YOUR_PROJECT_ID";
    batchPredict(projectId, modelId, inputUri, outputUri);
  }

  static void batchPredict(String projectId, String modelId, String inputUri, String outputUri)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
      // Get the full path of the model.
      ModelName name = ModelName.of(projectId, "us-central1", modelId);

      // Configure the source of the file from BigQuery
      BigQuerySource bigQuerySource = BigQuerySource.newBuilder().setInputUri(inputUri).build();
      BatchPredictInputConfig inputConfig =
          BatchPredictInputConfig.newBuilder().setBigquerySource(bigQuerySource).build();

      // Configure where to store the output in BigQuery
      BigQueryDestination bigQueryDestination =
          BigQueryDestination.newBuilder().setOutputUri(outputUri).build();
      BatchPredictOutputConfig outputConfig =
          BatchPredictOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).build();

      // Build the request that will be sent to the API
      BatchPredictRequest request =
          BatchPredictRequest.newBuilder()
              .setName(name.toString())
              .setInputConfig(inputConfig)
              .setOutputConfig(outputConfig)
              .build();

      // Start an asynchronous request
      OperationFuture<BatchPredictResult, OperationMetadata> future =
          client.batchPredictAsync(request);

      System.out.println("Waiting for operation to complete...");
      future.get();
      System.out.println("Batch Prediction results saved to BigQuery.");
    }
  }
}

Node.js

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기


/**
 * Demonstrates using the AutoML client to request prediction from
 * automl tables using bigQuery.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";
// const inputUri = '[BIGQUERY_PATH]'
// e.g., "bq://<project_id>.<dataset_id>.<table_id>",
// `The Big Query URI containing the inputs`;
// const outputUri = '[BIGQUERY_PATH]' e.g., "bq://<project_id>",
// `The destination Big Query URI for storing outputs`;

const automl = require('@google-cloud/automl');

// Create client for prediction service.
const automlClient = new automl.v1beta1.PredictionServiceClient();

// Get the full path of the model.
const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId);

async function batchPredict() {
  // Construct request
  // Get the Big Query input URI.
  const inputConfig = {
    bigquerySource: {
      inputUri: inputUri,
    },
  };

  // Get the Big Query output URI.
  const outputConfig = {
    bigqueryDestination: {
      outputUri: outputUri,
    },
  };

  const [, operation] = await automlClient.batchPredict({
    name: modelFullId,
    inputConfig: inputConfig,
    outputConfig: outputConfig,
  });

  // Get the latest state of long-running operation.
  console.log(`Operation name: ${operation.name}`);
}

batchPredict();

Python

AutoML Tables용 클라이언트 라이브러리에는 AutoML Tables API로 간소화할 수 있는 추가 Python 메서드가 포함됩니다. 이러한 메서드는 데이터세트와 모델을 id가 아닌 이름으로 지칭합니다. 데이터 세트와 모델 이름은 고유해야 합니다. 자세한 내용은 클라이언트 참조를 확인하세요.

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'
# bq_input_uri = 'bq://my-project.my-dataset.my-table'
# bq_output_uri = 'bq://my-project'
# params = {}

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Query model
response = client.batch_predict(
    bigquery_input_uri=bq_input_uri,
    bigquery_output_uri=bq_output_uri,
    model_display_name=model_display_name,
    params=params,
)
print("Making batch prediction... ")
# `response` is a async operation descriptor,
# you can register a callback for the operation to complete via `add_done_callback`:
# def callback(operation_future):
#   result = operation_future.result()
# response.add_done_callback(callback)
#
# or block the thread polling for the operation's results:
response.result()
# AutoML puts predictions in a newly generated dataset with a name by a mask "prediction_" + model_id + "_" + timestamp
# here's how to get the dataset name:
dataset_name = (
    response.metadata.batch_predict_details.output_info.bigquery_output_dataset
)

print(
    "Batch prediction complete.\nResults are in '{}' dataset.\n{}".format(
        dataset_name, response.metadata
    )
)

Cloud Storage에서 CSV 파일 사용

입력 데이터의 열과 데이터 유형 이름은 학습 데이터에서 사용한 데이터와 일치해야 합니다. 열 순서는 학습 데이터에서의 순서와 달라도 됩니다.

CSV 파일 요구사항

  • 데이터 소스의 첫 번째 줄에는 열의 이름이 있어야 합니다.
  • 각 데이터 소스 파일은 10GB를 넘지 않아야 합니다.

    여러 파일을 포함할 수도 있지만 최대 용량은 100GB로 제한됩니다.

  • Cloud Storage 버킷은 버킷 요구사항 을 준수해야 합니다.

  • AutoML Tables를 사용 중인 프로젝트와 다른 프로젝트에 Cloud Storage 버킷이 있다면 해당 프로젝트의 AutoML Tables 서비스 계정에 Storage Object Creator 역할을 제공해야 합니다. 자세히 알아보기

콘솔

  1. Google Cloud Console의 AutoML Tables 페이지로 이동합니다.

    AutoML Tables 페이지로 이동

  2. 모델을 선택하고 사용할 모델을 엽니다.

  3. 테스트 및 사용 탭을 선택합니다.

  4. 일괄 예측을 클릭합니다.

  5. 입력 데이터세트에서 Cloud Storage의 CSV를 선택하고 데이터 소스의 버킷 URI를 입력합니다.

  6. 결과에서 Cloud Storage 버킷을 선택하고 대상 버킷의 버킷 URI를 입력합니다.

  7. 각 특성이 예측에 미치는 영향을 확인하려면 특성 중요도 생성을 선택합니다.

    특성 중요도를 생성하면 예측에 필요한 시간과 컴퓨팅 리소스가 늘어납니다. Cloud Storage의 결과 목적지에는 로컬 특성 중요도를 사용할 수 없습니다.

  8. 일괄 예측 보내기를 클릭해 일괄 예측을 요청합니다.

    AutoML Tables 일괄 예측 페이지

REST

models.batchPredict 메서드를 사용해 일괄 예측을 요청합니다.

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • endpoint: 전역 위치인 경우 automl.googleapis.com, EU 리전인 경우 eu-automl.googleapis.com입니다.
  • project-id: Google Cloud 프로젝트 ID입니다.
  • location: 리소스의 위치로 전역인 경우 us-central1, 유럽 연합인 경우 eu입니다.
  • model-id: 모델의 ID입니다. 예를 들면 TBL543입니다.
  • input-bucket-name: 예측 데이터가 있는 Cloud Storage 버킷의 이름입니다.
  • input-directory-name: 예측 데이터가 있는 Cloud Storage 디렉터리의 이름입니다.
  • object-name: 예측 데이터가 있는 Cloud Storage 객체의 이름입니다.
  • output-bucket-name: 예측 결과의 Cloud Storage 버킷 이름입니다.
  • output-directory-name: 예측 결과의 Cloud Storage 디렉터리 이름입니다.

    AutoML Tables는 gs://output-bucket-name/output-directory-nameprediction-<model_name>-<timestamp>라는 예측 결과에 대한 하위 폴더를 만듭니다. 사용자는 이 경로에 대한 쓰기 권한이 있어야 합니다.

HTTP 메서드 및 URL:

POST https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict

JSON 요청 본문:

{
  "inputConfig": {
    "gcsSource": {
      "inputUris": [
        "gs://input-bucket-name/input-directory-name/object-name.csv"
      ]
    },
  },
  "outputConfig": {
    "gcsDestination": {
      "outputUriPrefix": "gs://output-bucket-name/output-directory-name"
     },
  },
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/models/model-id:batchPredict" | Select-Object -Expand Content
일괄 예측은 장기 실행 작업입니다. 작업 상태를 폴링하거나 작업이 반환될 때까지 기다립니다. 자세히 알아보기

요청 데이터에 feature_importance 매개변수를 추가하여 로컬 특성 중요도를 가져올 수 있습니다. 자세한 내용은 로컬 특성 중요도를 참조하세요.

Java

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.BatchPredictInputConfig;
import com.google.cloud.automl.v1beta1.BatchPredictOutputConfig;
import com.google.cloud.automl.v1beta1.BatchPredictRequest;
import com.google.cloud.automl.v1beta1.BatchPredictResult;
import com.google.cloud.automl.v1beta1.GcsDestination;
import com.google.cloud.automl.v1beta1.GcsSource;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.cloud.automl.v1beta1.PredictionServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

abstract class BatchPredict {

  static void batchPredict() throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    String inputUri = "gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl";
    String outputUri = "gs://YOUR_BUCKET_ID/path_to_save_results/";
    batchPredict(projectId, modelId, inputUri, outputUri);
  }

  static void batchPredict(String projectId, String modelId, String inputUri, String outputUri)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
      // Get the full path of the model.
      ModelName name = ModelName.of(projectId, "us-central1", modelId);

      // Configure the source of the file from a GCS bucket
      GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
      BatchPredictInputConfig inputConfig =
          BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();

      // Configure where to store the output in a GCS bucket
      GcsDestination gcsDestination =
          GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
      BatchPredictOutputConfig outputConfig =
          BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();

      // Build the request that will be sent to the API
      BatchPredictRequest request =
          BatchPredictRequest.newBuilder()
              .setName(name.toString())
              .setInputConfig(inputConfig)
              .setOutputConfig(outputConfig)
              .build();

      // Start an asynchronous request
      OperationFuture<BatchPredictResult, OperationMetadata> future =
          client.batchPredictAsync(request);

      System.out.println("Waiting for operation to complete...");
      future.get();
      System.out.println("Batch Prediction results saved to specified Cloud Storage bucket.");
    }
  }
}

Node.js

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기


/**
 * Demonstrates using the AutoML client to request prediction from
 * automl tables using GCS.
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";
// const inputUri = '[GCS_PATH]' e.g., "gs://<bucket-name>/<csv file>",
// `The Google Cloud Storage URI containing the inputs`;
// const outputUriPrefix = '[GCS_PATH]'
// e.g., "gs://<bucket-name>/<folder-name>",
// `The destination Google Cloud Storage URI for storing outputs`;

const automl = require('@google-cloud/automl');

// Create client for prediction service.
const automlClient = new automl.v1beta1.PredictionServiceClient();

// Get the full path of the model.
const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId);

async function batchPredict() {
  // Construct request
  const inputConfig = {
    gcsSource: {
      inputUris: [inputUri],
    },
  };

  // Get the Google Cloud Storage output URI.
  const outputConfig = {
    gcsDestination: {
      outputUriPrefix: outputUriPrefix,
    },
  };

  const [, operation] = await automlClient.batchPredict({
    name: modelFullId,
    inputConfig: inputConfig,
    outputConfig: outputConfig,
  });

  // Get the latest state of long-running operation.
  console.log(`Operation name: ${operation.name}`);
  return operation;
}

batchPredict();

Python

AutoML Tables용 클라이언트 라이브러리에는 AutoML Tables API로 간소화할 수 있는 추가 Python 메서드가 포함됩니다. 이러한 메서드는 데이터세트와 모델을 id가 아닌 이름으로 지칭합니다. 데이터 세트와 모델 이름은 고유해야 합니다. 자세한 내용은 클라이언트 참조를 확인하세요.

리소스가 EU 리전에 있다면 엔드포인트를 명시적으로 설정해야 합니다. 자세히 알아보기

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'
# gcs_input_uri = 'gs://YOUR_BUCKET_ID/path_to_your_input_csv'
# gcs_output_uri = 'gs://YOUR_BUCKET_ID/path_to_save_results/'
# params = {}

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# Query model
response = client.batch_predict(
    gcs_input_uris=gcs_input_uri,
    gcs_output_uri_prefix=gcs_output_uri,
    model_display_name=model_display_name,
    params=params,
)
print("Making batch prediction... ")
# `response` is a async operation descriptor,
# you can register a callback for the operation to complete via `add_done_callback`:
# def callback(operation_future):
#   result = operation_future.result()
# response.add_done_callback(callback)
#
# or block the thread polling for the operation's results:
response.result()

print(f"Batch prediction complete.\n{response.metadata}")

결과 검색

BigQuery에서 예측 결과 검색

BigQuery를 출력 대상으로 지정하면 일괄 예측 요청의 결과가 지정한 BigQuery 프로젝트의 새 데이터세트로 반환됩니다. BigQuery 데이터세트 이름은 모델 이름 앞에 'prediction_'과 예측 작업이 시작된 시점의 타임스탬프를 추가해 지정해야 합니다. BigQuery 데이터세트 이름은 모델의 테스트 및 사용 탭에 있는 일괄 예측 페이지의 최근 예측에서 찾을 수 있습니다.

BigQuery 데이터세트에는 predictionserrors의 2개 테이블이 있습니다. errors 테이블에는 AutoML Tables가 예측을 반환하지 못하는 예측 요청의 모든 행에 대한 하나의 행이 있습니다. 예를 들어 null 비허용 특성이 null인 경우입니다. predictions 테이블에는 반환된 모든 예측에 대한 하나의 행이 포함됩니다.

predictions 테이블에서 AutoML Tables는 예측 데이터를 반환하고. 타겟 열 이름 앞에 'predicted_'를 추가하여 예측 결과에 대한 새 열을 만듭니다. 예측 결과 열에는 예측 결과가 포함된 중첩된 BigQuery 구조가 포함됩니다.

예측 결과를 가져오려면 BigQuery 콘솔에서 쿼리를 사용하면 됩니다. 쿼리 형식은 모델 유형에 따라 다릅니다.

이진 분류

SELECT predicted_<target-column-name>[OFFSET(0)].tables AS value_1,
predicted_<target-column-name>[OFFSET(1)].tables AS value_2
FROM <bq-dataset-name>.predictions

'value_1'및 'value_2'는 위치 표시자이므로 타겟 값 또는 이에 상응하는 값으로 바꿀 수 있습니다.

멀티클래스 분류

SELECT predicted_<target-column-name>[OFFSET(0)].tables AS value_1,
predicted_<target-column-name>[OFFSET(1)].tables AS value_2,
predicted_<target-column-name>[OFFSET(2)].tables AS value_3,
...
predicted_<target-column-name>[OFFSET(4)].tables AS value_5
FROM <bq-dataset-name>.predictions

'value_1'. 'value_2' 등은 위치 표시자이므로 타겟 값 또는 이에 상응하는 값으로 바꿀 수 있습니다.

회귀:

SELECT predicted_<target-column-name>[OFFSET(0)].tables.value,
predicted_<target-column-name>[OFFSET(0)].tables.prediction_interval.start,
predicted_<target-column-name>[OFFSET(0)].tables.prediction_interval.end
FROM <bq-dataset-name>.predictions

Cloud Storage에서 결과 검색

Cloud Storage를 출력 대상으로 지정하면 일괄 예측 요청의 결과가 지정한 버킷의 새 폴더에 CSV 파일로 반환됩니다. 폴더 이름은 모델 이름 앞에 'prediction_'과 예측 작업이 시작된 시점의 타임스탬프를 추가해 지정해야 합니다. Cloud Storage 폴더 이름은 모델의 테스트 및 사용 탭에 있는 일괄 예측 페이지 하단의 최근 예측에서 찾을 수 있습니다.

Cloud Storage 폴더에는 오류 파일과 예측 파일의 두 가지 유형의 파일이 있습니다. 결과가 크면 추가 파일이 생성됩니다.

오류 파일의 이름은 errors_1.csv. errors_2.csv 등으로 지정됩니다. 이러한 오류 파일에는 헤더 행 외에 AutoML Tables가 예측을 반환하지 못하는 예측 요청의 모든 행에 대한 하나의 행이 포함됩니다.

예측 파일의 이름은 tables_1.csv. tables_2.csv 등으로 지정됩니다. 이러한 예측 파일에는 열 이름이 지정된 헤더 행과 반환된 모든 예측에 대한 하나의 행이 포함됩니다.

예측 파일에서 AutoML Tables는 예측 데이터를 반환하고. 모델 유형에 따라 예측 결과에 대한 1개 이상의 새 열을 만듭니다.

분류:

타겟 열의 각 예상 값에 대해 이름이 <target-column-name>_<value>_score인 열이 결과에 추가됩니다. 이 열에는 해당 값에 대한 점수 또는 신뢰도 추정치가 포함됩니다.

회귀:

해당 행의 예측 값은 predicted_<target-column-name>라는 열에 반환됩니다. CSV 출력에 대한 예측 간격은 반환되지 않습니다.

Cloud Storage에서는 결과에 로컬 특성 중요도를 사용할 수 없습니다.

결과 해석

결과를 해석하는 방법은 해결 중인 비즈니스 문제와 데이터의 분산 방식에 따라 다릅니다.

분류 모델의 결과 해석

분류 모델(이진 및 멀티클래스)의 예측 결과는 타겟 열의 각 예상 값에 대한 확률 점수를 반환합니다. 점수 사용 방식을 결정해야 합니다. 예를 들어 제공된 점수에서 이진 분류를 가져오려면 임계값을 식별해야 합니다. 'A'와 'B'라는 2개의 클래스가 있을 때 'A' 점수가 선택한 임계값보다 크다면 예시를 'A'로 분류하고, 그 외의 경우에는 'B'로 분류해야 합니다. 클래스의 균형이 맞지 않으면 임계값이 100% 또는 0%에 접근하게 됩니다.

Google Cloud Console의 모델 평가 페이지에서 정밀도 재현율 곡선 차트, 수신자 조작자 곡선 차트, 기타 관련 라벨별 통계를 사용하면 임계값 변경에 따라 평가 측정항목이 어떻게 변하는지 확인할 수 있습니다. 이렇게 하면 점수 값을 사용하여 예측 결과를 해석하는 최적의 방법을 결정하는 데 도움이 됩니다.

회귀 모델의 결과 해석

회귀 모델에서는 예측 값이 반환되며, 문제가 많을 경우 해당 값을 바로 사용할 수 있습니다. 예측 구간이 반환되거나 특정 구간이 비즈니스 문제에 적합하다고 판단되는 경우에도 예측 구간을 사용할 수 있습니다.

로컬 특성 중요도 결과 해석

로컬 특성 중요도 결과 해석에 대한 자세한 내용은 로컬 특성 중요도를 참조하세요.

다음 단계