Search code examples
pythonpython-3.xgrid-search

Combination of all parameters for grid search


I'm training a FastText word-representation model, and I'm performing a grid search over a range of multiple parameters. Below is multiple parameter lists:

wordNgrams = [2, 3, 4, 5]
lr = [10e-2, 10e-3, 10e-4, 10e-5, 10e-6]
dim = [200, 250, 300]
ws = [5, 6, 8, 10]

I'd like to try every possible combination for the above lists together and pass them as parameters to train my model. I don't know how to implement a python function to do that and was hoping for some help. Please help.


Solution

  • IIUC use itertools:

    from itertools import product
    print(product(wordNgrams, lr, dim, ws,repeat=4))