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