建立表格預測訓練管道
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 create_training_pipeline 方法,建立表格預測訓練管道。
程式碼範例
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["# Create a training pipeline for tabular forecasting\n\nCreates a training pipeline for tabular forecasting using the create_training_pipeline method.\n\nCode sample\n-----------\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI Python API\nreference documentation](/python/docs/reference/aiplatform/latest).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import aiplatform\n from google.protobuf import json_format\n from google.protobuf.struct_pb2 import Value\n\n\n def create_training_pipeline_tabular_forecasting_sample(\n project: str,\n display_name: str,\n dataset_id: str,\n model_display_name: str,\n target_column: str,\n time_series_identifier_column: str,\n time_column: str,\n time_series_attribute_columns: str,\n unavailable_at_forecast: str,\n available_at_forecast: str,\n forecast_horizon: int,\n location: str = \"us-central1\",\n api_endpoint: str = \"us-central1-aiplatform.googleapis.com\",\n ):\n # The AI Platform services require regional API endpoints.\n client_options = {\"api_endpoint\": api_endpoint}\n # Initialize client that will be used to create and send requests.\n # This client only needs to be created once, and can be reused for multiple requests.\n client = aiplatform.gapic.https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform_v1.services.pipeline_service.PipelineServiceClient.html(client_options=client_options)\n # set the columns used for training and their data types\n transformations = [\n {\"auto\": {\"column_name\": \"date\"}},\n {\"auto\": {\"column_name\": \"state_name\"}},\n {\"auto\": {\"column_name\": \"county_fips_code\"}},\n {\"auto\": {\"column_name\": \"confirmed_cases\"}},\n {\"auto\": {\"column_name\": \"deaths\"}},\n ]\n\n data_granularity = {\"unit\": \"day\", \"quantity\": 1}\n\n # the inputs should be formatted according to the training_task_definition yaml file\n training_task_inputs_dict = {\n # required inputs\n \"targetColumn\": target_column,\n \"timeSeriesIdentifierColumn\": time_series_identifier_column,\n \"timeColumn\": time_column,\n \"transformations\": transformations,\n \"dataGranularity\": data_granularity,\n \"optimizationObjective\": \"minimize-rmse\",\n \"trainBudgetMilliNodeHours\": 8000,\n \"timeSeriesAttributeColumns\": time_series_attribute_columns,\n \"unavailableAtForecast\": unavailable_at_forecast,\n \"availableAtForecast\": available_at_forecast,\n \"forecastHorizon\": forecast_horizon,\n }\n\n training_task_inputs = json_format.ParseDict(training_task_inputs_dict, Value())\n\n training_pipeline = {\n \"display_name\": display_name,\n \"training_task_definition\": \"gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_forecasting_1.0.0.yaml\",\n \"training_task_inputs\": training_task_inputs,\n \"input_data_config\": {\n \"dataset_id\": dataset_id,\n \"fraction_split\": {\n \"training_fraction\": 0.8,\n \"validation_fraction\": 0.1,\n \"test_fraction\": 0.1,\n },\n },\n \"model_to_upload\": {\"display_name\": model_display_name},\n }\n parent = f\"projects/{project}/locations/{location}\"\n response = client.https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform_v1.services.pipeline_service.PipelineServiceClient.html#google_cloud_aiplatform_v1_services_pipeline_service_PipelineServiceClient_create_training_pipeline(\n parent=parent, training_pipeline=training_pipeline\n )\n print(\"response:\", response)\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=aiplatform)."]]