Databricks Machine Learning Associate Question 639
Select 4You have trained a machine learning model in Databricks and saved it as a serialized .pkl file. Now, you want to perform batch inference on a large CSV file containing new data using pandas. Which of the following steps are necessary to correctly perform batch inference?
- A
Load the new data into a pandas DataFrame.
- B
Deserialize the model using pandas' built-in
read_pickle()method. - C
Apply the model's
predict()method to the DataFrame. - D
Save the inference results to a new CSV file using pandas'
to_csv()method. - E
Ensure the input data's feature columns match the model's training feature columns before inference.
Show answer and explanation
Correct answers: A, C, D, E
Explanation
To perform batch inference with pandas, you first load the new data into a pandas DataFrame. Then, you need to deserialize the model using a library like pickle or joblib (not pandas' read_pickle()). Afterward, use the model's predict() method on the DataFrame to generate predictions. Finally, ensure the input columns match the training features, and save the predictions to a file using pandas' to_csv() for further use. This process ensures accurate and functional batch inference.
- A. Correct.
Correct: Loading the new data into a pandas DataFrame is the first step to prepare it for batch inference.
- B. Incorrect.
Incorrect: While pandas has a
read_pickle()method, it is not typically used to load machine learning models. Instead, libraries likejobliborpickleare used for model deserialization. - C. Correct.
Correct: The
predict()method of the deserialized model is used to generate predictions for the input data. - D. Correct.
Correct: Saving the inference results to a CSV file using
to_csv()is a common step to persist the batch inference results. - E. Correct.
Correct: Ensuring the feature columns match is critical because the model expects the same input structure it was trained on.