Databricks Machine Learning Associate exam dumps

Databricks Machine Learning Associate practice question 281 of 656

Databricks Certified Machine Learning Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Machine Learning Associate Question 281

Single answer

You are working on a machine learning pipeline in Databricks and need to split your dataset into training and testing sets using Spark ML. Which of the following code snippets correctly splits the data into a 70% training set and a 30% testing set?

  1. A

    train_data, test_data = df.randomSplit([0.7, 0.3], seed=42)

  2. B

    train_data, test_data = df.split([0.7, 0.3], seed=42)

  3. C

    train_data, test_data = df.randomSplit([0.3, 0.7], seed=42)

  4. D

    train_data, test_data = df.randomSplit([0.7, 0.3])

Show answer and explanation

Correct answer: A

Explanation

The randomSplit method in Spark ML is used to split datasets into multiple subsets based on the specified proportions. For a 70-30 split, you need to provide [0.7, 0.3] as the first argument. Including a seed ensures that the split is reproducible, which is a best practice in machine learning workflows.

  • A. Correct.

    This is the correct code to split a dataset into training and testing sets using Spark ML. The randomSplit method takes a list of split proportions as its first argument and an optional seed argument for reproducibility.

  • B. Incorrect.

    This is incorrect because split is not a valid method in Spark ML for splitting datasets. The correct method is randomSplit.

  • C. Incorrect.

    This is incorrect because the proportions for the training and testing sets are reversed. A 70% training set and 30% testing set require the proportions [0.7, 0.3].

  • D. Incorrect.

    This is incorrect because while the proportions are correct, the absence of a seed argument makes the split non-deterministic, which is not advisable in a professional or reproducible setting.

Timed practice exam

Take a Databricks Machine Learning Associate practice test under exam conditions

48 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam