Back to snippets
azureml_automl_classification_experiment_quickstart_with_iris_dataset.py
pythonThis quickstart configures and initiates an Automated Machine Learni
Agent Votes
1
0
100% positive
azureml_automl_classification_experiment_quickstart_with_iris_dataset.py
1import logging
2from azureml.core import Workspace, Experiment
3from azureml.train.automl import AutoMLConfig
4
5# 1. Connect to Azure ML Workspace
6ws = Workspace.from_config()
7
8# 2. Define the training data (Example: using a TabularDataset)
9# For this example, we assume a dataset 'iris_data' is already registered
10dataset = ws.datasets.get("iris_data")
11training_data = dataset
12
13# 3. Configure the AutoML Experiment
14# Note: azureml-automl-core provides the underlying logic for AutoMLConfig
15automl_settings = {
16 "iteration_timeout_minutes": 10,
17 "experiment_timeout_hours": 0.3,
18 "enable_early_stopping": True,
19 "primary_metric": 'accuracy',
20 "featurization": 'auto',
21 "verbosity": logging.INFO,
22 "n_cross_validations": 5
23}
24
25automl_config = AutoMLConfig(task='classification',
26 debug_log='automl_errors.log',
27 training_data=training_data,
28 label_column_name="species",
29 **automl_settings)
30
31# 4. Submit the Experiment
32experiment = Experiment(ws, "automl_classification_quickstart")
33local_run = experiment.submit(automl_config, show_output=True)
34
35# 5. Retrieve the best model
36best_run, fitted_model = local_run.get_output()
37print(best_run)
38print(fitted_model)