DP-100 practice question 11 of 35

You plan to use a Python script to run an Azure Machine Learning experiment. The script creates a reference to the experiment run context, loads data…

Full set: 506 questions

Domain Run experiments and train models

Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution. After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen. You plan to use a Python script to run an Azure Machine Learning experiment. The script creates a reference to the experiment run context, loads data from a file, identifies the set of unique values for the label column, and completes the experiment run: from azureml.core import Run import pandas as pd run = Run.get_context() data = pd.read_csv('data.csv') label_vals = data['label'].unique() # Add code to record metrics here run.complete() The experiment must record the unique labels in the data as metrics for the run that can be reviewed later. You must add code to the script to record the unique label values as run metrics at the point indicated by the comment. Solution: Replace the comment with the following code: run.log_table('Label Values', label_vals) Does the solution meet the goal?
Answer options
A: Yes
B: No Correct answer
Correct Answer:
B. No
Explanation

The solution is incorrect because the code provided will fail. The run.logtable() method expects the second argument (value) to be a dictionary, where each key is a column name and the corresponding value is a list of the data for that column. The variable labelvals, created by data['label'].unique(), is a NumPy array, not a dictionary. Passing a NumPy array directly to run.logtable() results in a TypeError because the argument type is invalid. The code will not execute successfully and therefore will not log the required metrics.

Why Incorrect

A. Yes: This is incorrect because the provided code is syntactically wrong for the run.logtable method. The method's signature requires a dictionary for the value parameter, but a NumPy array is supplied, which will cause an error.

References

1. Microsoft Azure Machine Learning SDK Documentation: The official documentation for the azureml.core.Run class specifies the signature for the logtable method.

Source: Microsoft Docs

azureml.core.Run class.

Reference: The method signature is defined as logtable(name: str

value: dict

description: str = ''). This explicitly shows that the value parameter must be a dictionary (dict).

Link: https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#azureml-core-run-log-table?view=azure-ml-py#azureml-core-run-log-table)

2. Pandas Library Documentation: The documentation for the pandas.unique function confirms the data type of the returned object.

Source: pandas development team

pandas 2.2.2 documentation.

Reference: The pandas.unique function "Return[s] unique values of Series object... The unique values are returned in order of appearance. Hash table-based unique

therefore does NOT sort. Returns: numpy.ndarray". This confirms labelvals is a NumPy array.

Link: https://pandas.pydata.org/docs/reference/api/pandas.unique.html

Scroll to Top