| 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."""  | 
            ||
| 117 | @classmethod  | 
            ||
| 118 | def get_test_params(cls, parameter_set="default"):  | 
            ||
| 119 | """Return testing parameter settings for the skbase object.  | 
            ||
| 120 | |||
| 121 | ``get_test_params`` is a unified interface point to store  | 
            ||
| 122 | parameter settings for testing purposes. This function is also  | 
            ||
| 123 | used in ``create_test_instance`` and ``create_test_instances_and_names``  | 
            ||
| 124 | to construct test instances.  | 
            ||
| 125 | |||
| 126 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``.  | 
            ||
| 127 | |||
| 128 | Each ``dict`` is a parameter configuration for testing,  | 
            ||
| 129 | and can be used to construct an "interesting" test instance.  | 
            ||
| 130 | A call to ``cls(**params)`` should  | 
            ||
| 131 | be valid for all dictionaries ``params`` in the return of ``get_test_params``.  | 
            ||
| 132 | |||
| 133 | The ``get_test_params`` need not return fixed lists of dictionaries,  | 
            ||
| 134 | it can also return dynamic or stochastic parameter settings.  | 
            ||
| 135 | |||
| 136 | Parameters  | 
            ||
| 137 | ----------  | 
            ||
| 138 | parameter_set : str, default="default"  | 
            ||
| 139 | Name of the set of test parameters to return, for use in tests. If no  | 
            ||
| 140 | special parameters are defined for a value, will return `"default"` set.  | 
            ||
| 141 | |||
| 142 | Returns  | 
            ||
| 143 | -------  | 
            ||
| 144 |         params : dict or list of dict, default = {} | 
            ||
| 145 | Parameters to create testing instances of the class  | 
            ||
| 146 | Each dict are parameters to construct an "interesting" test instance, i.e.,  | 
            ||
| 147 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.  | 
            ||
| 148 | `create_test_instance` uses the first (or only) dictionary in `params`  | 
            ||
| 149 | """  | 
            ||
| 150 | from hyperactive.experiment.integrations import SklearnCvExperiment  | 
            ||
| 151 | |||
| 152 | sklearn_exp = SklearnCvExperiment.create_test_instance()  | 
            ||
| 153 |         param_grid = { | 
            ||
| 154 | "C": [0.01, 0.1, 1, 10],  | 
            ||
| 155 | "gamma": [0.0001, 0.01, 0.1, 1, 10],  | 
            ||
| 156 | }  | 
            ||
| 157 |         params_sklearn = { | 
            ||
| 158 | "experiment": sklearn_exp,  | 
            ||
| 159 | "param_grid": param_grid,  | 
            ||
| 160 | }  | 
            ||
| 161 | |||
| 162 | from hyperactive.experiment.toy import Ackley  | 
            ||
| 163 | |||
| 164 | ackley_exp = Ackley.create_test_instance()  | 
            ||
| 165 |         param_grid = { | 
            ||
| 166 | "x0": np.linspace(-5, 5, 10),  | 
            ||
| 167 | "x1": np.linspace(-5, 5, 10),  | 
            ||
| 168 | }  | 
            ||
| 169 |         params_ackley = { | 
            ||
| 170 | "experiment": ackley_exp,  | 
            ||
| 171 | "param_grid": param_grid,  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 | return [params_sklearn, params_ackley]  | 
            ||
| 175 |