Databricks Certified Machine Learning Associate · Free Practice Question Medium

Question 19

A data scientist has designed a three-class decision tree classifier utilizing Spark MLandcomputed the predictions in a Spark DataFrame, named preds_dt, with the following schema:

prediction DOUBLE, actual DOUBLE.

Which code segment can be used to calculate the accuracy of the model based on the data in preds_dt and assign the result to the accuracy variable?

Choose only ONE best answer.


  • A

    None

  • B
  • C
  • D
  • E
Reveal correct answer

Correct answer: D

Explanation

Correct Answer:


Explanation:

  1. Why This Is Correct?

    • For a multi-class classifier in Spark ML, the MulticlassClassificationEvaluator is the correct tool to compute metrics like accuracy.

    • Key steps:

      1. Initialize the evaluator with:

        • predictionCol="prediction" (model outputs).

        • labelCol="actual" (true labels).

        • metricName="accuracy".

      2. Call evaluate() on the DataFrame (preds_df).

  2. Example:


Why Other Options Are Incorrect?

  • RegressionEvaluator:

    • For regression tasks, not classification.

  • Summarizer:

    • Does not exist in Spark ML.

  • Missing evaluate() call:

    • Just initializing the evaluator doesn’t compute the metric.

Key Takeaway:

For multi-class accuracy in Spark ML:

  1. Use MulticlassClassificationEvaluator.

  2. Ensure column names match your DataFrame schema.

Pro Tip: Other supported metrics include f1, weightedPrecision, and weightedRecall.


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