| Conditions | 1 |
| Total Lines | 51 |
| 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 | """Hyperactive cross-validation search for scikit-learn integration. |
||
| 96 | @Checks.verify_fit |
||
| 97 | def fit(self, X, y, **fit_params): |
||
| 98 | """ |
||
| 99 | Fit the estimator using the provided training data. |
||
| 100 | |||
| 101 | Parameters |
||
| 102 | ---------- |
||
| 103 | - X: array-like or sparse matrix, shape (n_samples, n_features) |
||
| 104 | The training input samples. |
||
| 105 | - y: array-like, shape (n_samples,) or (n_samples, n_outputs) |
||
| 106 | The target values. |
||
| 107 | - **fit_params: dict of string -> object |
||
| 108 | Additional fit parameters. |
||
| 109 | |||
| 110 | Returns |
||
| 111 | ------- |
||
| 112 | - self: object |
||
| 113 | Returns the instance itself. |
||
| 114 | """ |
||
| 115 | X, y = self._check_data(X, y) |
||
| 116 | |||
| 117 | fit_params = _check_method_params(X, params=fit_params) |
||
| 118 | self.scorer_ = check_scoring(self.estimator, scoring=self.scoring) |
||
| 119 | |||
| 120 | experiment = SklearnCvExperiment( |
||
| 121 | estimator=self.estimator, |
||
| 122 | scoring=self.scorer_, |
||
| 123 | cv=self.cv, |
||
| 124 | X=X, |
||
| 125 | y=y, |
||
| 126 | ) |
||
| 127 | objective_function = experiment.score |
||
| 128 | |||
| 129 | hyper = Hyperactive(verbosity=False) |
||
| 130 | hyper.add_search( |
||
| 131 | objective_function, |
||
| 132 | search_space=self.params_config, |
||
| 133 | optimizer=self.optimizer, |
||
| 134 | n_iter=self.n_iter, |
||
| 135 | n_jobs=self.n_jobs, |
||
| 136 | random_state=self.random_state, |
||
| 137 | ) |
||
| 138 | hyper.run() |
||
| 139 | |||
| 140 | self.best_params_ = hyper.best_para(objective_function) |
||
| 141 | self.best_score_ = hyper.best_score(objective_function) |
||
| 142 | self.search_data_ = hyper.search_data(objective_function) |
||
| 143 | |||
| 144 | _safe_refit(self, X, y, fit_params) |
||
| 145 | |||
| 146 | return self |
||
| 147 | |||
| 172 |