Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Modelle verwalten
Auf dieser Seite erfahren Sie, wie BigQuery ML-Modelle verwaltet werden. Außerdem wird das Kopieren und Umbenennen von Modellen beschrieben.
Erforderliche Rollen
Bitten Sie Ihren Administrator, Ihnen die IAM-Rolle BigQuery-Datenbearbeiter (roles/bigquery.dataEditor) für das Projekt zuzuweisen, um die Berechtigungen zu erhalten, die Sie zum Lesen und Erstellen von BigQuery-Modellen benötigen.
Weitere Informationen zum Zuweisen von Rollen finden Sie unter Zugriff auf Projekte, Ordner und Organisationen verwalten.
Diese vordefinierte Rolle enthält die Berechtigungen, die zum Lesen und Erstellen von BigQuery-Modellen erforderlich sind. Erweitern Sie den Abschnitt Erforderliche Berechtigungen, um die erforderlichen Berechtigungen anzuzeigen:
Erforderliche Berechtigungen
Die folgenden Berechtigungen sind erforderlich, um BigQuery-Modelle zu lesen und zu erstellen:
So lesen Sie Informationen aus Modellen:
bigquery.models.getData
Der Name eines vorhandenen Modells kann nicht geändert werden. Wenn Sie den Namen des Modells ändern müssen, führen Sie die Schritte zum Kopieren des Modells aus. Verwenden Sie dann den neuen Modellnamen, wenn Sie das Ziel im Kopiervorgang angeben.
Modelle kopieren
Zum Kopieren eines oder mehrerer Modelle aus einem Quell-Dataset in ein Ziel-Dataset haben Sie folgende Möglichkeiten:
Google Cloud Console verwenden
Den Befehl bq cp des bq-Befehlszeilentools verwenden
Das Kopieren von Modellen wird in der Google Cloud Console nicht unterstützt.
bq
Führen Sie den Befehl bq cp aus. Optionale Flags:
-f oder --force überschreiben ein vorhandenes Modell im Ziel-Dataset, ohne eine Bestätigung von Ihnen anzufordern.
-n oder --no_clobber geben folgende Fehlermeldung zurück, wenn das Modell im Ziel-Dataset vorhanden ist: '[PROJECT_ID]:[DATASET].[MODEL]'
already exists, skipping.
Wenn -n nicht angegeben ist, werden Sie standardmäßig gefragt, ob das Zielmodell ersetzt werden soll.
Wenn sich das Quell- oder Ziel-Dataset in einem anderen Projekt als Ihrem Standardprojekt befindet, fügen Sie die Projekt-ID im folgenden Format dem Dataset-Namen hinzu: PROJECT_ID:DATASET.
Geben Sie das Flag --location an und legen Sie als Wert Ihren Standort fest.
LOCATION: der Name Ihres Standorts. Das Flag --location ist optional. Wenn Sie BigQuery z. B. in der Region Tokio verwenden, können Sie für das Flag den Wert asia-northeast1 festlegen. Mit der Datei .bigqueryrc können Sie einen Standardwert für den Standort festlegen.
Eine vollständige Liste der Standorte finden Sie unter BigQuery-Standorte.
PROJECT_ID: Ihre Projekt-ID
DATASET: der Name des Quell- oder Ziel-Datasets.
SOURCE_MODEL: das Modell, das Sie kopieren.
DESTINATION_MODEL: der Name des Modells im Ziel-Dataset.
Beispiele:
Geben Sie den folgenden Befehl ein, um mydataset.mymodel in mydataset2 zu kopieren.
Beide Datasets befinden sich in Ihrem Standardprojekt und wurden am multiregionalen Standort US erstellt.
Geben Sie den folgenden Befehl ein, um mydataset.mymodel zu kopieren und ein Zielmodell mit demselben Namen zu überschreiben. Das Quell-Dataset befindet sich in Ihrem Standardprojekt. Das Ziel-Dataset befindet sich in myotherproject. Mit dem Kürzel -f wird das Zielmodell ohne Bestätigungsaufforderung überschrieben.
mydataset und myotherdatasetwurden am multiregionalen Standort US erstellt.
Geben Sie den folgenden Befehl ein, um mydataset.mymodel zu kopieren. Wenn das Ziel-Dataset ein Modell mit demselben Namen enthält, wird eine Fehlermeldung zurückgegeben. Das Quell-Dataset befindet sich in Ihrem Standardprojekt. Das Ziel-Dataset befindet sich in myotherproject. Mit dem Kürzel -n wird verhindert, dass ein Modell mit demselben Namen überschrieben wird.
Beide Datasets wurden am multiregionalen Standort US erstellt.
Geben Sie den folgenden Befehl ein, um mydataset.mymodel in mydataset2 zu kopieren und dem Modell mymodel2 einen neuen Namen zu geben. Beide Datasets befinden sich in Ihrem Standardprojekt.
Beide Datasets wurden in der Region asia-northeast1 erstellt.
Rufen Sie zum Kopieren eines Modells mithilfe der API die Methode bigquery.jobs.insert auf und konfigurieren Sie einen copy-Job. Geben Sie im Abschnitt jobReference der Jobressource Ihren Standort im Attribut location an.
Geben Sie die folgenden Werte in der Jobkonfiguration an:
sourceTable: enthält Informationen zum Modell, das kopiert werden soll.
destinationTable: enthält Informationen zum neuen Modell.
createDisposition: gibt an, ob das Modell erstellt werden soll, wenn es nicht vorhanden ist.
writeDisposition: gibt an, ob ein vorhandenes Modell überschrieben werden soll.
Modelle verschlüsseln
Weitere Informationen zur Verwendung eines vom Kunden verwalteten Verschlüsselungsschlüssels (CMEK) zum Verschlüsseln eines Modells finden Sie unter CMEK zum Schutz von BigQuery ML-Modellen verwenden.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-12-22 (UTC)."],[[["\u003cp\u003eThis document explains how to manage BigQuery ML models, focusing on copying and renaming models, as directly renaming existing models is not supported.\u003c/p\u003e\n"],["\u003cp\u003eTo read and create BigQuery models, users need the \u003ccode\u003ebigquery.models.getData\u003c/code\u003e and \u003ccode\u003ebigquery.models.create\u003c/code\u003e permissions, respectively, which are included in the \u003ccode\u003eroles/bigquery.dataEditor\u003c/code\u003e IAM role.\u003c/p\u003e\n"],["\u003cp\u003eModels can be copied to a destination dataset using the Google Cloud command-line tool (\u003ccode\u003ebq cp\u003c/code\u003e), API (\u003ccode\u003ejobs.insert\u003c/code\u003e), or client libraries, but not the Google Cloud console, and they must adhere to specific naming conventions.\u003c/p\u003e\n"],["\u003cp\u003eCopying models with the command-line tool (\u003ccode\u003ebq cp\u003c/code\u003e) supports options to overwrite (\u003ccode\u003e-f\u003c/code\u003e) or prevent overwriting (\u003ccode\u003e-n\u003c/code\u003e) existing models at the destination, but the \u003ccode\u003e--destination_kms_key\u003c/code\u003e flag is unsupported.\u003c/p\u003e\n"],["\u003cp\u003eWhile model renaming is not directly supported, it can be achieved by copying a model to a new destination and assigning it the desired name during the copy operation.\u003c/p\u003e\n"]]],[],null,["# Manage models\n=============\n\nThis document shows you how to manage BigQuery ML models, including\ncopying models and renaming models.\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to read and create BigQuery models,\n\nask your administrator to grant you the\n\n\n[BigQuery Data Editor](/iam/docs/roles-permissions/bigquery#bigquery.dataEditor) (`roles/bigquery.dataEditor`)\nIAM role on the project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains\n\nthe permissions required to read and create BigQuery models. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to read and create BigQuery models:\n\n- To read information from models: ` ``bigquery.models.getData`\n- To create models: ` ``bigquery.models.create`\n\n\nYou might also be able to get\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nRename models\n-------------\n\nYou cannot change the name of an existing model. If you need to\nchange the model's name, follow the steps to [copy the model](#copy-model). When\nyou specify the destination in the copy operation, use the new model name.\n\nCopy models\n-----------\n\nYou can copy one or more models from a source dataset to a destination dataset\nby:\n\n- Using the Google Cloud console.\n- Using the bq command-line tool's `bq cp` command.\n- Calling the [jobs.insert](/bigquery/docs/reference/rest/v2/jobs/insert) API method directly and configuring a [copy job](/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy) or by using the client libraries.\n\n### Limitations on copying models\n\nModel copy jobs are subject to the following limitations:\n\n- When you copy a model, the name of the destination model must adhere to the same naming conventions as when you [create a model](/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create#model_name).\n- Model copies are subject to BigQuery [limits](/bigquery/quotas#copy_jobs) on copy jobs.\n- Copying a model is not supported by the Google Cloud console.\n- Copying multiple source models in a single command is not supported.\n- When you copy a model by using the CLI, the `--destination_kms_key` flag is not supported.\n\n### Copy a model\n\nYou can copy a model by:\n\n- Using the command-line tool's `bq cp` command\n- Calling the [`jobs.insert`](/bigquery/docs/reference/rest/v2/jobs/insert) API method and configuring a [copy job](/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy) or by using the client libraries\n\nTo copy a model: \n\n### Console\n\nThe Google Cloud console does not support copying models.\n\n### bq\n\nIssue the `bq cp` command. Optional flags:\n\n- `-f` or `--force` overwrites an existing model in the destination dataset and doesn't prompt you for confirmation.\n- `-n` or `--no_clobber` returns the following error message if the model\n exists in the destination dataset: `'[PROJECT_ID]:[DATASET].[MODEL]'\n already exists, skipping`.\n\n If `-n` is not specified, the default behavior is to prompt you to choose\n whether to replace the destination model.\n\n| **Note:** The `--destination_kms_key` flag is not supported when you copy a model.\n\nIf the source or destination dataset is in a project other than your default\nproject, add the project ID to the dataset names in the following format:\n\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eDATASET\u003c/var\u003e.\n\nSupply the\n`--location` flag and set the value to your\n[location](/bigquery/docs/locations). \n\n```bash\nbq --location=LOCATION cp -f -n PROJECT_ID:DATASET.SOURCE_MODEL PROJECT_ID:DATASET.DESTINATION_MODEL\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the name of your location. The `--location` flag is optional. For example, if you are using BigQuery in the Tokyo region, you can set the flag's value to `asia-northeast1`. You can set a default value for the location using the [.bigqueryrc file](/bigquery/docs/bq-command-line-tool#setting_default_values_for_command-line_flags). For a full list of locations, see [BigQuery locations](/bigquery/docs/locations).\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n- \u003cvar translate=\"no\"\u003eDATASET\u003c/var\u003e: the name of the source or destination dataset.\n- \u003cvar translate=\"no\"\u003eSOURCE_MODEL\u003c/var\u003e: the model you're copying.\n- \u003cvar translate=\"no\"\u003eDESTINATION_MODEL\u003c/var\u003e: the name of the model in the destination dataset.\n\nExamples:\n\nEnter the following command to copy `mydataset.mymodel` to\n`mydataset2`.\n\nBoth datasets are in your default project and were\ncreated in the `US` multi-region location. \n\n```\nbq --location=US cp mydataset.mymodel mydataset2.mymodel\n```\n\nEnter the following command to copy `mydataset.mymodel` and to overwrite a\ndestination model with the same name. The source dataset is in your default\nproject. The destination dataset is in `myotherproject`. The `-f` shortcut is\nused to overwrite the destination model without a prompt.\n`mydataset` and\n`myotherdataset` were created in the `US` multi-region\nlocation. \n\n```\nbq --location=US cp -f mydataset.mymodel myotherproject:myotherdataset.mymodel\n```\n\nEnter the following command to copy `mydataset.mymodel` and to return an error\nif the destination dataset contains a model with the same name. The source\ndataset is in your default project. The destination dataset is in\n`myotherproject`. The `-n` shortcut is used to prevent overwriting a model with\nthe same name.\nBoth\ndatasets were created in the `US` multi-region location. \n\n```\nbq --location=US cp -n mydataset.mymodel myotherproject:myotherdataset.mymodel\n```\n\nEnter the following command to copy `mydataset.mymodel` to `mydataset2` and\nto rename the model `mymodel2`. Both datasets are in your default project.\nBoth datasets were created in the `asia-northeast1` region. \n\n```\nbq --location=asia-northeast1 cp mydataset.mymodel mydataset2.mymodel2\n```\n\n### API\n\nTo copy a model by using the API, call the\n[`bigquery.jobs.insert`](/bigquery/docs/reference/rest/v2/jobs/insert)\nmethod and configure a `copy` job. Specify your location in the\n`location` property in the `jobReference` section of the\n[job resource](/bigquery/docs/reference/rest/v2/jobs).\n\nYou must specify the following values in your job configuration: \n\n```\n\"copy\": {\n \"sourceTable\": { // Required\n \"projectId\": string, // Required\n \"datasetId\": string, // Required\n \"tableId\": string // Required\n },\n \"destinationTable\": { // Required\n \"projectId\": string, // Required\n \"datasetId\": string, // Required\n \"tableId\": string // Required\n },\n \"createDisposition\": string, // Optional\n \"writeDisposition\": string, // Optional\n },\n```\n\nWhere:\n\n- `sourceTable`: provides information about the model to be copied.\n- `destinationTable`: provides information about the new model.\n- [createDisposition](/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.create_disposition): specifies whether to create the model if it doesn't exist.\n- [writeDisposition](/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.write_disposition): specifies whether to overwrite an existing model.\n\nEncrypt models\n--------------\n\nFor more information about using a customer-managed encryption key (CMEK) to\nencrypt a model, see\n[Use CMEK to protect BigQuery ML models](/bigquery/docs/customer-managed-encryption#cmek-bqml).\n\nWhat's next\n-----------\n\n- For an overview of BigQuery ML, see [Introduction to BigQuery ML](/bigquery/docs/bqml-introduction).\n- To get started using BigQuery ML, see [Create machine learning models in BigQuery ML](/bigquery/docs/create-machine-learning-model).\n- To learn more about working with models, see:\n - [Get model metadata](/bigquery/docs/getting-model-metadata)\n - [List models](/bigquery/docs/listing-models)\n - [Update model metadata](/bigquery/docs/updating-model-metadata)\n - [Delete models](/bigquery/docs/deleting-models)\n - [Manage models with Vertex AI](/bigquery/docs/managing-models-vertex)"]]