DATABRICKS-MACHINE-LEARNING-ASSOCIATE practice question 5 of 15
Which of the Spark operations can be used to randomly split a Spark DataFrame into a training DataFrame and a test DataFrame for downstream use?
Full set: 74 questionsThe DataFrame.randomSplit() method is the designated Spark operation for randomly partitioning a DataFrame into multiple, non-overlapping subsets. It accepts a list of weights that define the approximate proportions for each split and an optional seed for reproducibility. This function is the standard and most direct approach for creating training and test DataFrames from a single source DataFrame in a Spark-based machine learning workflow. The resulting splits are returned as a list of DataFrames.
A. TrainValidationSplit is a high-level hyperparameter tuning class that internally performs a single split, but it is not the fundamental DataFrame operation itself.
B. DataFrame.where is a filtering operation used to select rows based on a specific condition; it does not perform a random split.
C. CrossValidator is a hyperparameter tuning class that performs k-fold cross-validation, creating multiple splits, not a single train/test split operation.
D. TrainValidationSplitModel is the object returned after fitting a TrainValidationSplit estimator; it is a result, not an operation for splitting data.
1. Apache Spark Official Documentation. The PySpark API reference for pyspark.sql.DataFrame.randomSplit explicitly states its purpose: "Randomly splits this DataFrame with the provided weights." It provides a clear example of creating two splits.
Source: Apache Spark 3.5.0 Documentation
pyspark.sql.DataFrame.randomSplit.
2. Databricks Official Documentation. The documentation on preparing data for machine learning demonstrates this exact use case. It shows an example: traindf
testdf = originaldf.randomSplit([.8
.2]
seed=42)
directly confirming its use for creating training and test sets.
Source: Databricks Documentation > Machine Learning > Get started > Tutorial: ML end-to-end on Databricks > Step 2: Prepare the data.
3. University Courseware. Reputable data science courses that use Spark consistently teach randomSplit for this purpose. For example
materials from UC Berkeley's Data 100 course show randomSplit as the standard method for creating training and test sets in PySpark.
Source: University of California
Berkeley
Data 100: Principles & Techniques of Data Science
Course Materials (e.g.
Fall 2022
Lecture 20 on Parallel Processing).
Keep practicing
Take the free DATABRICKS-MACHINE-LEARNING-ASSOCIATE practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other DATABRICKS-MACHINE-LEARNING-ASSOCIATE practice questions
- Question 2The implementation of linear regression in Spark ML first attempts to solve the linear re…
- Question 3A data scientist wants to parallelize the training of trees in a gradient boosted tree to…
- Question 6A data scientist is attempting to tune a logistic regression model logistic using scikit-…
- Question 7Which of the following is a benefit of using vectorized pandas UDFs instead of standard P…
- Question 8A data scientist is developing a machine learning pipeline using AutoML on Databricks Mac…
- Question 10Which of the following hyperparameter optimization methods automatically makes informed s…
