| Conditions | 1 |
| Total Lines | 59 |
| Code Lines | 20 |
| 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 | """Adapter for gfo package.""" |
||
| 89 | @classmethod |
||
| 90 | def get_test_params(cls, parameter_set="default"): |
||
| 91 | """Return testing parameter settings for the skbase object. |
||
| 92 | |||
| 93 | ``get_test_params`` is a unified interface point to store |
||
| 94 | parameter settings for testing purposes. This function is also |
||
| 95 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
| 96 | to construct test instances. |
||
| 97 | |||
| 98 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
| 99 | |||
| 100 | Each ``dict`` is a parameter configuration for testing, |
||
| 101 | and can be used to construct an "interesting" test instance. |
||
| 102 | A call to ``cls(**params)`` should |
||
| 103 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
| 104 | |||
| 105 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
| 106 | it can also return dynamic or stochastic parameter settings. |
||
| 107 | |||
| 108 | Parameters |
||
| 109 | ---------- |
||
| 110 | parameter_set : str, default="default" |
||
| 111 | Name of the set of test parameters to return, for use in tests. If no |
||
| 112 | special parameters are defined for a value, will return `"default"` set. |
||
| 113 | |||
| 114 | Returns |
||
| 115 | ------- |
||
| 116 | params : dict or list of dict, default = {} |
||
| 117 | Parameters to create testing instances of the class |
||
| 118 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
| 119 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
| 120 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
| 121 | """ |
||
| 122 | import numpy as np |
||
| 123 | from hyperactive.experiment.integrations import SklearnCvExperiment |
||
| 124 | |||
| 125 | sklearn_exp = SklearnCvExperiment.create_test_instance() |
||
| 126 | params_sklearn = { |
||
| 127 | "experiment": sklearn_exp, |
||
| 128 | "search_space": { |
||
| 129 | "C": np.array([0.01, 0.1, 1, 10]), |
||
| 130 | "gamma": np.array([0.0001, 0.01, 0.1, 1, 10]), |
||
| 131 | }, |
||
| 132 | "n_iter": 100, |
||
| 133 | } |
||
| 134 | |||
| 135 | from hyperactive.experiment.toy import Ackley |
||
| 136 | |||
| 137 | ackley_exp = Ackley.create_test_instance() |
||
| 138 | params_ackley = { |
||
| 139 | "experiment": ackley_exp, |
||
| 140 | "search_space": { |
||
| 141 | "x0": np.linspace(-5, 5, 10), |
||
| 142 | "x1": np.linspace(-5, 5, 10), |
||
| 143 | }, |
||
| 144 | "n_iter": 100, |
||
| 145 | } |
||
| 146 | |||
| 147 | return [params_sklearn, params_ackley] |
||
| 148 |