| Conditions | 1 |
| Total Lines | 64 |
| Code Lines | 26 |
| 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 | """Experiment adapter for sklearn cross-validation experiments.""" |
||
| 142 | @classmethod |
||
| 143 | def get_test_params(cls, parameter_set="default"): |
||
| 144 | """Return testing parameter settings for the skbase object. |
||
| 145 | |||
| 146 | ``get_test_params`` is a unified interface point to store |
||
| 147 | parameter settings for testing purposes. This function is also |
||
| 148 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
| 149 | to construct test instances. |
||
| 150 | |||
| 151 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
| 152 | |||
| 153 | Each ``dict`` is a parameter configuration for testing, |
||
| 154 | and can be used to construct an "interesting" test instance. |
||
| 155 | A call to ``cls(**params)`` should |
||
| 156 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
| 157 | |||
| 158 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
| 159 | it can also return dynamic or stochastic parameter settings. |
||
| 160 | |||
| 161 | Parameters |
||
| 162 | ---------- |
||
| 163 | parameter_set : str, default="default" |
||
| 164 | Name of the set of test parameters to return, for use in tests. If no |
||
| 165 | special parameters are defined for a value, will return `"default"` set. |
||
| 166 | |||
| 167 | Returns |
||
| 168 | ------- |
||
| 169 | params : dict or list of dict, default = {} |
||
| 170 | Parameters to create testing instances of the class |
||
| 171 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
| 172 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
| 173 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
| 174 | """ |
||
| 175 | from sklearn.datasets import load_diabetes, load_iris |
||
| 176 | from sklearn.svm import SVC, SVR |
||
| 177 | from sklearn.metrics import accuracy_score, mean_absolute_error |
||
| 178 | from sklearn.model_selection import KFold |
||
| 179 | |||
| 180 | X, y = load_iris(return_X_y=True) |
||
| 181 | params_classif = { |
||
| 182 | "estimator": SVC(), |
||
| 183 | "scoring": accuracy_score, |
||
| 184 | "cv": KFold(n_splits=3, shuffle=True), |
||
| 185 | "X": X, |
||
| 186 | "y": y, |
||
| 187 | } |
||
| 188 | |||
| 189 | X, y = load_diabetes(return_X_y=True) |
||
| 190 | params_regress = { |
||
| 191 | "estimator": SVR(), |
||
| 192 | "scoring": mean_absolute_error, |
||
| 193 | "cv": 2, |
||
| 194 | "X": X, |
||
| 195 | "y": y, |
||
| 196 | } |
||
| 197 | |||
| 198 | X, y = load_diabetes(return_X_y=True) |
||
| 199 | params_all_default = { |
||
| 200 | "estimator": SVR(), |
||
| 201 | "X": X, |
||
| 202 | "y": y, |
||
| 203 | } |
||
| 204 | |||
| 205 | return [params_classif, params_regress, params_all_default] |
||
| 206 | |||
| 223 |