What is the purpose of model evaluation in machine learning?
Model evaluation helps us understand how well a machine learning model performs on new, unseen data. It tells us if the model is accurate and reliable for making predictions.
Click to reveal answer
beginner
Name two common metrics used to evaluate classification models in Apache Spark.
Two common metrics are Accuracy and Area Under the ROC Curve (AUC). Accuracy measures the percentage of correct predictions, while AUC measures the model's ability to distinguish between classes.
Click to reveal answer
beginner
What does the Root Mean Squared Error (RMSE) tell us in regression models?
RMSE shows the average difference between predicted and actual values. A lower RMSE means the model's predictions are closer to the real data.
Click to reveal answer
intermediate
How do you use the BinaryClassificationEvaluator in Apache Spark?
You create a BinaryClassificationEvaluator object, set the label and rawPrediction columns, and then call the evaluate() method on your model's predictions to get metrics like AUC.
Click to reveal answer
beginner
Why is it important to split data into training and test sets before evaluation?
Splitting data ensures the model is tested on new data it hasn't seen before. This helps us get a realistic measure of how the model will perform in real life.
Click to reveal answer
Which metric is best for evaluating a regression model?
ARoot Mean Squared Error (RMSE)
BAccuracy
CArea Under ROC Curve (AUC)
DPrecision
✗ Incorrect
RMSE measures the average prediction error for regression models, making it the best choice here.
What does an AUC value close to 1 indicate?
APoor model performance
BModel overfitting
CRandom guessing
DExcellent model performance
✗ Incorrect
An AUC close to 1 means the model can perfectly distinguish between classes.
In Apache Spark, which evaluator is used for multi-class classification?
ABinaryClassificationEvaluator
BMulticlassClassificationEvaluator
CRegressionEvaluator
DClusteringEvaluator
✗ Incorrect
MulticlassClassificationEvaluator is designed for evaluating models with more than two classes.
Why should you avoid evaluating a model on the training data?
AIt takes too long
BTraining data is too small
CIt gives an overly optimistic performance estimate
DTraining data is always noisy
✗ Incorrect
Evaluating on training data can make the model look better than it really is on new data.
Which metric measures the proportion of true positives out of all predicted positives?
APrecision
BAccuracy
CRecall
DF1 Score
✗ Incorrect
Precision tells us how many predicted positives were actually correct.
Explain how you would evaluate a binary classification model using Apache Spark.
Think about the steps from data preparation to metric calculation.
You got /5 concepts.
Describe the difference between accuracy and AUC as evaluation metrics.
Consider when each metric is useful.
You got /4 concepts.
Practice
(1/5)
1. Which metric is commonly used to evaluate a classification model's accuracy in Apache Spark?
easy
A. R-squared
B. Root Mean Squared Error
C. Accuracy
D. Mean Absolute Error
Solution
Step 1: Understand classification metrics
Classification models predict categories, so accuracy measures correct predictions over total predictions.
Step 2: Match metric to model type
Accuracy is the standard metric for classification, while RMSE, MAE, and R-squared are for regression.
Final Answer:
Accuracy -> Option C
Quick Check:
Classification accuracy = Accuracy [OK]
Hint: Use accuracy for classification, RMSE for regression [OK]
Common Mistakes:
Confusing regression metrics with classification
Using R-squared for classification
Choosing MAE for classification
2. Which of the following is the correct way to create a BinaryClassificationEvaluator in Spark to evaluate areaUnderROC?
easy
A. BinaryClassificationEvaluator(metric="areaUnderROC")
B. BinaryClassificationEvaluator(metricName="areaUnderROC")
C. BinaryClassificationEvaluator(metricName='accuracy')
D. BinaryClassificationEvaluator(metric='accuracy')
Solution
Step 1: Recall evaluator syntax
BinaryClassificationEvaluator uses parameter metricName to specify the metric.
Step 2: Check metric value
"areaUnderROC" is a valid metricName; accuracy is not valid for this evaluator.
Final Answer:
BinaryClassificationEvaluator(metricName="areaUnderROC") -> Option B
Quick Check:
Use metricName="areaUnderROC" in BinaryClassificationEvaluator [OK]
Hint: Use metricName, not metric, for evaluator metrics [OK]
Common Mistakes:
Using 'metric' instead of 'metricName'
Passing invalid metric names like 'accuracy'
Using single quotes inconsistently
3. Given the following Spark code, what will be the output of the evaluator?
from pyspark.ml.evaluation import RegressionEvaluator
evaluator = RegressionEvaluator(metricName="accuracy")
What is the cause of the error?
medium
A. "accuracy" is not a valid metric for RegressionEvaluator
B. RegressionEvaluator requires a DataFrame input
C. metricName parameter is misspelled
D. RegressionEvaluator cannot be imported from pyspark.ml.evaluation
Solution
Step 1: Check valid metrics for RegressionEvaluator
RegressionEvaluator supports metrics like rmse, mse, mae, r2 but not accuracy.
Step 2: Identify error cause
Using "accuracy" causes an error because it is for classification, not regression.
Final Answer:
"accuracy" is not a valid metric for RegressionEvaluator -> Option A
Quick Check:
RegressionEvaluator metrics exclude accuracy [OK]
Hint: Use classification evaluator for accuracy metric [OK]
Common Mistakes:
Confusing metric names between evaluators
Assuming metricName typo causes error
Ignoring evaluator import errors
5. You have a Spark ML model for binary classification. You want to evaluate it using both areaUnderROC and F1 score. Which approach correctly evaluates both metrics on the same predictions DataFrame?
hard
A. Use BinaryClassificationEvaluator with metricName="areaUnderROC" and MulticlassClassificationEvaluator with metricName="f1"
B. Use BinaryClassificationEvaluator twice with metricName="areaUnderROC" and metricName="f1" respectively
C. Use RegressionEvaluator with metricName="areaUnderROC" and MulticlassClassificationEvaluator with metricName="f1"
D. Use MulticlassClassificationEvaluator twice with metricName="areaUnderROC" and metricName="f1"
Solution
Step 1: Identify evaluators for each metric
areaUnderROC is supported by BinaryClassificationEvaluator; F1 score is supported by MulticlassClassificationEvaluator.
Step 2: Combine evaluators correctly
Use BinaryClassificationEvaluator for areaUnderROC and MulticlassClassificationEvaluator for F1 on the same predictions DataFrame.
Final Answer:
Use BinaryClassificationEvaluator with metricName="areaUnderROC" and MulticlassClassificationEvaluator with metricName="f1" -> Option A