| Conditions | 1 |
| Total Lines | 58 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """Grid search optimizer.""" |
||
| 118 | @classmethod |
||
| 119 | def get_test_params(cls, parameter_set="default"): |
||
| 120 | """Return testing parameter settings for the skbase object. |
||
| 121 | |||
| 122 | ``get_test_params`` is a unified interface point to store |
||
| 123 | parameter settings for testing purposes. This function is also |
||
| 124 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
| 125 | to construct test instances. |
||
| 126 | |||
| 127 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
| 128 | |||
| 129 | Each ``dict`` is a parameter configuration for testing, |
||
| 130 | and can be used to construct an "interesting" test instance. |
||
| 131 | A call to ``cls(**params)`` should |
||
| 132 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
| 133 | |||
| 134 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
| 135 | it can also return dynamic or stochastic parameter settings. |
||
| 136 | |||
| 137 | Parameters |
||
| 138 | ---------- |
||
| 139 | parameter_set : str, default="default" |
||
| 140 | Name of the set of test parameters to return, for use in tests. If no |
||
| 141 | special parameters are defined for a value, will return `"default"` set. |
||
| 142 | |||
| 143 | Returns |
||
| 144 | ------- |
||
| 145 | params : dict or list of dict, default = {} |
||
| 146 | Parameters to create testing instances of the class |
||
| 147 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
| 148 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
| 149 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
| 150 | """ |
||
| 151 | from hyperactive.experiment.integrations import SklearnCvExperiment |
||
| 152 | |||
| 153 | sklearn_exp = SklearnCvExperiment.create_test_instance() |
||
| 154 | param_grid = { |
||
| 155 | "C": [0.01, 0.1, 1, 10], |
||
| 156 | "gamma": [0.0001, 0.01, 0.1, 1, 10], |
||
| 157 | } |
||
| 158 | params_sklearn = { |
||
| 159 | "experiment": sklearn_exp, |
||
| 160 | "param_grid": param_grid, |
||
| 161 | } |
||
| 162 | |||
| 163 | from hyperactive.experiment.toy import Ackley |
||
| 164 | |||
| 165 | ackley_exp = Ackley.create_test_instance() |
||
| 166 | param_grid = { |
||
| 167 | "x0": np.linspace(-5, 5, 10), |
||
| 168 | "x1": np.linspace(-5, 5, 10), |
||
| 169 | } |
||
| 170 | params_ackley = { |
||
| 171 | "experiment": ackley_exp, |
||
| 172 | "param_grid": param_grid, |
||
| 173 | } |
||
| 174 | |||
| 175 | return [params_sklearn, params_ackley] |
||
| 176 |