Recupero di un modello
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Recupera una risorsa modello per un determinato ID modello.
Per saperne di più
Per la documentazione dettagliata che include questo esempio di codice, vedi quanto segue:
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis webpage provides code samples in Go, Java, Node.js, and Python to retrieve metadata for a specific BigQuery ML model using the corresponding client libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples demonstrate how to fetch model details by providing the project ID, dataset ID, and model ID, allowing users to access information such as the model's name and description.\u003c/p\u003e\n"],["\u003cp\u003eEach sample guides users on how to set up authentication using Application Default Credentials and directs them to the appropriate BigQuery API reference documentation for further information.\u003c/p\u003e\n"],["\u003cp\u003eThe content also suggests resources for learning about using client libraries, how to set up a given language, and where to search for more examples.\u003c/p\u003e\n"]]],[],null,["# Get a model resource for a given model ID.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Get model metadata](/bigquery/docs/getting-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 \t\"io\"\n\n \t\"cloud.google.com/go/bigquery\"\n )\n\n // printModelInfo demonstrates fetching metadata about a BigQuery ML model and printing some of\n // it to an io.Writer.\n func printModelInfo(w io.Writer, 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 \tmeta, err := client.Dataset(datasetID).Model(modelID).Metadata(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"couldn't retrieve metadata: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Got model '%q' with friendly name '%q'\\n\", modelID, meta.Name)\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 public class GetModel {\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_ID\";\n getModel(datasetName, modelName);\n }\n\n public static void getModel(String datasetName, String modelName) {\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.ModelId.html modelId = https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.ModelId.html.of(datasetName, modelName);\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);\n System.out.println(\"Model: \" + model.getDescription());\n\n System.out.println(\"Successfully retrieved model\");\n } catch (https://cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/com.google.cloud.bigquery.BigQueryException.html e) {\n System.out.println(\"Cannot retrieve model \\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 getModel() {\n // Retrieves model named \"my_existing_model\" in \"my_dataset\".\n\n /**\n * TODO(developer): Uncomment the following lines before running the sample\n */\n // const datasetId = \"my_dataset\";\n // const modelId = \"my_existing_model\";\n\n const dataset = bigquery.dataset(datasetId);\n const [model] = await dataset.https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html(modelId).get();\n\n console.log('Model:');\n console.log(https://cloud.google.com/nodejs/docs/reference/bigquery/latest/bigquery/dataset.html.metadata.modelReference);\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\n full_model_id = \"{}.{}.{}\".format(model.project, model.dataset_id, model.model_id)\n friendly_name = model.friendly_name\n print(\n \"Got model '{}' with friendly_name '{}'.\".format(full_model_id, friendly_name)\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)."]]