create_grid_params

czsc.utils.create_grid_params(prefix: str, detail=False, **kwargs) dict[source]

创建 grid search 参数组合

Parameters:
  • prefix – 参数组前缀

  • detail – 是否使用参数值构建参数组的名称

  • kwargs – 任意参数的候选序列,参数值推荐使用 iterable

Returns:

参数组合字典

Examples

>>>x = create_grid_params(“test”, x=(1, 2), y=(‘a’, ‘b’), detail=True) >>>print(x) Out[0]:

{‘test_x=1_y=a’: {‘x’: 1, ‘y’: ‘a’},

‘test_x=1_y=b’: {‘x’: 1, ‘y’: ‘b’}, ‘test_x=2_y=a’: {‘x’: 2, ‘y’: ‘a’}, ‘test_x=2_y=b’: {‘x’: 2, ‘y’: ‘b’}}

# 单个参数传入单个值也是可以的,但类型必须是 int, float, str 中的任一 >>>x = create_grid_params(“test”, x=2, y=(‘a’, ‘b’), detail=False) >>>print(x) Out[1]:

{‘test@001’: {‘x’: 2, ‘y’: ‘a’},

‘test@002’: {‘x’: 2, ‘y’: ‘b’}}