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:

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:

Explanation:

  • Option A (RegressionEvaluator with metricName="mae") correctly specifies the RegressionEvaluator for the regression task and uses the Mean Absolute Error (MAE) as the evaluation metric.

  • Option B (MulticlassClassificationEvaluator with metricName="mae") is incorrect. MulticlassClassificationEvaluator is not suitable for regression tasks, and it is used for classification tasks.

  • Option C (BinaryClassificationEvaluator with metricName="mae") is incorrect. BinaryClassificationEvaluator is intended for binary classification tasks, not regression tasks.

  • Option D (RegressionSummarizer with metricName="mae") is incorrect. RegressionSummarizer is not the correct evaluator for calculating MAE.

  • Option E (RegressionEvaluator with metricName="mae") is the correct option, equivalent to Option A. It correctly uses the RegressionEvaluator for 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.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need