Databricks Machine Learning Associate Question 290
Select 3You are tasked with building a machine learning model to predict customer churn using Spark ML in Databricks. After preprocessing the data, you split it into training and test datasets. You then train a logistic regression model on the training dataset and evaluate its performance using the test dataset. Which of the following steps are necessary to correctly train and evaluate the model?
- A
Split the dataset into training and test sets using
randomSplit. - B
Fit the logistic regression model on the test dataset.
- C
Use
BinaryClassificationEvaluatorto compute the evaluation metric on the test dataset. - D
Transform the test dataset using the trained logistic regression model.
- E
Normalize the features using
VectorAssemblerafter splitting the dataset.
Show answer and explanation
Correct answers: A, C, D
Explanation
To correctly train and evaluate a machine learning model using Spark ML, the dataset must be split into training and test sets. The model is trained on the training set and evaluated on the test set. Key steps include transforming the test dataset using the trained model and using appropriate evaluators like BinaryClassificationEvaluator to compute evaluation metrics. Proper preprocessing, such as normalization, should occur before splitting the data to avoid inconsistencies.
- A. Correct.
Correct. Splitting the dataset into training and test sets using
randomSplitis a common and necessary step to ensure the model is trained on one part of the data and evaluated on another. - B. Incorrect.
Incorrect. The model should be fit on the training dataset, not the test dataset. Fitting the model on the test set would lead to data leakage and invalidate the evaluation.
- C. Correct.
Correct.
BinaryClassificationEvaluatoris used to compute evaluation metrics like AUC or accuracy on the test dataset, which is a critical step in evaluating model performance. - D. Correct.
Correct. After training the model, you must transform the test dataset using the trained logistic regression model to generate predictions. These predictions are then used for evaluation.
- E. Incorrect.
Incorrect. Feature normalization (e.g., using
VectorAssembler) should be applied before splitting the dataset to ensure consistency across subsets. Normalizing after splitting may lead to discrepancies between training and test sets.