nerdexam
Microsoft

DP-100 · Question #301

You have a Jupyter Notebook that contains Python code that is used to train a model. You must create a Python script for the production deployment. The solution must minimize code maintenance. Which t

The correct answer is A. Refactor the Jupyter Notebook code into functions C. Define a main() function in the Python script. The two correct actions are (A) Refactor the Jupyter Notebook code into functions and (C) Define a main() function in the Python script. Refactoring into functions organizes the logic into reusable, testable units and removes the cell-by-cell execution model of notebooks. Definin

Train and deploy models

Question

You have a Jupyter Notebook that contains Python code that is used to train a model. You must create a Python script for the production deployment. The solution must minimize code maintenance. Which two actions should you perform? Each correct answer presents part of the solution. NOTE: Each correct selection is worth one point.

Options

  • ARefactor the Jupyter Notebook code into functions
  • BSave each function to a separate Python file
  • CDefine a main() function in the Python script
  • DRemove all comments and functions from the Python script

How the community answered

(45 responses)
  • A
    82% (37)
  • B
    7% (3)
  • D
    11% (5)

Explanation

The two correct actions are (A) Refactor the Jupyter Notebook code into functions and (C) Define a main() function in the Python script. Refactoring into functions organizes the logic into reusable, testable units and removes the cell-by-cell execution model of notebooks. Defining a main() function and guarding it with 'if name == "main":' is standard Python script structure, enabling the script to be run directly or imported as a module. Saving each function to a separate file (B) would fragment the code unnecessarily and increase maintenance. Removing all comments and functions (D) would produce unreadable, unmaintainable code.

Topics

#Production deployment#Code refactoring#Code organization#Python scripting best practices

Community Discussion

No community discussion yet for this question.

Full DP-100 Practice