Databricks Machine Learning Professional Question 36
Select 3You are building a machine learning model in Databricks and want to ensure that the model's input schema is clearly defined and that it can be easily validated during deployment. You decide to log a model using MLflow with a model signature and input example. Which of the following steps are required to correctly log the model with these features?
- A
Generate a sample input DataFrame and pass it to the
input_exampleparameter when callingmlflow.log_model(). - B
Use the
infer_signature()function to automatically infer the model signature from a sample input and output. - C
Log the model signature and input example as separate artifacts in MLflow using
mlflow.log_artifact(). - D
Ensure the
input_examplematches the schema defined in the model signature. - E
Skip defining an input example if the model signature is already defined.
Show answer and explanation
Correct answers: A, B, D
Explanation
To log a model with MLflow that includes a model signature and input example, you must define both correctly. The model signature provides the schema for the model's inputs and outputs, while the input example demonstrates a valid input instance. These features ensure that the model can be validated and used seamlessly during deployment. The infer_signature() function simplifies the process of defining the signature, and the input_example must align with the signature for consistency. Logging these directly with mlflow.log_model() is the correct approach.
- A. Correct.
Correct: Generating a sample input DataFrame and passing it to the
input_exampleparameter is necessary to log an input example for the model in MLflow. This helps in validating inputs during deployment. - B. Correct.
Correct: Using the
infer_signature()function is the recommended way to define the model signature, as it infers the schema of the inputs and outputs automatically from sample data. - C. Incorrect.
Incorrect: While artifacts can be logged using
mlflow.log_artifact(), the model signature and input example should be logged directly with the model usingmlflow.log_model(). - D. Correct.
Correct: The
input_examplemust match the schema defined in the model signature to ensure consistency and prevent validation errors during deployment. - E. Incorrect.
Incorrect: Skipping the input example is not recommended, even if the model signature is defined, as the input example provides additional information for validating inputs during deployment.