| Conditions | 1 |
| Total Lines | 56 |
| Code Lines | 21 |
| 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.""" |
||
| 111 | @classmethod |
||
| 112 | def get_test_params(cls, parameter_set="default"): |
||
| 113 | """Return testing parameter settings for the skbase object. |
||
| 114 | |||
| 115 | ``get_test_params`` is a unified interface point to store |
||
| 116 | parameter settings for testing purposes. This function is also |
||
| 117 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
| 118 | to construct test instances. |
||
| 119 | |||
| 120 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
| 121 | |||
| 122 | Each ``dict`` is a parameter configuration for testing, |
||
| 123 | and can be used to construct an "interesting" test instance. |
||
| 124 | A call to ``cls(**params)`` should |
||
| 125 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
| 126 | |||
| 127 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
| 128 | it can also return dynamic or stochastic parameter settings. |
||
| 129 | |||
| 130 | Parameters |
||
| 131 | ---------- |
||
| 132 | parameter_set : str, default="default" |
||
| 133 | Name of the set of test parameters to return, for use in tests. If no |
||
| 134 | special parameters are defined for a value, will return `"default"` set. |
||
| 135 | |||
| 136 | Returns |
||
| 137 | ------- |
||
| 138 | params : dict or list of dict, default = {} |
||
| 139 | Parameters to create testing instances of the class |
||
| 140 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
| 141 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
| 142 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
| 143 | """ |
||
| 144 | from sklearn.datasets import load_diabetes, load_iris |
||
| 145 | from sklearn.svm import SVC, SVR |
||
| 146 | from sklearn.metrics import accuracy_score, mean_absolute_error |
||
| 147 | from sklearn.model_selection import KFold |
||
| 148 | |||
| 149 | X, y = load_iris(return_X_y=True) |
||
| 150 | params_classif = { |
||
| 151 | "estimator": SVC(), |
||
| 152 | "scoring": accuracy_score, |
||
| 153 | "cv": KFold(n_splits=3, shuffle=True), |
||
| 154 | "X": X, |
||
| 155 | "y": y, |
||
| 156 | } |
||
| 157 | |||
| 158 | X, y = load_diabetes(return_X_y=True) |
||
| 159 | params_regress = { |
||
| 160 | "estimator": SVR(), |
||
| 161 | "scoring": mean_absolute_error, |
||
| 162 | "cv": KFold(n_splits=2, shuffle=True), |
||
| 163 | "X": X, |
||
| 164 | "y": y, |
||
| 165 | } |
||
| 166 | return [params_classif, params_regress] |
||
| 167 | |||
| 183 |