Create a training pipeline for tabular forecasting
Stay organized with collections
Save and categorize content based on your preferences.
Creates a training pipeline for tabular forecasting using the create_training_pipeline method.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","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)."]]