Databricks Machine Learning Associate Question 291
Select 3You are tasked with building a machine learning model using Spark ML to predict house prices. After splitting the dataset into training and test sets, you decide to evaluate the model's performance using the Root Mean Squared Error (RMSE). Which of the following steps are necessary to correctly train and evaluate the model?
- A
Fit the model on the training dataset using the
fit()method. - B
Transform the test dataset using the model's
transform()method to generate predictions. - C
Directly compute RMSE on the training dataset without using the test dataset.
- D
Use the
RegressionEvaluatorfrom Spark ML to compute RMSE on the predictions. - E
Combine the training and test datasets before fitting the model to improve accuracy.
Show answer and explanation
Correct answers: A, B, D
Explanation
To properly train and evaluate a machine learning model in Spark ML, you must first train the model using the fit() method on the training dataset. Then, you should use the trained model's transform() method to generate predictions on the test dataset. Finally, evaluation metrics like RMSE should be computed using tools such as RegressionEvaluator on the test dataset's predictions. Combining training and test datasets or using the training dataset directly for evaluation would result in biased and unreliable results.
- A. Correct.
Correct: The
fit()method is used to train the model on the training dataset, which is a required step in Spark ML. - B. Correct.
Correct: The
transform()method is used to generate predictions on the test dataset, which are then used for evaluation. - C. Incorrect.
Incorrect: RMSE should be computed on the test dataset predictions, not directly on the training dataset, as this would lead to overfitting and incorrect evaluation.
- D. Correct.
Correct: The
RegressionEvaluatoris the proper tool in Spark ML to calculate metrics like RMSE on the predictions. - E. Incorrect.
Incorrect: Combining training and test data before fitting the model violates the principle of having separate datasets for training and evaluation.