Deleting models

This page shows you how to delete BigQuery ML models. You can delete a model by:

  • Using the Cloud Console
  • Using the command-line tool's bq rm command or bq query command
  • Calling the models.delete API method or by calling the jobs.query method
  • Using the client libraries

Currently, you can only delete one model at a time. When you delete a model, any data in the model is also deleted.

To automatically delete models after a specified period of time, set the model's expiration time when you create it using the CLI, API, or client libraries. If you did not set the expiration when the model was created, you can update it.

Limitations on deleting models

Deleting a model is subject to the following limitations:

  • You cannot delete multiple models at the same time. Models must be deleted individually.
  • Deleting a model cannot be undone.

Required permissions

To delete models in a dataset, you must be assigned the WRITER role on the dataset, or you must be assigned a project-level IAM role that includes bigquery.models.delete permissions. If you are granted bigquery.models.delete permissions at the project level, you can delete models in any dataset in the project. The following, project-level IAM roles include bigquery.models.delete permissions:

  • bigquery.dataEditor
  • bigquery.dataOwner
  • bigquery.admin

For more information on IAM roles and permissions in BigQuery ML, see Access control. For more information on dataset-level roles, see Primitive roles for datasets in the BigQuery documentation.

Deleting a model

To delete a model:

Console

You can delete a model in the BigQuery web UI by using the Delete Model option or by running a query that contains a DROP MODEL | DROP MODEL IF EXISTS DDL statement.

Option one: Use the Delete Model option.

  1. Go to the BigQuery web UI in the Cloud Console.

    Go to the BigQuery web UI

  2. In the navigation panel, in the Resources section, expand your project name and dataset name.

  3. Click your model name. Models are indicated by the model icon: model icon.

  4. On the right side of the window, click Delete Model.

  5. In the Delete model dialog, type the name of the model and then click Delete.

Option two: Use a DDL statement.

  1. Go to the BigQuery web UI.

    Go to the BigQuery web UI

  2. Click Compose new query.

  3. Type your DDL statement in the Query editor text area.

     DROP MODEL mydataset.mymodel
     

  4. Click Run. When the query completes, the model is removed from the navigation pane.

CLI

You can delete a model using the bq command-line tool by entering the:

  • bq rm command with the --model or -m flag
  • bq query command and supplying the DDL statement as the query parameter

If you are deleting a model in a project other than your default project, add the project ID to the dataset in the following format: [PROJECT_ID]:[DATASET].[MODEL].

Option one: Enter the bq rm command

When you use the bq rm command to remove a model, you must confirm the action. You can use the --force flag (or -f shortcut) to skip confirmation.

bq rm -f --model [PROJECT_ID]:[DATASET].[MODEL]

Where:

  • [PROJECT_ID] is your project ID.
  • [DATASET] is the name of the dataset.
  • [MODEL] is the name of the model you're deleting.

The rm command produces no output.

Examples:

Enter the following command to delete mymodel from mydataset. mydataset is in your default project.

bq rm --model mydataset.mymodel

Enter the following command to delete mymodel from mydataset. mydataset is in myotherproject, not your default project.

bq rm --model myotherproject:mydataset.mymodel

Enter the following command to delete mymodel from mydataset. mydataset is in your default project. The command uses the -f shortcut to bypass confirmation.

bq rm -f --model mydataset.mymodel

You can confirm that the model was deleted by issuing the bq ls command. For more information, see Listing models.

Option two: Enter the bq query command

To delete a model by using the bq query command, supply the DROP MODEL statement in the query parameter and supply the --use_legacy_sql=false flag to specify standard SQL query syntax.

Examples:

Enter the following command to delete mymodel from mydataset. mydataset is in your default project.

bq query --use_legacy_sql=false 'DROP MODEL mydataset.mymodel'

Enter the following command to delete mymodel from mydataset. mydataset is in myotherproject, not your default project.

bq query --use_legacy_sql=false \
'DROP MODEL myotherproject:mydataset.mymodel'

API

Option one: Call the models.delete method

To delete a model, call the models.delete method and provide the projectId, datasetId, and modelId.

Option two: Call the jobs.query method

To delete a model, call the jobs.query method and supply the DROP MODEL DDL statement in the request body's query property.

Restoring a deleted model

Currently, you cannot restore a deleted model.

What's next

Σας βοήθησε αυτή η σελίδα; Πείτε μας τη γνώμη σας:

Αποστολή σχολίων σχετικά με…

Αυτή η σελίδα