diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95b8c00f51..af0ec72b29 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.11.5 hooks: - id: isort name: isort imports autosklearn @@ -15,7 +15,7 @@ repos: files: test/.* - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.3.0 hooks: - id: black name: black formatter autosklearn @@ -31,7 +31,7 @@ repos: # This is disabled as most modules fail this - repo: https://github.com/pycqa/pydocstyle - rev: 6.1.1 + rev: 6.3.0 hooks: - id: pydocstyle files: DISABLED # autosklearn/.* @@ -39,7 +39,7 @@ repos: additional_dependencies: ["toml"] # Needed to parse pyproject.toml - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.990 + rev: v1.2.0 hooks: - id: mypy name: mypy auto-sklearn diff --git a/autosklearn/pipeline/regression.py b/autosklearn/pipeline/regression.py index dcc2fa3fcf..85f5ed70ab 100644 --- a/autosklearn/pipeline/regression.py +++ b/autosklearn/pipeline/regression.py @@ -106,12 +106,35 @@ def iterative_fit(self, X, y, n_iter=1, **fit_params): ) def predict(self, X, batch_size=None): + """Predict the classes using the selected model. + + Predicted values are capped to approximately the maximum and minimum labels + seen during training. + + Parameters + ---------- + X : array-like, shape = (n_samples, n_features) + + batch_size: int or None, defaults to None + batch_size controls whether the pipeline will be + called on small chunks of the data. Useful when calling the + predict method on the whole array X results in a MemoryError. + + Returns + ------- + array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes) + Returns the predicted values""" y = super().predict(X, batch_size=batch_size) - y[y > (2 * self.y_max_)] = 2 * self.y_max_ + + if self.y_max_ > 0: + y[y > (2 * self.y_max_)] = 2 * self.y_max_ + elif self.y_max_ < 0: + y[y > (0.5 * self.y_max_)] = 0.5 * self.y_max_ if self.y_min_ < 0: y[y < (2 * self.y_min_)] = 2 * self.y_min_ elif self.y_min_ > 0: y[y < (0.5 * self.y_min_)] = 0.5 * self.y_min_ + return y def _get_hyperparameter_search_space(