A data scientist is using ParamGridBuilder with CrossValidator in PySpark ML and wants to select the final model configuration based on the highest average F1 score across folds, not accuracy. Which change is required to their MulticlassClassificationEvaluator setup?
- A. No change is needed —
CrossValidatoralways internally computes and optimizes for F1 for multiclass problems regardless of the evaluator's configured metric - B. Switch to
BinaryClassificationEvaluator, which is required whenever F1 score is the target metric - C. Manually compute F1 for each fold outside of
CrossValidatorsince it does not support any classification metric besides accuracy - D. Set the evaluator's metric parameter to
f1(e.g.metricName='f1') soCrossValidatorselects the parameter combination that maximizes F1 across folds✓ Correct
Explanation
CrossValidator selects the best model according to whatever metric the supplied evaluator is configured for, so setting MulticlassClassificationEvaluator(metricName='f1') makes it optimize for F1 across folds. It does not silently default to F1 (option 2) or only accuracy (option 4) — the metric is whatever you configure. BinaryClassificationEvaluator (option 3) is for two-class problems evaluated by AUC/AUPRC and is not required for F1, which MulticlassClassificationEvaluator supports natively (including for two classes).