Databricks Machine Learning Associate Question 640
Select 4You have trained a machine learning model to predict house prices and saved it as model.pkl. Your task is to use pandas for batch inference on a new dataset new_data.csv, which contains features but no target values. Which of the following steps are required to perform batch inference using pandas in this scenario?
- A
Load the pre-trained model using a library like joblib or pickle.
- B
Load the new dataset using pandas and preprocess it to match the training data format.
- C
Directly call the
predictmethod on the pandas DataFrame without further preparation. - D
Convert the pandas DataFrame to a NumPy array or similar format before passing it to the model's
predictmethod. - E
Save the prediction results back to a pandas DataFrame or CSV file for further analysis.
Show answer and explanation
Correct answers: A, B, D, E
Explanation
To perform batch inference using pandas, you need to load the pre-trained model and the new dataset, preprocess the dataset to match the training data format, and convert the DataFrame to a compatible format (like a NumPy array) before passing it to the model's predict method. Finally, the predictions should be saved back to a pandas DataFrame or a CSV file for further analysis. Directly using the DataFrame without conversion would result in an error in most cases.
- A. Correct.
Correct. The pre-trained model must be loaded using joblib or pickle to perform inference.
- B. Correct.
Correct. The new dataset must be loaded and preprocessed to match the format used during model training.
- C. Incorrect.
Incorrect. A pandas DataFrame cannot always directly be passed to the model's
predictmethod; it often requires conversion to a NumPy array or similar format. - D. Correct.
Correct. Most machine learning models require the input data to be in a NumPy array or similar format for predictions.
- E. Correct.
Correct. After generating predictions, saving them back to a pandas DataFrame or CSV file is a crucial step to make the results accessible for further use.