Azure ML AutoML Client

1.62.0 · active · verified Thu Apr 16

The `azureml-train-automl-client` library is a core component of the Azure Machine Learning Python SDK v1, enabling users to automatically find the best machine learning model and its hyperparameters for various tasks like classification, regression, and forecasting. As of version 1.62.0, it supports Python versions >=3.8 and <3.12. Its release cadence is tightly coupled with the broader Azure ML SDK v1, which typically saw monthly or bi-monthly updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `AutoMLConfig` for a classification task. It first attempts to load an existing Azure ML Workspace using environment variables. It then creates an `Experiment` object and provides a template for configuring and submitting an AutoML run. Note that for actual execution, you must provide a valid `training_data` `Dataset` object, `label_column_name`, and a `compute_target`.

import os
from azureml.core import Workspace, Experiment, Dataset
from azureml.train.automl import AutoMLConfig

# Placeholder for Azure ML Workspace details
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'your_subscription_id')
resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'your_resource_group')
workspace_name = os.environ.get('AZURE_WORKSPACE_NAME', 'your_workspace_name')

# Ensure these are replaced with actual valid values or environment variables
if 'your_' in subscription_id or 'your_' in resource_group or 'your_' in workspace_name:
    print("WARNING: Please set AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP, AZURE_WORKSPACE_NAME environment variables ")
    print("or replace placeholder values in the quickstart code for actual execution.")
    # Exit or use dummy data for demonstration if not intended to run live
    exit(1)

try:
    ws = Workspace.get(name=workspace_name,
                       subscription_id=subscription_id,
                       resource_group=resource_group)
    print(f"Workspace '{ws.name}' loaded successfully.")
except Exception as e:
    print(f"Could not load workspace. Error: {e}")
    # Handle workspace creation or authentication error
    exit(1)

# Create an experiment
experiment = Experiment(workspace=ws, name='automl-quickstart-experiment')

# Example: Load a registered dataset (replace with your actual dataset)
# For a real run, you'd register a dataset or use a local one.
# This is a dummy to make the code runnable for structure.
# In a real scenario, you'd load your training data like:
# training_data = Dataset.get_by_name(ws, name='my_training_dataset')

# Create a dummy AutoMLConfig (requires actual data and compute for a real run)
automl_config = AutoMLConfig(
    task='classification',
    primary_metric='accuracy',
    experiment_timeout_minutes=30,
    training_data=None, # Replace with your actual Dataset object, e.g., training_data
    label_column_name='target_column', # Replace with your target column name
    compute_target='cpu-cluster', # Replace with your compute target name
    enable_early_stopping=True,
    n_cross_validations=5,
    max_concurrent_iterations=2,
    max_cores_per_iteration=-1, # Use all available cores
    # Additional settings like featurization, blacklisting, etc. can be added
)

print("AutoMLConfig created. To run, you would submit it:")
print("run = experiment.submit(automl_config, show_output=True)")
print("run.wait_for_completion(show_output=True)")
# To run the experiment:
# run = experiment.submit(automl_config, show_output=True)
# run.wait_for_completion(show_output=True)

view raw JSON →