Databricks Certified Machine Learning Associate · Free Practice Question Medium
Question 16
A data scientist is working on a regression task in Databricks using Spark MLlib. They have computed predictions and true labels stored in the DataFrame regression_preds_df with the following schema:
- prediction DOUBLE
- label DOUBLE
Which of the following code blocks can be used to compute the mean absolute error (MAE) for the regression model?
-
A
mae_evaluator = RegressionEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")mae = mae_evaluator.evaluate(regression_preds_df) -
B
mae_evaluator = MulticlassClassificationEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")mae = mae_evaluator.evaluate(regression_preds_df) -
C
mae_evaluator = BinaryClassificationEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")mae = mae_evaluator.evaluate(regression_preds_df) -
D
mae_evaluator = RegressionSummarizer(predictionCol="prediction", labelCol="label", metricName="mae")mae = mae_evaluator.evaluate(regression_preds_df)
Reveal correct answer
Correct answer: A
Explanation
The correct code block to compute the Mean Absolute Error (MAE) for the regression model is:
- mae_evaluator = RegressionEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
- mae = mae_evaluator.evaluate(regression_preds_df)
Explanation:
Option A (
RegressionEvaluatorwithmetricName="mae") correctly specifies theRegressionEvaluatorfor the regression task and uses the Mean Absolute Error (MAE) as the evaluation metric.Option B (
MulticlassClassificationEvaluatorwithmetricName="mae") is incorrect.MulticlassClassificationEvaluatoris not suitable for regression tasks, and it is used for classification tasks.Option C (
BinaryClassificationEvaluatorwithmetricName="mae") is incorrect.BinaryClassificationEvaluatoris intended for binary classification tasks, not regression tasks.Option D (
RegressionSummarizerwithmetricName="mae") is incorrect.RegressionSummarizeris not the correct evaluator for calculating MAE.Option E (
RegressionEvaluatorwithmetricName="mae") is the correct option, equivalent to Option A. It correctly uses theRegressionEvaluatorfor regression tasks and specifies the Mean Absolute Error (MAE) as the evaluation metric.
Therefore, the recommended code block is Option E.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
