Modellbeschreibung aktualisieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Das Attribut "description" (Beschreibung) eines Modells für eine bestimmte Modell-ID aktualisieren.
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["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"]],[],[[["\u003cp\u003eThis page provides code samples in Go, Java, Node.js, and Python demonstrating how to update a model's description property in BigQuery.\u003c/p\u003e\n"],["\u003cp\u003eThe samples use the BigQuery client libraries and require users to set up Application Default Credentials for authentication.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample includes instructions on how to set up the environment before running the code, as well as references to the BigQuery API documentation for each language.\u003c/p\u003e\n"],["\u003cp\u003eThe process consists of fetching model metadata and updating the description accordingly, and then making an API request to modify it.\u003c/p\u003e\n"],["\u003cp\u003eA Google Cloud sample browser is included to search and filter code samples for other Google cloud products.\u003c/p\u003e\n"]]],[],null,["# Update a model description\n\nUpdate a model's description property for a given model ID.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Update model metadata](/bigquery/docs/updating-model-metadata)\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Go API\nreference documentation](https://godoc.org/cloud.google.com/go/bigquery).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import (\n \t\"context\"\n \t\"fmt\"\n\n \t\"cloud.google.com/go/bigquery\"\n )\n\n // updateModelDescription demonstrates fetching BigQuery ML model metadata and updating the\n // Description metadata.\n func updateModelDescription(projectID, datasetID, modelID string) error {\n \t// projectID := \"my-project-id\"\n \t// datasetID := \"mydataset\"\n \t// modelID := \"mymodel\"\n \tctx := context.Background()\n \tclient, err := bigquery.NewClient(ctx, projectID)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigquery.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \tmodel := client.Dataset(datasetID).Model(modelID)\n \toldMeta, err := model.Metadata(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"couldn't retrieve model metadata: %w\", err)\n \t}\n \tupdate := bigquery.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/index.html#cloud_google_com_go_bigquery_ModelMetadataToUpdate{\n \t\tDescription: \"This model was modified from a Go program\",\n \t}\n \tif _, err = model.Update(ctx, update, oldMeta.ETag); err != nil {\n \t\treturn fmt.Errorf(\"couldn't update model: %w\", err)\n \t}\n \treturn nil\n }\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Java API\nreference documentation](/java/docs/reference/google-cloud-bigquery/latest/overview).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryOptions.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Model.html;\n import com.google.cloud.bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.ModelId.html;\n\n // Sample to update description on a model\n public class UpdateModelDescription {\n\n public static void main(String[] args) {\n // TODO(developer): Replace these variables before running the sample.\n String datasetName = \"MY_DATASET_NAME\";\n String modelName = \"MY_MODEL_NAME\";\n String newDescription = \"A really great model.\";\n updateModelDescription(datasetName, modelName, newDescription);\n }\n\n public static void updateModelDescription(\n String datasetName, String modelName, String newDescription) {\n try {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html bigquery = https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryOptions.html.getDefaultInstance().getService();\n\n https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.Model.html model = bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html#com_google_cloud_bigquery_BigQuery_getModel_com_google_cloud_bigquery_ModelId_com_google_cloud_bigquery_BigQuery_ModelOption____(ModelId.of(datasetName, modelName));\n bigquery.https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQuery.html#com_google_cloud_bigquery_BigQuery_update_com_google_cloud_bigquery_DatasetInfo_com_google_cloud_bigquery_BigQuery_DatasetOption____(model.toBuilder().setDescription(newDescription).build());\n System.out.println(\"Model description updated successfully to \" + newDescription);\n } catch (https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html e) {\n System.out.println(\"Model description was not updated \\n\" + e.toString());\n }\n }\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Node.js API\nreference documentation](https://googleapis.dev/nodejs/bigquery/latest/index.html).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n // Import the Google Cloud client library\n const {BigQuery} = require('https://cloud.google.com/nodejs/docs/reference/bigquery/latest/overview.html');\n const bigquery = new https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/bigquery.html();\n\n async function updateModel() {\n // Updates a model's metadata.\n\n /**\n * TODO(developer): Uncomment the following lines before running the sample\n */\n // const datasetId = \"my_dataset\";\n // const modelId = \"my__model\";\n\n const metadata = {\n description: 'A really great model.',\n };\n\n const dataset = bigquery.dataset(datasetId);\n const [apiResponse] = await dataset.https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html(modelId).setMetadata(metadata);\n const newDescription = apiResponse.description;\n\n console.log(`${modelId} description: ${newDescription}`);\n }\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Python API\nreference documentation](/python/docs/reference/bigquery/latest).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n\n from google.cloud import https://cloud.google.com/python/docs/reference/bigquery/latest/\n\n # Construct a BigQuery client object.\n client = https://cloud.google.com/python/docs/reference/bigquery/latest/.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html()\n\n # TODO(developer): Set model_id to the ID of the model to fetch.\n # model_id = 'your-project.your_dataset.your_model'\n\n model = client.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html#google_cloud_bigquery_client_Client_get_model(model_id) # Make an API request.\n model.description = \"This model was modified from a Python program.\"\n model = client.https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.client.Client.html#google_cloud_bigquery_client_Client_update_model(model, [\"description\"]) # Make an API request.\n\n full_model_id = \"{}.{}.{}\".format(model.project, model.dataset_id, model.model_id)\n print(\n \"Updated model '{}' with description '{}'.\".format(\n full_model_id, model.description\n )\n )\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigquery)."]]