
Explanation:
The correct approach to compute the Mean Absolute Error (MAE) for a regression model in Spark MLlib involves using the RegressionEvaluator with metricName="mae". This is correctly demonstrated in options B and E. Options A and C are incorrect because they use evaluators meant for classification tasks (MulticlassClassificationEvaluator and BinaryClassificationEvaluator, respectively), which are not suitable for regression. Option D is incorrect as RegressionSummarizer is not the appropriate class for calculating MAE. Therefore, the recommended code blocks are options B and E, which are functionally equivalent.
Ultimate access to all questions.
No comments yet.
A data scientist is performing a regression task in Databricks using Spark MLlib. They have a DataFrame named regression_preds_df with predictions and true labels, structured as follows: prediction DOUBLE, label DOUBLE. Which of the following code snippets correctly calculates the Mean Absolute Error (MAE) for the regression model?
A
mae_evaluator = MulticlassClassificationEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)
mae_evaluator = MulticlassClassificationEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)
B
mae_evaluator = RegressionEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)
mae_evaluator = RegressionEvaluator(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)
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)
mae_evaluator = RegressionSummarizer(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)
E
mae_evaluator = RegressionEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)
mae_evaluator = RegressionEvaluator(predictionCol="prediction", labelCol="label", metricName="mae")
mae = mae_evaluator.evaluate(regression_preds_df)