用于网格搜索的所有参数的组合

Combination of all parameters for grid search

我正在训练 FastText 单词表示模型,并且正在对一系列多个参数执行网格搜索。下面是多个参数列表:

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]

我想尝试以上列表的所有可能组合,并将它们作为参数传递来训练我的模型。我不知道如何实现 python 函数来做到这一点,希望得到一些帮助。请帮忙。

IIUC 使用 itertools:

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

您也可以使用 sklearn.model_selection 中的 ParameterGrid。在回答类似问题时解释得更好 here.