For this exercise, if we first make all the possible combinations of the hyperparameters into a list, then we can loop through this list only once instead of using two for loops—which I find confusing. We can make such a list via itertools.product
function.
Then use it like this:
for lr, mln in hyperparam_comb:
model.set_params(
classifier__learning_rate=lr,
classifier__max_leaf_nodes=mln)
...
According to the documentation, the output of itertools.product
would be the same as using nested for-loops in a generator expression: