데이터 세트 관리

이 페이지에서는 데이터 세트에 대한 정보를 삭제하고 가져오는 방법을 설명합니다.

데이터 세트를 만들고 데이터를 가져오는 방법에 대한 자세한 내용은 데이터 세트 만들기 및 데이터 가져오기를 참조하세요.

시작하기 전에

AutoML Tables를 사용하려면 먼저 시작하기 전에의 설명대로 프로젝트를 설정해야 합니다.

데이터세트 나열

프로젝트에는 수많은 데이터 세트가 포함될 수 있습니다. 이 섹션에서는 프로젝트에 사용할 수 있는 데이터세트의 목록을 검색하는 방법을 설명합니다.

콘솔

AutoML Tables UI를 사용해 사용 가능한 데이터 세트 목록을 표시하려면 왼쪽 탐색 메뉴 맨 위에 있는 데이터 세트 링크를 클릭하고 리전을 선택합니다.

REST

데이터세트를 나열하려면 datasets.list 메서드를 사용합니다.

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

  • endpoint: 전역 위치인 경우 automl.googleapis.com, EU 리전인 경우 eu-automl.googleapis.com입니다.
  • project-id: Google Cloud 프로젝트 ID입니다.
  • location: 리소스의 위치로 전역인 경우 us-central1, 유럽 연합인 경우 eu입니다.

HTTP 메서드 및 URL:

GET https://endpoint/v1beta1/projects/project-id/locations/location/datasets

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

curl

다음 명령어를 실행합니다.

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://endpoint/v1beta1/projects/project-id/locations/location/datasets"

PowerShell

다음 명령어를 실행합니다.

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

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/datasets" | Select-Object -Expand Content

다음과 비슷한 JSON 응답이 표시됩니다.

{
      "name": "projects/29434381/locations/us-central1/datasets/TBL75559",
      "displayName": "test_dataset",
      "createTime": "2019-03-21T00:50:20.660378Z",
      "updateTime": "2019-08-23T19:32:52.025469Z",
      "etag": "AB3BwFoV4USmhM3pT8c6Y5AIA6n51dAmSuObc=",
      "exampleCount": 94356,
      "tablesDatasetMetadata": {
        "primaryTableSpecId": "16930321664",
        "targetColumnSpecId": "46579780096",
        "areStatsFresh": true,
        "targetColumnCorrelations": {
          "6788648672679690240": {
            "cramersV": 0.16511808788616378
          },
          "87292427152392192": {
            "cramersV": 0.20327159375043746
          },
          "2393135436366086144": {
            "cramersV": 0.15513206308654948
          },
          "9094491681893384192": {
            "cramersV": 0.021499396246101456
          },
          "7004821454793474048": {
            "cramersV": 0.030097587339321379
          }
        },
        "statsUpdateTime": "2019-08-16T01:43:38.583Z",
        "tablesDatasetType": "BASIC"
      }
    },
...

Java

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

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.Dataset;
import com.google.cloud.automl.v1beta1.ListDatasetsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import java.io.IOException;

class ListDatasets {

  static void listDatasets() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    listDatasets(projectId);
  }

  // List the datasets
  static void listDatasets(String projectId) throws IOException {
    // 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 (AutoMlClient client = AutoMlClient.create()) {
      // A resource that represents Google Cloud Platform location.
      LocationName projectLocation = LocationName.of(projectId, "us-central1");
      ListDatasetsRequest request =
          ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build();

      // List all the datasets available in the region by applying filter.
      System.out.println("List of datasets:");
      for (Dataset dataset : client.listDatasets(request).iterateAll()) {
        // Display the dataset information
        System.out.format("%nDataset name: %s%n", dataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = dataset.getName().split("/");
        String retrievedDatasetId = names[names.length - 1];
        System.out.format("Dataset id: %s%n", retrievedDatasetId);
        System.out.format("Dataset display name: %s%n", dataset.getDisplayName());
        System.out.println("Dataset create time:");
        System.out.format("\tseconds: %s%n", dataset.getCreateTime().getSeconds());
        System.out.format("\tnanos: %s%n", dataset.getCreateTime().getNanos());

        System.out.format("Tables dataset metadata: %s%n", dataset.getTablesDatasetMetadata());

      }
    }
  }
}

Node.js

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

const automl = require('@google-cloud/automl');
const util = require('util');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to list all datasets.
 * 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 filter = '[FILTER_EXPRESSIONS]' e.g., "tablesDatasetMetadata:*";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// List all the datasets available in the region by applying filter.
client
  .listDatasets({parent: projectLocation, filter: filter})
  .then(responses => {
    const dataset = responses[0];

    // Display the dataset information.
    console.log('List of datasets:');
    for (let i = 0; i < dataset.length; i++) {
      const tablesDatasetMetadata = dataset[i].tablesDatasetMetadata;

      console.log(`Dataset name: ${dataset[i].name}`);
      console.log(`Dataset Id: ${dataset[i].name.split('/').pop(-1)}`);
      console.log(`Dataset display name: ${dataset[i].displayName}`);
      console.log(`Dataset example count: ${dataset[i].exampleCount}`);
      console.log('Tables dataset metadata:');
      console.log(
        `\tTarget column correlations: ${util.inspect(
          tablesDatasetMetadata.targetColumnCorrelations,
          false,
          null
        )}`
      );
      console.log(
        `\tPrimary table spec Id: ${tablesDatasetMetadata.primaryTableSpecId}`
      );
      console.log(
        `\tTarget column spec Id: ${tablesDatasetMetadata.targetColumnSpecId}`
      );
      console.log(
        `\tWeight column spec Id: ${tablesDatasetMetadata.weightColumnSpecId}`
      );
      console.log(
        `\tMl use column spec Id: ${tablesDatasetMetadata.mlUseColumnSpecId}`
      );
    }
  })
  .catch(err => {
    console.error(err);
  });

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'
# filter = 'filter expression here'

from google.cloud import automl_v1beta1 as automl

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

# List all the datasets available in the region by applying filter.
response = client.list_datasets(filter=filter)

print("List of datasets:")
for dataset in response:
    # Display the dataset information.
    print(f"Dataset name: {dataset.name}")
    print("Dataset id: {}".format(dataset.name.split("/")[-1]))
    print(f"Dataset display name: {dataset.display_name}")
    metadata = dataset.tables_dataset_metadata
    print(
        "Dataset primary table spec id: {}".format(metadata.primary_table_spec_id)
    )
    print(
        "Dataset target column spec id: {}".format(metadata.target_column_spec_id)
    )
    print(
        "Dataset target column spec id: {}".format(metadata.target_column_spec_id)
    )
    print(
        "Dataset weight column spec id: {}".format(metadata.weight_column_spec_id)
    )
    print(
        "Dataset ml use column spec id: {}".format(metadata.ml_use_column_spec_id)
    )
    print(f"Dataset example count: {dataset.example_count}")
    print(f"Dataset create time: {dataset.create_time}")
    print("\n")

데이터 세트 삭제

데이터세트를 삭제하면 데이터세트가 프로젝트에서 영구적으로 제거됩니다. 단, 데이터세트를 삭제해도 데이터세트에서 생성한 모델은 삭제되지 않습니다. 모델을 삭제하려면 해당 모델을 선택해서 삭제해야 합니다.

콘솔

  1. AutoML Tables UI에 사용 가능한 데이터 세트 목록을 표시하려면 왼쪽 탐색 메뉴 맨 위에 있는 데이터 세트 링크를 클릭하고 리전을 선택합니다.

  2. 삭제하려는 행 맨 오른쪽에 있는 추가 작업 메뉴를 클릭하고 데이터세트 삭제를 클릭합니다.

    AutoML Tables 스키마 페이지

  3. 확인 대화상자에서 확인을 클릭합니다.

REST

데이터세트를 삭제하려면 datasets.delete 메서드를 사용합니다.

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

  • endpoint: 전역 위치인 경우 automl.googleapis.com, EU 리전인 경우 eu-automl.googleapis.com입니다.
  • project-id: Google Cloud 프로젝트 ID입니다.
  • location: 리소스의 위치로 전역인 경우 us-central1, 유럽 연합인 경우 eu입니다.
  • dataset-id: 삭제할 데이터 세트의 ID입니다. 예를 들면 TBL6543입니다.

HTTP 메서드 및 URL:

DELETE https://endpoint/v1beta1/projects/project-id/locations/location/datasets/dataset-id

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

curl

다음 명령어를 실행합니다.

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://endpoint/v1beta1/projects/project-id/locations/location/datasets/dataset-id"

PowerShell

다음 명령어를 실행합니다.

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

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://endpoint/v1beta1/projects/project-id/locations/location/datasets/dataset-id" | Select-Object -Expand Content

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/29452381/locations/us-central1/operations/TBL6543",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2019-12-26T17:19:50.684850Z",
    "updateTime": "2019-12-26T17:19:50.684850Z",
    "deleteDetails": {},
    "worksOn": [
      "projects/29452381/locations/us-central1/datasets/TBL6543"
    ],
    "state": "DONE"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

데이터 세트 삭제는 장기 실행 작업입니다. 작업 상태를 폴링하거나 작업이 반환될 때까지 기다립니다. 자세히 알아보기

Java

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

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.DatasetName;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class DeleteDataset {

  static void deleteDataset() throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String datasetId = "YOUR_DATASET_ID";
    deleteDataset(projectId, datasetId);
  }

  // Delete a dataset
  static void deleteDataset(String projectId, String datasetId)
      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 (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the dataset.
      DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
      Empty response = client.deleteDatasetAsync(datasetFullId).get();
      System.out.format("Dataset deleted. %s%n", response);
    }
  }
}

Node.js

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

const automl = require('@google-cloud/automl');
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to delete a dataset.
 * 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 datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936";

// Get the full path of the dataset.
const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId);

// Delete a dataset.
client
  .deleteDataset({name: datasetFullId})
  .then(responses => {
    const operation = responses[0];
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    const operationDetails = responses[2];

    // Get the dataset delete details.
    console.log('Dataset delete details:');
    console.log('\tOperation details:');
    console.log(`\t\tName: ${operationDetails.name}`);
    console.log(`\t\tDone: ${operationDetails.done}`);
  })
  .catch(err => {
    console.error(err);
  });

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'
# dataset_display_name = 'DATASET_DISPLAY_NAME_HERE

from google.cloud import automl_v1beta1 as automl

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

# Delete a dataset.
response = client.delete_dataset(dataset_display_name=dataset_display_name)

# synchronous check of operation status.
print(f"Dataset deleted. {response.result()}")

다음 단계