how and where to edit enable_early_stopping = False in AutoMLConfig for notebook/python SDK runs

Paromita Biswas 0 Reputation points
2024-06-25T15:15:15.7666667+00:00

how and where to edit enable_early_stopping = False in AutoMLConfig for notebook/python SDK runs

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,685 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,570 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 6,501 Reputation points
    2024-06-25T16:29:25.2566667+00:00

    Hello Paromita Biswas,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    I understand that you have a challenge to enable_early_stopping = False, in AutoMLConfig for notebook/python SDK runs. Also, you would like to know how and where to solve this issue.

    Solution

    There are two things based on practice, if you are using old notebook and Python SDK and it requested you to create AutoMLConfig. You will create this by yourself and ensure you are able to enable_early_stopping = False This is how to do it:

    # Import necessary Libraries
    from azureml.core.workspace import Workspace
    from azureml.train.automl import AutoMLConfig
    from azureml.core.experiment import Experiment
    # Load the workspace
    ws = Workspace.from_config()
    # Create AutoMLConfig
    automl_config = AutoMLConfig(
        task='classification',
        primary_metric='accuracy',
        experiment_timeout_minutes=30,
        training_data=train_data,  # Replace with your dataset
        label_column_name='target',  # Replace with your label column
        n_cross_validations=5,
        enable_early_stopping=False,
        # Add other parameters as needed
    )
    # Run the experiment
    experiment = Experiment(ws, 'your_experiment_name')
    run = experiment.submit(automl_config, show_output=True)
    

    Secondly, if you have updated version, AutoMLConfig has been replaced with a new configuration object in the Azure Machine Learning Python SDK, specifically AutoMLJob within the azure.ai.ml package. Especially, in a Jupyter notebook or any Python environment, you can disable early stopping with the new AutoMLJob class by following these steps:

    1. Ensure you have the latest Azure ML SDK installed using bash: pip install azure-ai-ml
    2.    # Import necessary Libraries
         from azure.ai.ml import automl
         from azure.ai.ml.entities import AutomlClassificationJob
         from azure.ai.ml import MLClient
         from azure.identity import DefaultAzureCredential
         # Load the workspace
         ml_client = MLClient(
             DefaultAzureCredential(),
             subscription_id="your-subscription-id",
             resource_group_name="your-resource-group",
             workspace_name="your-workspace-name"
         )
         # Create AutoML Job Configuration
         classification_job = automl.classification(
             compute="your-compute-cluster",
             experiment_name="your-experiment-name",
             training_data="path/to/your/training/data",
             label_column_name="your-label-column",
             primary_metric="accuracy",
             n_cross_validations=5,
             enable_early_stopping=False,  # Disable early stopping
             # Add other necessary parameters
         )
         # Submit the job
         returned_job = ml_client.jobs.create_or_update(classification_job)
         ml_client.jobs.stream(returned_job.name)
      

    References

    Kindly read more from the additional resources available by the right side of this page, and utilize the following links for more details.

    Source: AutoMLConfig class. Accessed, 6/25/2024.

    Source: Automated Machine Learning for Classification -Notebook examples. Accessed, 6/25/2024.

    Source: Automated ML Jobs. Accessed, 6/25/2024.

    Source: Azure ML SDK Documentation for azure-ai-ml package. Accessed, 6/25/2024.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam