相关文章推荐
爱跑步的凉面  ·  Mockito: ...·  1 月前    · 
憨厚的烈马  ·  WPF ...·  5 月前    · 

Hello,

I am running the Azure ML Python example from here, https://learn.microsoft.com/en-us/python/api/overview/azure/ml/?view=azure-ml-py#run

Specifically this section of the example;

from azureml.core.experiment import Experiment  
from azureml.core import ScriptRunConfig  
script_run_config = ScriptRunConfig(source_directory=os.getcwd(), script="train.ipynb", run_config=compute_config)  
experiment = Experiment(workspace=ws, name="compute_target_test")  
run = experiment.submit(config=script_run_config)  
run.wait_for_completion(show_output=True)  

When I execute the above code I receive the error;
message': "User program failed with NameError: name 'true' is not defined"

The log file gives the following details;

File "train.ipynb", line 67, in <module>
"notebookHasBeenCompleted": true
NameError: name 'true' is not defined

The problem is the train.ipynb file does not contain 67 lines.

Could anyone provide some assistance as to how to resolve this.

Thanks.

With the help of this post, https://learn.microsoft.com/en-us/answers/questions/674712/nameerror-when-trying-to-run-an-scriptrunconfig-in.html
I have been able to resolve the problem.

The issue is the script parameter in the ScriptRunConfig class must be a *.py file and not a *.ipynb file. After changing the extension to *.py and downloading the Notebook the following JSON object will be visible;

"microsoft": {  
          "host": {  
            "AzureML": {  
              "notebookHasBeenCompleted": true  

After changing the "true" value to "True" the script will execute successfully.

@Graham Benson Thanks for the question. We are able to run successfully with out an error as shown below.

Here is link to the sample for using the environments.

https://github.com/Azure/MachineLearningNotebooks/tree/master/how-to-use-azureml/training/using-environments

@Ramr-msft

Having solved the above issue, I am now receiving the warning;

"Warning: you have pip-installed dependencies in your environment file, but you do not list pip itself as one of your conda dependencies...."

I am using the curated environment, AzureML-sklearn-0.24-ubuntu18.04-py37-cpu which contains the packages;

  • scikit-learn==0.24.1
  • numpy>=1.16.0
  • pandas~=1.1.x
  • Following is the Notebook code;

        from azureml.core import Workspace, Environment      
        from azureml.core import ScriptRunConfig, Experiment  
        ws = Workspace.from_config()  
        myenv = Environment.get(workspace=ws, name="AzureML-sklearn-0.24-ubuntu18.04-py37-cpu")     
        exp = Experiment(name="myexp", workspace = ws)  
        # Instantiate environment  
        myenv = Environment(name="myenv")  
        # Add training script to run config  
        runconfig = ScriptRunConfig(source_directory=".", script="train.py")  
        # Attach compute target to run config  
        runconfig.run_config.target = "local"  
        # Attach environment to run config  
        runconfig.run_config.environment = myenv  
        # Submit run   
        run = exp.submit(runconfig)  
    

    The train.py script is taken from the example, here https://learn.microsoft.com/en-us/python/api/overview/azure/ml/?view=azure-ml-py#run

    ------------------------------ train.py script ----------------------------------  
    # train.py  
    from sklearn import svm  
    import numpy as np  
    import joblib  
    import os  
    # customer ages  
    X_train = np.array([50, 17, 35, 23, 28, 40, 31, 29, 19, 62])  
    X_train = X_train.reshape(-1, 1)  
    # churn y/n  
    y_train = ["yes", "no", "no", "no", "yes", "yes", "yes", "no", "no", "yes"]  
    clf = svm.SVC(gamma=0.001, C=100.)  
    clf.fit(X_train, y_train)  
    os.makedirs("outputs", exist_ok=True)  
    joblib.dump(value=clf, filename="outputs/churn-model.pkl")  
    ------------------------------ train.py script ----------------------------------  
    

    Can you please assist with the above. Why would I receive the error message when the environment being used is a Microsoft curated environment?

    Thank you