Using ParamGridBuilder in Spark MLlib, how many total models will be trained if you add 3 values for maxDepth and 4 values for numTrees to a RandomForestClassifier?
Select an answer to reveal the explanation.
Short Explanation and Infographic
ParamGridBuilder creates a full Cartesian product — every combination of every parameter value. 3 depths × 4 tree counts = 12 unique configurations, each trained and evaluated separately.
Full explanation below image
Full Explanation
ParamGridBuilder().addGrid(rf.maxDepth, [3, 5, 10]).addGrid(rf.numTrees, [10, 20, 50, 100]).build() creates a list of 3 × 4 = 12 parameter maps, one for each unique combination: (maxDepth=3, numTrees=10), (maxDepth=3, numTrees=20), ..., (maxDepth=10, numTrees=100). When used with CrossValidator(numFolds=5), the total number of model training jobs = 12 parameter combinations × 5 folds = 60 training jobs. With TrainValidationSplit (single train/validation split), it's 12 jobs. ParamGridBuilder is exhaustive grid search — it doesn't prune combinations. For larger search spaces, random search (Hyperopt with SparkTrials) is more efficient. The addGrid method takes the parameter object (not a string) and a list of values.