Lesson 1 of 2 Automated ML and Hyperparameter Tuning

Automated Machine Learning

This lesson explains what automated ML tries, which tasks it supports, how a job is configured and limited, how the primary metric is chosen, and what data guardrails report.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe what automated ML searches over.
  • Identify the data and compute each task type needs.
  • Choose a primary metric for imbalanced data.
  • Explain the limits that control cost.

What automated ML does

Choosing an algorithm, preparing features and tuning hyperparameters can take weeks of trial and error. Automated ML runs that search automatically: it generates trials that combine featurization steps with algorithms and hyperparameter values, trains and validates each one, and ranks them by a chosen metric. It usually finishes with ensemble models that combine the best trials.

The result is a ranked list of models, each tracked with MLflow, and a best model that can be registered and deployed like any other. Automated ML is particularly useful to establish a strong baseline quickly, to explore a new dataset, and for teams with limited data science capacity. A data scientist can then decide whether a custom model is worth building to beat it.

Supported tasks

Automated ML supports tabular, computer vision and natural language processing (NLP) tasks. The task determines the algorithms tried, the metrics available and the data format required.

TaskDataExample primary metrics
Classificationmltable with a target columnAUC_weighted, accuracy, average_precision_score_weighted, norm_macro_recall
Regressionmltable with a numeric targetnormalized_root_mean_squared_error, r2_score, spearman_correlation
Forecastingmltable with a time column and optional series IDsnormalized_root_mean_squared_error, normalized_mean_absolute_error
Image classification and object detectionmltable pointing to labelled imagesaccuracy, mean_average_precision
Text classification and named entity recognitionmltable with text and labelsaccuracy

Computer vision and NLP tasks train deep learning models and require GPU compute. Forecasting adds settings such as the forecast horizon, the time column and the time series identifier columns.

Configuring a job

An automated ML job names the task, the training data, the target column, the primary metric, the compute, and settings for validation, featurization and limits. The following example uses the Python SDK.

from azure.ai.ml import automl, Input

job = automl.classification(
    compute="cpu-cluster",
    experiment_name="churn-automl",
    training_data=Input(type="mltable", path="azureml:churn-table:2"),
    target_column_name="churned",
    primary_metric="AUC_weighted",
    n_cross_validations=5,
    enable_model_explainability=True,
)
job.set_limits(timeout_minutes=90, trial_timeout_minutes=15, max_trials=40,
               max_concurrent_trials=4, enable_early_termination=True)
job.set_training(blocked_training_algorithms=["KNN"])
returned = ml_client.jobs.create_or_update(job)

The same job can be written in YAML with type: automl and task: classification. Validation uses a separate validation dataset, a percentage split, or k-fold cross-validation; cross-validation gives more reliable rankings on small datasets at the cost of more compute.

Choosing the primary metric

The primary metric decides which model wins, so it must reflect what the business cares about and suit the data. Accuracy is misleading on imbalanced classes: a fraud dataset with 1 percent fraud gives 99 percent accuracy to a model that never predicts fraud. AUC_weighted and average_precision_score_weighted measure ranking quality and are better for imbalanced data; norm_macro_recall rewards finding the minority class.

For regression, normalized_root_mean_squared_error penalizes large errors, normalized_mean_absolute_error treats all errors equally, and r2_score measures explained variance. The primary metric also decides how the final ensemble is weighted, so changing it can change the best model completely.

Featurization and guardrails

By default (mode="auto"), automated ML prepares features itself: it imputes missing values, encodes categorical columns, scales numeric columns, and extracts features from dates and text. Featurization can be turned off, or customized per column, for example to set a column's type or imputation method, or to drop a column. The same featurization is saved with the model and applied at inference.

  • Class balancing detection warns when the target is imbalanced.
  • Missing feature values imputation reports which columns were imputed and how.
  • High cardinality feature detection flags columns with too many distinct values to encode usefully.

These data guardrails appear in the job's results and should be read before trusting the best model, because they often reveal data problems, such as an identifier column being used as a feature, that inflate validation scores.

Limits and cost control

An automated ML job can run hundreds of trials, so limits are essential. timeout_minutes caps the whole job, trial_timeout_minutes caps each trial, max_trials caps the number of trials, and max_concurrent_trials sets how many run at once, which should not exceed the cluster's maximum nodes. enable_early_termination stops the job when the score stops improving.

Blocked algorithms remove model types that are known to be unsuitable, such as slow algorithms for large data, and allowed algorithms restrict the search to a list. Each restriction shortens the search and lowers cost, at the risk of missing a good model.

Worked example

A misleading best model

An automated ML classification job for loan default, where 3 percent of loans default, reports a best model with 97.1 percent accuracy. When it is tested, it predicts that no loan defaults. The job used accuracy as the primary metric, and the data guardrails show a class balancing warning.

Accuracy rewards predicting the majority class on imbalanced data, so the search optimized for the wrong goal. Rerun the job with AUC_weighted or average_precision_score_weighted as the primary metric, which measure how well the model ranks defaulters above non-defaulters, and consider norm_macro_recall if finding defaults matters most. Review the guardrails and the confusion matrix of the new best model before registering it.

Increasing max_trials would search longer for the same wrong objective. Blocking the algorithm that won would only change which model predicts the majority class. Disabling featurization does not address class imbalance.

Check yourself

Only 2 percent of transactions are fraudulent. Why is accuracy a poor primary metric for automated ML here?

Show answer

A model that predicts "not fraud" for everything is 98 percent accurate. AUC_weighted or average_precision_score_weighted reflect how well the rare class is ranked.

Exam Tips

Remember for the exam

  • Automated ML tries featurization, algorithms and hyperparameters, ranked by a primary metric.
  • Tabular tasks need mltable data; vision and NLP tasks need GPU compute.
  • Use AUC_weighted or average precision for imbalanced classes, not accuracy.
  • Read the data guardrails; set timeouts, trial limits and concurrency to control cost.