grid_search
GridSearch
¶
Bases: Search
A class which executes a grid search.
Grid search can be used to evaluate or optimize results of one or more hyperparameters.
search = GridSearch(eval_fn=lambda search_idx, a, b: a + b, params={"a": [1, 2, 3], "b": [4, 5, 6]})
search.fit()
print(search.get_best_results()) # {'param': {'a': 6, 'b': 6, 'search_idx': 10}, 'result': {'value': 12}}
search = GridSearch(eval_fn=lambda search_idx, a, b: {"sum": a + b}, params={"a": [1, 2, 3], "b": [4, 5, 6]})
search.fit()
print(search.get_best_results()) # {'param': {'a': 6, 'b': 6, 'search_idx': 10}, 'result': {'sum': 12}}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eval_fn |
Callable[..., Union[Dict[str, Any], float]]
|
Function that evaluates result given parameter. One of its arguments must be 'search_idx' which will be automatically provided by the search routine. This can help with file saving / logging during the search. The eval_fn should return a dictionary, or else the return would be wrapped inside one. |
required |
params |
Dict[str, List]
|
A dictionary with key names matching the |
required |
best_mode |
Optional[str]
|
Whether maximal or minimal objective is desired. Must be either 'min' or 'max'. |
None
|
optimize_field |
Optional[str]
|
the key corresponding to the target value when deciding the best. If None and multiple keys exist in result dictionary, the optimization is ambiguous therefore an error will be raised. |
None
|
name |
str
|
The name of the search instance. This is used for saving and loading purposes. |
'grid_search'
|
Raises:
Type | Description |
---|---|
AssertionError
|
If |